Backstage Sigil of Holding (#785)

* Backstage Sigil of Holding
All Sigil of Holding features work, just need to add the aesthetics -> TehNut
Somebody might want to look at adding LP costs to the Sigil?
Also recipes need to be added
Added a keybinding system for future usage
Standardized some NBT tags

Compact classes

Fix lang stuff?

* Fancify Sigil of Holding GUI
Displays the selected sigil in the GUI now

Woops

* Quick fix

* Unused import

* Final commit I promise
This commit is contained in:
Arcaratus 2016-06-07 18:50:41 -04:00 committed by Nick Ignoffo
parent 9aa2f86c88
commit 8d66575530
19 changed files with 922 additions and 6 deletions

View file

@ -38,6 +38,8 @@ public class Constants
public static final String INPUT_AMOUNT = "inputAmount"; public static final String INPUT_AMOUNT = "inputAmount";
public static final String STORED_LP = "storedLP"; public static final String STORED_LP = "storedLP";
public static final String RITUAL_READER = "ritualReaderState"; public static final String RITUAL_READER = "ritualReaderState";
public static final String ITEMS = "Items";
public static final String SLOT = "Slot";
public static final String ALTAR = "bloodAltar"; public static final String ALTAR = "bloodAltar";
public static final String ALTAR_TIER = "upgradeLevel"; public static final String ALTAR_TIER = "upgradeLevel";
@ -111,6 +113,10 @@ public class Constants
public static final String ITEM_INVENTORY = "itemInventory"; public static final String ITEM_INVENTORY = "itemInventory";
public static final String BLOCKPOS_CONNECTION = "connections"; public static final String BLOCKPOS_CONNECTION = "connections";
public static final String CURRENT_SIGIL = "currentSigil";
public static final String MOST_SIG = "mostSig";
public static final String LEAST_SIG = "leastSig";
} }
public static class Mod public static class Mod
@ -129,6 +135,7 @@ public class Constants
public static final int ROUTING_NODE_GUI = 2; public static final int ROUTING_NODE_GUI = 2;
public static final int MASTER_ROUTING_NODE_GUI = 3; public static final int MASTER_ROUTING_NODE_GUI = 3;
public static final int ALCHEMY_TABLE_GUI = 4; public static final int ALCHEMY_TABLE_GUI = 4;
public static final int SIGIL_HOLDING_GUI = 5;
} }
public static class Compat public static class Compat
@ -217,6 +224,7 @@ public class Constants
SIGIL_TRANSPOSITION("ItemSigilTransposition"), SIGIL_TRANSPOSITION("ItemSigilTransposition"),
RITUAL_READER("ItemRitualReader"), RITUAL_READER("ItemRitualReader"),
SANGUINE_BOOK("ItemSanguineBook"), SANGUINE_BOOK("ItemSanguineBook"),
SIGIL_HOLDING("ItemSigilHolding"),
; ;
@Getter @Getter

View file

@ -1,5 +1,7 @@
package WayofTime.bloodmagic.client.gui; package WayofTime.bloodmagic.client.gui;
import WayofTime.bloodmagic.item.inventory.ContainerHolding;
import WayofTime.bloodmagic.item.inventory.InventoryHolding;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -36,6 +38,8 @@ public class GuiHandler implements IGuiHandler
return new ContainerMasterRoutingNode(player.inventory, (TileMasterRoutingNode) world.getTileEntity(pos)); return new ContainerMasterRoutingNode(player.inventory, (TileMasterRoutingNode) world.getTileEntity(pos));
case Constants.Gui.ALCHEMY_TABLE_GUI: case Constants.Gui.ALCHEMY_TABLE_GUI:
return new ContainerAlchemyTable(player.inventory, (TileAlchemyTable) world.getTileEntity(pos)); return new ContainerAlchemyTable(player.inventory, (TileAlchemyTable) world.getTileEntity(pos));
case Constants.Gui.SIGIL_HOLDING_GUI:
return new ContainerHolding(player, new InventoryHolding(player.getHeldItemMainhand()));
} }
return null; return null;
@ -60,6 +64,8 @@ public class GuiHandler implements IGuiHandler
return new GuiMasterRoutingNode(player.inventory, (TileMasterRoutingNode) world.getTileEntity(pos)); return new GuiMasterRoutingNode(player.inventory, (TileMasterRoutingNode) world.getTileEntity(pos));
case Constants.Gui.ALCHEMY_TABLE_GUI: case Constants.Gui.ALCHEMY_TABLE_GUI:
return new GuiAlchemyTable(player.inventory, (TileAlchemyTable) world.getTileEntity(pos)); return new GuiAlchemyTable(player.inventory, (TileAlchemyTable) world.getTileEntity(pos));
case Constants.Gui.SIGIL_HOLDING_GUI:
return new GuiHolding(player, new InventoryHolding(player.getHeldItemMainhand()));
} }
} }

View file

@ -0,0 +1,56 @@
package WayofTime.bloodmagic.client.gui;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.item.inventory.ContainerHolding;
import WayofTime.bloodmagic.item.inventory.InventoryHolding;
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
import WayofTime.bloodmagic.util.helper.TextHelper;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiHolding extends GuiContainer
{
private ResourceLocation texture = new ResourceLocation(Constants.Mod.MODID, "gui/SigilHolding.png");
private EntityPlayer player;
public GuiHolding(EntityPlayer player, InventoryHolding inventoryHolding)
{
super(new ContainerHolding(player, inventoryHolding));
xSize = 176;
ySize = 121;
this.player = player;
}
@Override
protected void drawGuiContainerForegroundLayer(int param1, int param2)
{
//the parameters for drawString are: string, x, y, color
fontRendererObj.drawString(TextHelper.localize("item.BloodMagic.sigil.holding.name"), 53, 4, 4210752);
}
@Override
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
//draw your Gui here, only thing you need to change is the path
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture);
int x = (width - xSize) / 2;
int y = (height - ySize) / 2;
this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
if (player != null && player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() instanceof ItemSigilHolding)
{
if (ItemSigilHolding.getCurrentSigil(player.getHeldItemMainhand()) != null)
{
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(texture);
this.drawTexturedModalRect(4 + x + 36 * ItemSigilHolding.getCurrentItemOrdinal(player.getHeldItemMainhand()), y + 13, 0, 123, 24, 24);
}
}
}
}

View file

@ -0,0 +1,194 @@
package WayofTime.bloodmagic.item.inventory;
import WayofTime.bloodmagic.api.iface.ISigil;
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.FMLCommonHandler;
public class ContainerHolding extends Container
{
private final int PLAYER_INVENTORY_ROWS = 3;
private final int PLAYER_INVENTORY_COLUMNS = 9;
private final EntityPlayer player;
public final InventoryHolding inventoryHolding;
public ContainerHolding(EntityPlayer player, InventoryHolding inventoryHolding)
{
this.player = player;
this.inventoryHolding = inventoryHolding;
int currentSlotHeldIn = player.inventory.currentItem;
for (int columnIndex = 0; columnIndex < ItemSigilHolding.inventorySize; ++columnIndex)
{
this.addSlotToContainer(new SlotHolding(this, inventoryHolding, player, columnIndex, 8 + columnIndex * 36, 17));
}
for (int rowIndex = 0; rowIndex < PLAYER_INVENTORY_ROWS; ++rowIndex)
{
for (int columnIndex = 0; columnIndex < PLAYER_INVENTORY_COLUMNS; ++columnIndex)
{
this.addSlotToContainer(new Slot(player.inventory, columnIndex + rowIndex * 9 + 9, 8 + columnIndex * 18, 41 + rowIndex * 18));
}
}
for (int actionBarIndex = 0; actionBarIndex < PLAYER_INVENTORY_COLUMNS; ++actionBarIndex)
{
if (actionBarIndex == currentSlotHeldIn)
{
this.addSlotToContainer(new SlotDisabled(player.inventory, actionBarIndex, 8 + actionBarIndex * 18, 99));
}
else
{
this.addSlotToContainer(new Slot(player.inventory, actionBarIndex, 8 + actionBarIndex * 18, 99));
}
}
}
@Override
public boolean canInteractWith(EntityPlayer entityPlayer)
{
return true;
}
@Override
public void onContainerClosed(EntityPlayer entityPlayer)
{
super.onContainerClosed(entityPlayer);
if (!entityPlayer.worldObj.isRemote)
{
saveInventory(entityPlayer);
}
}
@Override
public void detectAndSendChanges()
{
super.detectAndSendChanges();
if (!player.worldObj.isRemote)
{
saveInventory(player);
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer entityPlayer, int slotIndex)
{
ItemStack stack = null;
Slot slotObject = (Slot) inventorySlots.get(slotIndex);
int slots = inventorySlots.size();
if (slotObject != null && slotObject.getHasStack())
{
ItemStack stackInSlot = slotObject.getStack();
stack = stackInSlot.copy();
if (stack.getItem() instanceof ISigil)
{
if (slotIndex < ItemSigilHolding.inventorySize)
{
if (!this.mergeItemStack(stackInSlot, ItemSigilHolding.inventorySize, slots, false))
{
return null;
}
}
else if (!this.mergeItemStack(stackInSlot, 0, ItemSigilHolding.inventorySize, false))
{
return null;
}
}
else if (stack.getItem() instanceof ItemSigilHolding)
{
if (slotIndex < ItemSigilHolding.inventorySize + (PLAYER_INVENTORY_ROWS * PLAYER_INVENTORY_COLUMNS))
{
if (!this.mergeItemStack(stackInSlot, ItemSigilHolding.inventorySize + (PLAYER_INVENTORY_ROWS * PLAYER_INVENTORY_COLUMNS), inventorySlots.size(), false))
{
return null;
}
}
else if (!this.mergeItemStack(stackInSlot, ItemSigilHolding.inventorySize, ItemSigilHolding.inventorySize + (PLAYER_INVENTORY_ROWS * PLAYER_INVENTORY_COLUMNS), false))
{
return null;
}
}
if (stackInSlot.stackSize == 0)
{
slotObject.putStack(null);
} else
{
slotObject.onSlotChanged();
}
if (stackInSlot.stackSize == stack.stackSize)
{
return null;
}
slotObject.onPickupFromSlot(player, stackInSlot);
}
return stack;
}
public void saveInventory(EntityPlayer entityPlayer)
{
inventoryHolding.onGuiSaved(entityPlayer);
}
private class SlotHolding extends Slot
{
private final EntityPlayer player;
private ContainerHolding containerHolding;
public SlotHolding(ContainerHolding containerHolding, IInventory inventory, EntityPlayer player, int slotIndex, int x, int y)
{
super(inventory, slotIndex, x, y);
this.player = player;
this.containerHolding = containerHolding;
}
@Override
public void onSlotChanged()
{
super.onSlotChanged();
if (FMLCommonHandler.instance().getEffectiveSide().isServer())
{
containerHolding.saveInventory(player);
}
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
return itemStack.getItem() instanceof ISigil && !(itemStack.getItem() instanceof ItemSigilHolding);
}
}
private class SlotDisabled extends Slot
{
public SlotDisabled(IInventory inventory, int slotIndex, int x, int y)
{
super(inventory, slotIndex, x, y);
}
@Override
public boolean isItemValid(ItemStack itemStack)
{
return false;
}
@Override
public boolean canTakeStack(EntityPlayer player)
{
return false;
}
}
}

View file

@ -0,0 +1,101 @@
package WayofTime.bloodmagic.item.inventory;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.iface.ISigil;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import java.util.UUID;
public class InventoryHolding extends ItemInventory
{
protected ItemStack[] inventory;
public InventoryHolding(ItemStack itemStack)
{
super(itemStack, ItemSigilHolding.inventorySize, "SigilOfHolding");
// readFromNBT(itemStack.getTagCompound());
}
public void onGuiSaved(EntityPlayer entityPlayer)
{
masterStack = findParentStack(entityPlayer);
if (masterStack != null)
{
save();
}
}
public ItemStack findParentStack(EntityPlayer entityPlayer)
{
if (hasUUID(masterStack))
{
UUID parentStackUUID = new UUID(masterStack.getTagCompound().getLong(Constants.NBT.MOST_SIG), masterStack.getTagCompound().getLong(Constants.NBT.LEAST_SIG));
for (int i = 0; i < entityPlayer.inventory.getSizeInventory(); i++)
{
ItemStack itemStack = entityPlayer.inventory.getStackInSlot(i);
if (hasUUID(itemStack))
{
if (itemStack.getTagCompound().getLong(Constants.NBT.MOST_SIG) == parentStackUUID.getMostSignificantBits() && itemStack.getTagCompound().getLong(Constants.NBT.LEAST_SIG) == parentStackUUID.getLeastSignificantBits())
{
return itemStack;
}
}
}
}
return null;
}
public void save()
{
NBTTagCompound nbtTagCompound = masterStack.getTagCompound();
if (nbtTagCompound == null)
{
nbtTagCompound = new NBTTagCompound();
UUID uuid = UUID.randomUUID();
nbtTagCompound.setLong(Constants.NBT.MOST_SIG, uuid.getMostSignificantBits());
nbtTagCompound.setLong(Constants.NBT.LEAST_SIG, uuid.getLeastSignificantBits());
}
writeToNBT(nbtTagCompound);
masterStack.setTagCompound(nbtTagCompound);
}
@Override
public boolean isItemValidForSlot(int slotIndex, ItemStack itemStack)
{
return itemStack.getItem() instanceof ISigil && !(itemStack.getItem() instanceof ItemSigilHolding);
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
public static boolean hasUUID(ItemStack itemStack)
{
return itemStack.getTagCompound().hasKey(Constants.NBT.MOST_SIG) && itemStack.getTagCompound().hasKey(Constants.NBT.LEAST_SIG);
}
public static void setUUID(ItemStack itemStack)
{
itemStack = NBTHelper.checkNBT(itemStack);
if (!itemStack.getTagCompound().hasKey(Constants.NBT.MOST_SIG) && !itemStack.getTagCompound().hasKey(Constants.NBT.LEAST_SIG))
{
UUID itemUUID = UUID.randomUUID();
itemStack.getTagCompound().setLong(Constants.NBT.MOST_SIG, itemUUID.getMostSignificantBits());
itemStack.getTagCompound().setLong(Constants.NBT.LEAST_SIG, itemUUID.getLeastSignificantBits());
}
}
}

View file

@ -50,7 +50,7 @@ public class ItemInventory implements IInventory
public void readFromNBT(NBTTagCompound tagCompound) public void readFromNBT(NBTTagCompound tagCompound)
{ {
NBTTagList tags = tagCompound.getTagList("Items", 10); NBTTagList tags = tagCompound.getTagList(Constants.NBT.ITEMS, 10);
inventory = new ItemStack[getSizeInventory()]; inventory = new ItemStack[getSizeInventory()];
for (int i = 0; i < tags.tagCount(); i++) for (int i = 0; i < tags.tagCount(); i++)
@ -58,7 +58,7 @@ public class ItemInventory implements IInventory
if (!isSyncedSlot(i)) if (!isSyncedSlot(i))
{ {
NBTTagCompound data = tags.getCompoundTagAt(i); NBTTagCompound data = tags.getCompoundTagAt(i);
byte j = data.getByte("Slot"); byte j = data.getByte(Constants.NBT.SLOT);
if (j >= 0 && j < inventory.length) if (j >= 0 && j < inventory.length)
{ {
@ -77,13 +77,13 @@ public class ItemInventory implements IInventory
if ((inventory[i] != null) && !isSyncedSlot(i)) if ((inventory[i] != null) && !isSyncedSlot(i))
{ {
NBTTagCompound data = new NBTTagCompound(); NBTTagCompound data = new NBTTagCompound();
data.setByte("Slot", (byte) i); data.setByte(Constants.NBT.SLOT, (byte) i);
inventory[i].writeToNBT(data); inventory[i].writeToNBT(data);
tags.appendTag(data); tags.appendTag(data);
} }
} }
tagCompound.setTag("Items", tags); tagCompound.setTag(Constants.NBT.ITEMS, tags);
} }
public void readFromStack(ItemStack masterStack) public void readFromStack(ItemStack masterStack)

View file

@ -0,0 +1,305 @@
package WayofTime.bloodmagic.item.sigil;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.api.util.helper.NBTHelper;
import WayofTime.bloodmagic.item.inventory.InventoryHolding;
import WayofTime.bloodmagic.util.handler.BMKeyBinding;
import WayofTime.bloodmagic.util.handler.IKeybindable;
import WayofTime.bloodmagic.util.helper.TextHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import java.util.List;
public class ItemSigilHolding extends ItemSigilBase implements IKeybindable
{
public static int inventorySize;
public ItemSigilHolding()
{
super("holding");
inventorySize = 5;
}
@Override
public void onKeyPressed(ItemStack stack, EntityPlayer player, BMKeyBinding.Key key, boolean showInChat)
{
if (stack == player.getHeldItemMainhand() && stack.getItem() instanceof ItemSigilHolding && key.equals(BMKeyBinding.Key.OPEN_SIGIL_HOLDING))
{
InventoryHolding.setUUID(stack);
player.openGui(BloodMagic.instance, Constants.Gui.SIGIL_HOLDING_GUI, player.worldObj, (int) player.posX, (int) player.posY, (int) player.posZ);
}
}
@Override
public String getHighlightTip(ItemStack stack, String displayName)
{
ItemStack[] inv = getInternalInventory(stack);
if (inv == null)
return displayName;
int currentSlot = getCurrentItemOrdinal(stack);
ItemStack item = inv[currentSlot];
if (item == null)
return displayName;
else
return TextHelper.localizeEffect("item.BloodMagic.sigil.holding.display", displayName, item.getDisplayName());
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced)
{
super.addInformation(stack, player, tooltip, advanced);
ItemStack[] inv = getInternalInventory(stack);
if (inv == null)
return;
int currentSlot = getCurrentItemOrdinal(stack);
ItemStack item = inv[currentSlot];
for (int i = 0; i < inventorySize; i++)
{
if (inv[i] != null)
if (item != null && inv[i] == item)
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.sigil.holding.sigilInSlot", i + 1, "&l&n" + inv[i].getDisplayName() + "&r"));
else
tooltip.add(TextHelper.localizeEffect("tooltip.BloodMagic.sigil.holding.sigilInSlot", i + 1, inv[i].getDisplayName()));
}
}
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
{
int currentSlot = getCurrentItemOrdinal(stack);
ItemStack[] inv = getInternalInventory(stack);
if (inv == null)
return EnumActionResult.PASS;
ItemStack itemUsing = inv[currentSlot];
if (itemUsing == null)
return EnumActionResult.PASS;
EnumActionResult result = itemUsing.getItem().onItemUseFirst(itemUsing, player, world, pos, side, hitX, hitY, hitZ, hand);
saveInventory(stack, inv);
return result;
}
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
{
int currentSlot = getCurrentItemOrdinal(stack);
ItemStack[] inv = getInternalInventory(stack);
if (inv == null)
return EnumActionResult.PASS;
ItemStack itemUsing = inv[currentSlot];
if (itemUsing == null)
return EnumActionResult.PASS;
EnumActionResult result = itemUsing.getItem().onItemUse(itemUsing, playerIn, worldIn, pos, hand, facing, hitX, hitY, hitZ);
saveInventory(stack, inv);
return result;
}
@Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand)
{
int currentSlot = getCurrentItemOrdinal(stack);
ItemStack[] inv = getInternalInventory(stack);
if (inv == null)
return ActionResult.newResult(EnumActionResult.PASS, stack);
ItemStack itemUsing = inv[currentSlot];
if (itemUsing == null)
return ActionResult.newResult(EnumActionResult.PASS, stack);
itemUsing.getItem().onItemRightClick(itemUsing, world, player, hand);
saveInventory(stack, inv);
return ActionResult.newResult(EnumActionResult.PASS, stack);
}
public void saveInventory(ItemStack itemStack, ItemStack[] inventory)
{
NBTTagCompound itemTag = itemStack.getTagCompound();
if (itemTag == null)
{
itemStack.setTagCompound(new NBTTagCompound());
}
NBTTagList itemList = new NBTTagList();
for (int i = 0; i < inventorySize; i++)
{
if (inventory[i] != null)
{
NBTTagCompound tag = new NBTTagCompound();
tag.setByte(Constants.NBT.SLOT, (byte) i);
inventory[i].writeToNBT(tag);
itemList.appendTag(tag);
}
}
itemTag.setTag(Constants.NBT.ITEMS, itemList);
}
@Override
public void onUpdate(ItemStack itemStack, World world, Entity entity, int itemSlot, boolean isSelected)
{
if (itemStack.getTagCompound() != null)
{
this.tickInternalInventory(itemStack, world, entity, itemSlot, isSelected);
}
}
public void tickInternalInventory(ItemStack itemStack, World world, Entity entity, int itemSlot, boolean isSelected)
{
ItemStack[] inv = getInternalInventory(itemStack);
if (inv == null)
{
return;
}
for (int i = 0; i < inventorySize; i++)
{
if (inv[i] == null)
{
continue;
}
inv[i].getItem().onUpdate(inv[i], world, entity, itemSlot, isSelected);
}
}
public static int next(int mode)
{
int index = mode + 1;
if (index >= inventorySize)
{
index = 0;
}
return index;
}
public static int prev(int mode)
{
int index = mode - 1;
if (index < 0)
{
index = inventorySize;
}
return index;
}
private static void initModeTag(ItemStack itemStack)
{
if (itemStack.getTagCompound() == null)
{
itemStack = NBTHelper.checkNBT(itemStack);
itemStack.getTagCompound().setInteger(Constants.NBT.CURRENT_SIGIL, inventorySize);
}
}
public static ItemStack getCurrentSigil(ItemStack itemStack)
{
if (itemStack.getItem() instanceof ItemSigilHolding)
{
ItemStack[] itemStacks = getInternalInventory(itemStack);
if (itemStacks != null)
{
return itemStacks[getCurrentItemOrdinal(itemStack)];
}
}
return null;
}
public static int getCurrentItemOrdinal(ItemStack itemStack)
{
if (itemStack.getItem() instanceof ItemSigilHolding)
{
initModeTag(itemStack);
int currentSigil = itemStack.getTagCompound().getInteger(Constants.NBT.CURRENT_SIGIL);
currentSigil = MathHelper.clamp_int(currentSigil, 0, inventorySize - 1);
return currentSigil;
}
return 0;
}
public static ItemStack[] getInternalInventory(ItemStack itemStack)
{
initModeTag(itemStack);
NBTTagCompound tagCompound = itemStack.getTagCompound();
if (tagCompound == null)
{
return null;
}
NBTTagList tagList = tagCompound.getTagList(Constants.NBT.ITEMS, 10);
if (tagList == null)
{
return null;
}
ItemStack[] inv = new ItemStack[inventorySize];
for (int i = 0; i < tagList.tagCount(); i++)
{
NBTTagCompound data = tagList.getCompoundTagAt(i);
byte j = data.getByte(Constants.NBT.SLOT);
if (j >= 0 && j < inv.length)
{
inv[j] = ItemStack.loadItemStackFromNBT(data);
}
}
return inv;
}
public static void cycleSigil(ItemStack itemStack, int mode)
{
if (itemStack.getItem() instanceof ItemSigilHolding)
{
initModeTag(itemStack);
itemStack.getTagCompound().setInteger(Constants.NBT.CURRENT_SIGIL, mode);
}
}
}

View file

@ -19,6 +19,8 @@ public class BloodMagicPacketHandler
INSTANCE.registerMessage(ItemRouterButtonPacketProcessor.class, ItemRouterButtonPacketProcessor.class, 1, Side.SERVER); INSTANCE.registerMessage(ItemRouterButtonPacketProcessor.class, ItemRouterButtonPacketProcessor.class, 1, Side.SERVER);
INSTANCE.registerMessage(PlayerVelocityPacketProcessor.class, PlayerVelocityPacketProcessor.class, 2, Side.CLIENT); INSTANCE.registerMessage(PlayerVelocityPacketProcessor.class, PlayerVelocityPacketProcessor.class, 2, Side.CLIENT);
INSTANCE.registerMessage(PlayerFallDistancePacketProcessor.class, PlayerFallDistancePacketProcessor.class, 3, Side.SERVER); INSTANCE.registerMessage(PlayerFallDistancePacketProcessor.class, PlayerFallDistancePacketProcessor.class, 3, Side.SERVER);
INSTANCE.registerMessage(SigilHoldingPacketProcessor.class, SigilHoldingPacketProcessor.class, 4, Side.SERVER);
INSTANCE.registerMessage(KeyProcessor.class, KeyProcessor.class, 5, Side.SERVER);
} }
public static void sendToAllAround(IMessage message, TileEntity te, int range) public static void sendToAllAround(IMessage message, TileEntity te, int range)

View file

@ -0,0 +1,61 @@
package WayofTime.bloodmagic.network;
import WayofTime.bloodmagic.util.handler.BMKeyBinding;
import WayofTime.bloodmagic.util.handler.IKeybindable;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class KeyProcessor implements IMessage, IMessageHandler<KeyProcessor, IMessage>
{
public int keyId;
public boolean showInChat;
public KeyProcessor()
{
}
public KeyProcessor(BMKeyBinding.Key key, boolean showInChat)
{
this.keyId = key.ordinal();
this.showInChat = showInChat;
}
@Override
public void fromBytes(ByteBuf buf)
{
this.keyId = buf.readInt();
this.showInChat = buf.readBoolean();
}
@Override
public void toBytes(ByteBuf buf)
{
buf.writeInt(this.keyId);
buf.writeBoolean(this.showInChat);
}
@Override
public IMessage onMessage(KeyProcessor msg, MessageContext ctx)
{
EntityPlayer entityPlayer = ctx.getServerHandler().playerEntity;
if (entityPlayer != null)
{
ItemStack heldStack = entityPlayer.getHeldItemMainhand();
if (heldStack.getItem() instanceof IKeybindable)
{
if (msg.keyId < 0 || msg.keyId >= BMKeyBinding.Key.values().length)
{
return null;
}
BMKeyBinding.Key key = BMKeyBinding.Key.values()[msg.keyId];
((IKeybindable) heldStack.getItem()).onKeyPressed(heldStack, entityPlayer, key, msg.showInChat);
}
}
return null;
}
}

View file

@ -0,0 +1,56 @@
package WayofTime.bloodmagic.network;
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class SigilHoldingPacketProcessor implements IMessage, IMessageHandler<SigilHoldingPacketProcessor, IMessage>
{
private int slot;
private int mode;
public SigilHoldingPacketProcessor()
{
}
public SigilHoldingPacketProcessor(int slot, int mode)
{
this.slot = slot;
this.mode = mode;
}
@Override
public void toBytes(ByteBuf buffer)
{
buffer.writeInt(slot);
buffer.writeInt(mode);
}
@Override
public void fromBytes(ByteBuf buffer)
{
slot = buffer.readInt();
mode = buffer.readInt();
}
@Override
public IMessage onMessage(SigilHoldingPacketProcessor message, MessageContext ctx)
{
ItemStack itemStack = null;
if (message.slot > -1 && message.slot < 9)
{
itemStack = ctx.getServerHandler().playerEntity.inventory.getStackInSlot(message.slot);
}
if (itemStack != null)
{
ItemSigilHolding.cycleSigil(itemStack, message.mode);
}
return null;
}
}

View file

@ -40,7 +40,6 @@ import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import org.apache.commons.lang3.tuple.Pair; import org.apache.commons.lang3.tuple.Pair;
import java.awt.*; import java.awt.*;
import java.lang.reflect.Field;
public class ClientProxy extends CommonProxy public class ClientProxy extends CommonProxy
{ {

View file

@ -50,6 +50,7 @@ import WayofTime.bloodmagic.item.sigil.ItemSigilEnderSeverance;
import WayofTime.bloodmagic.item.sigil.ItemSigilFastMiner; import WayofTime.bloodmagic.item.sigil.ItemSigilFastMiner;
import WayofTime.bloodmagic.item.sigil.ItemSigilGreenGrove; import WayofTime.bloodmagic.item.sigil.ItemSigilGreenGrove;
import WayofTime.bloodmagic.item.sigil.ItemSigilHaste; import WayofTime.bloodmagic.item.sigil.ItemSigilHaste;
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
import WayofTime.bloodmagic.item.sigil.ItemSigilLava; import WayofTime.bloodmagic.item.sigil.ItemSigilLava;
import WayofTime.bloodmagic.item.sigil.ItemSigilMagnetism; import WayofTime.bloodmagic.item.sigil.ItemSigilMagnetism;
import WayofTime.bloodmagic.item.sigil.ItemSigilPhantomBridge; import WayofTime.bloodmagic.item.sigil.ItemSigilPhantomBridge;
@ -113,6 +114,7 @@ public class ModItems
public static Item sigilWhirlwind; public static Item sigilWhirlwind;
public static Item sigilPhantomBridge; public static Item sigilPhantomBridge;
public static Item sigilCompression; public static Item sigilCompression;
public static Item sigilHolding;
public static Item sigilTeleposition; public static Item sigilTeleposition;
public static Item sigilTransposition; public static Item sigilTransposition;
@ -210,6 +212,7 @@ public class ModItems
sigilWhirlwind = registerItem(new ItemSigilWhirlwind(), Constants.BloodMagicItem.SIGIL_WHIRLWIND.getRegName()); sigilWhirlwind = registerItem(new ItemSigilWhirlwind(), Constants.BloodMagicItem.SIGIL_WHIRLWIND.getRegName());
sigilCompression = registerItem(new ItemSigilCompression(), Constants.BloodMagicItem.SIGIL_COMPRESSION.getRegName()); sigilCompression = registerItem(new ItemSigilCompression(), Constants.BloodMagicItem.SIGIL_COMPRESSION.getRegName());
sigilEnderSeverance = registerItem(new ItemSigilEnderSeverance(), Constants.BloodMagicItem.SIGIL_ENDER_SEVERANCE.getRegName()); sigilEnderSeverance = registerItem(new ItemSigilEnderSeverance(), Constants.BloodMagicItem.SIGIL_ENDER_SEVERANCE.getRegName());
sigilHolding = registerItem(new ItemSigilHolding(), Constants.BloodMagicItem.SIGIL_HOLDING.getRegName());
sigilTeleposition = registerItem(new ItemSigilTeleposition(), Constants.BloodMagicItem.SIGIL_TELEPOSITION.getRegName()); sigilTeleposition = registerItem(new ItemSigilTeleposition(), Constants.BloodMagicItem.SIGIL_TELEPOSITION.getRegName());
sigilTransposition = registerItem(new ItemSigilTransposition(), Constants.BloodMagicItem.SIGIL_TRANSPOSITION.getRegName()); sigilTransposition = registerItem(new ItemSigilTransposition(), Constants.BloodMagicItem.SIGIL_TRANSPOSITION.getRegName());

View file

@ -0,0 +1,36 @@
package WayofTime.bloodmagic.util.handler;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.network.KeyProcessor;
import WayofTime.bloodmagic.util.handler.event.ClientHandler;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.client.registry.ClientRegistry;
public class BMKeyBinding extends KeyBinding
{
private Key keyType;
public BMKeyBinding(String name, int keyId, Key keyType)
{
super(Constants.Mod.MODID + ".keybind." + name, keyId, Constants.Mod.NAME);
this.keyType = keyType;
ClientRegistry.registerKeyBinding(this);
ClientHandler.keyBindings.add(this);
}
public void handleKeyPress()
{
ItemStack itemStack = ClientHandler.minecraft.thePlayer.getHeldItemMainhand();
if (itemStack.getItem() instanceof IKeybindable)
{
BloodMagicPacketHandler.INSTANCE.sendToServer(new KeyProcessor(this.keyType, false));
}
}
public enum Key
{
OPEN_SIGIL_HOLDING
}
}

View file

@ -0,0 +1,9 @@
package WayofTime.bloodmagic.util.handler;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public interface IKeybindable
{
void onKeyPressed(ItemStack stack, EntityPlayer player, BMKeyBinding.Key key, boolean showInChat);
}

View file

@ -10,28 +10,38 @@ import WayofTime.bloodmagic.api.ritual.RitualComponent;
import WayofTime.bloodmagic.client.render.RenderFakeBlocks; import WayofTime.bloodmagic.client.render.RenderFakeBlocks;
import WayofTime.bloodmagic.item.ItemRitualDiviner; import WayofTime.bloodmagic.item.ItemRitualDiviner;
import WayofTime.bloodmagic.item.ItemRitualReader; import WayofTime.bloodmagic.item.ItemRitualReader;
import WayofTime.bloodmagic.item.sigil.ItemSigilHolding;
import WayofTime.bloodmagic.network.BloodMagicPacketHandler;
import WayofTime.bloodmagic.network.SigilHoldingPacketProcessor;
import WayofTime.bloodmagic.tile.TileMasterRitualStone; import WayofTime.bloodmagic.tile.TileMasterRitualStone;
import WayofTime.bloodmagic.util.GhostItemHelper; import WayofTime.bloodmagic.util.GhostItemHelper;
import WayofTime.bloodmagic.util.handler.BMKeyBinding;
import WayofTime.bloodmagic.util.helper.TextHelper; import WayofTime.bloodmagic.util.helper.TextHelper;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*; import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.client.event.MouseEvent;
import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.InputEvent;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.input.Keyboard;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Handler @Handler
@ -46,7 +56,11 @@ public class ClientHandler
public TextureAtlasSprite ritualStoneDawn; public TextureAtlasSprite ritualStoneDawn;
public TextureAtlasSprite ritualStoneDusk; public TextureAtlasSprite ritualStoneDusk;
private static Minecraft minecraft = Minecraft.getMinecraft(); public static Minecraft minecraft = Minecraft.getMinecraft();
public static final List<BMKeyBinding> keyBindings = new ArrayList<BMKeyBinding>();
public static final BMKeyBinding keyOpenSigilHolding = new BMKeyBinding("openSigilHolding", Keyboard.KEY_H, BMKeyBinding.Key.OPEN_SIGIL_HOLDING);
@SubscribeEvent @SubscribeEvent
public void onTooltipEvent(ItemTooltipEvent event) public void onTooltipEvent(ItemTooltipEvent event)
@ -102,6 +116,36 @@ public class ClientHandler
renderRitualInformation(player, event.getPartialTicks()); renderRitualInformation(player, event.getPartialTicks());
} }
@SubscribeEvent
public void onMouseEvent(MouseEvent event)
{
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
if (event.getDwheel() != 0 && player != null && player.isSneaking())
{
ItemStack stack = player.getHeldItemMainhand();
if (stack != null)
{
Item item = stack.getItem();
if (item instanceof ItemSigilHolding)
{
cycleSigil(stack, player, event.getDwheel());
event.setCanceled(true);
}
}
}
}
private void cycleSigil(ItemStack stack, EntityPlayer player, int dWheel)
{
int mode = ItemSigilHolding.getCurrentItemOrdinal(stack);
mode = dWheel < 0 ? ItemSigilHolding.next(mode) : ItemSigilHolding.prev(mode);
ItemSigilHolding.cycleSigil(stack, mode);
BloodMagicPacketHandler.INSTANCE.sendToServer(new SigilHoldingPacketProcessor(player.inventory.currentItem, mode));
}
private static TextureAtlasSprite forName(TextureMap textureMap, String name, String dir) private static TextureAtlasSprite forName(TextureMap textureMap, String name, String dir)
{ {
return textureMap.registerSprite(new ResourceLocation(Constants.Mod.DOMAIN + dir + "/" + name)); return textureMap.registerSprite(new ResourceLocation(Constants.Mod.DOMAIN + dir + "/" + name));
@ -187,4 +231,17 @@ public class ClientHandler
GlStateManager.popMatrix(); GlStateManager.popMatrix();
} }
@SubscribeEvent
public void onKey(InputEvent event)
{
if (!minecraft.inGameHasFocus)
return;
for (BMKeyBinding key : keyBindings)
{
if (key.isPressed())
key.handleKeyPress();
}
}
} }

View file

@ -0,0 +1,16 @@
{
"forge_marker": 1,
"defaults": {
"model": "builtin/generated",
"transform": "forge:default-item"
},
"variants": {
"type": {
"normal": {
"textures": {
"layer0": "bloodmagic:items/SigilOfHolding"
}
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.2 KiB

View file

@ -122,6 +122,8 @@ item.BloodMagic.sigil.seer.name=Seer's Sigil
item.BloodMagic.sigil.phantomBridge.name=Sigil of the Phantom Bridge item.BloodMagic.sigil.phantomBridge.name=Sigil of the Phantom Bridge
item.BloodMagic.sigil.whirlwind.name=Sigil of the Whirlwind item.BloodMagic.sigil.whirlwind.name=Sigil of the Whirlwind
item.BloodMagic.sigil.enderSeverance.name=Sigil of Ender Severance item.BloodMagic.sigil.enderSeverance.name=Sigil of Ender Severance
item.BloodMagic.sigil.holding.name=Sigil of Holding
item.BloodMagic.sigil.holding.display=%s: &l&n%s
item.BloodMagic.sigil.teleposition.name=Teleposition Sigil item.BloodMagic.sigil.teleposition.name=Teleposition Sigil
item.BloodMagic.sigil.transposition.name=Transposition Sigil item.BloodMagic.sigil.transposition.name=Transposition Sigil
@ -283,6 +285,8 @@ tooltip.BloodMagic.sigil.whirlwind.desc=&oBest not to wear a skirt
tooltip.BloodMagic.sigil.enderSeverance.desc=&oPutting Endermen in Dire situations! tooltip.BloodMagic.sigil.enderSeverance.desc=&oPutting Endermen in Dire situations!
tooltip.BloodMagic.sigil.teleposition.desc=I am very close to being moved by this. tooltip.BloodMagic.sigil.teleposition.desc=I am very close to being moved by this.
tooltip.BloodMagic.sigil.transposition.desc=Feel the power of the Force, my young apprentice. tooltip.BloodMagic.sigil.transposition.desc=Feel the power of the Force, my young apprentice.
tooltip.BloodMagic.sigil.holding.desc=Sigil-ception
tooltip.BloodMagic.sigil.holding.sigilInSlot=Slot %d: %s
tooltip.BloodMagic.bound.sword.desc=&oCulling the weak tooltip.BloodMagic.bound.sword.desc=&oCulling the weak
tooltip.BloodMagic.bound.pickaxe.desc=&oDestroying stone without mercy tooltip.BloodMagic.bound.pickaxe.desc=&oDestroying stone without mercy
@ -588,6 +592,9 @@ commands.soulnetwork.notACommand=That is not a valid command
commands.soulnetwork.fillMax.success=Successfully filled %s's Soul Network to their orb max! commands.soulnetwork.fillMax.success=Successfully filled %s's Soul Network to their orb max!
commands.soulnetwork.create.success=Successfully created %s's Soul Network (Orb tier: %d) commands.soulnetwork.create.success=Successfully created %s's Soul Network (Orb tier: %d)
# Keybinds
BloodMagic.keybind.openSigilHolding=Open Sigil of Holding
# JustEnoughItems # JustEnoughItems
jei.BloodMagic.recipe.altar=Blood Altar jei.BloodMagic.recipe.altar=Blood Altar
jei.BloodMagic.recipe.binding=Alchemy Array (Binding) jei.BloodMagic.recipe.binding=Alchemy Array (Binding)