Jump to content

p455w0rd

Forge Modder
  • Posts

    61
  • Joined

  • Last visited

Everything posted by p455w0rd

  1. My shield extends the vanilla shield and I use this: @SubscribeEvent public void attackEvent(LivingAttackEvent e) { float damage = e.getAmount(); ItemStack activeItemStack; EntityPlayer player; if (!(e.getEntityLiving() instanceof EntityPlayer)) { return; } player = (EntityPlayer) e.getEntityLiving(); if (player.getActiveItemStack() == null) { return; } activeItemStack = player.getActiveItemStack(); if (damage > 0.0F && activeItemStack != null && activeItemStack.getItem() instanceof ItemShield) { int i = 1 + MathHelper.floor_float(damage); activeItemStack.damageItem(i, player); if (activeItemStack.stackSize <= 0) { EnumHand enumhand = player.getActiveHand(); net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem(player, activeItemStack, enumhand); if (enumhand == EnumHand.MAIN_HAND) { player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, (ItemStack) null); } else { player.setItemStackToSlot(EntityEquipmentSlot.OFFHAND, (ItemStack) null); } activeItemStack = null; if (FMLCommonHandler.instance().getSide() == Side.CLIENT) { player.playSound(SoundEvents.ITEM_SHIELD_BREAK, 0.8F, 0.8F + player.worldObj.rand.nextFloat() * 0.4F); } } } }
  2. Updated GuiCompressor to have actual dimensions set (xSize is 176): https://github.com/p455w0rd/p455w0rds1.9Things/blob/master/src/java/p455w0rd/p455w0rdsthings/client/gui/GuiCompressor.java Also all other code related to compressor machine is now using IItemHandler: ContainerCompressor: https://github.com/p455w0rd/p455w0rds1.9Things/blob/master/src/java/p455w0rd/p455w0rdsthings/container/ContainerCompressor.java TileEntityCompressor: https://github.com/p455w0rd/p455w0rds1.9Things/blob/master/src/java/p455w0rd/p455w0rdsthings/blocks/tileentities/TileEntityCompressor.java It definitely reminds of the issue I had a good while back when working on the Wireless Crafting Terminal when I had forgotten to set the dimensions of the GUI. The difference is that setting that info did nothing for the issue I'm experiencing currently.
  3. it depends on how you're making your model..if you're using a JSON model (ala Crayfish's Model Creator or the like), then yes
  4. We're dissuaded from teaching basic Java things here, but you need to reference an item in the list..you're trying to use the entire list..so if you're wanting the first item returned, you'd need to use get(), so: ItemStack copper = OreDictionary.getOres("ingotCopper").get(0); but you'd really need to encase this whole functionality with a check for if there is even anything in the list of ingotCopper
  5. you'd need to load the list of items registered as ingotCopper and use one of the results.. So for copper ingots, to get the list you'd use OreDictionary.getOres("ingotCopper") ..this returns an ArrayList you can go through and set preference or w/e or just return first result..
  6. While I had forgotten to do that, it isn't the problem. I tried using the default texture/sizes from GuiContainer and I tried using custom xSize/ySize (set in constructor) to no avail.
  7. Okay, so I converted to IItemHandler (via Choonster's Examples)..same thing persists. (And I figured as much would be the case). So I'm stumped still. I've tried all sorts of combinations of ordering the slots in the container with the only positive result being that when I add hotbar slots, followed by the 27 player inv slots, followed by the 2 custom slots, the player inv slots function correctly..still can't pick up hotbar items and when I click either of the 2 custom slots, it acts as if I'm clicking slots 0/1 on the hotbar. I am able to successfully insert items via a hopper. Updates to code can be found on github @ https://github.com/p455w0rd/p455w0rds1.9Things
  8. Well, my TE implements ISidedInventory which extends IInventory which is a separate inventory from InventoryPlayer, no? Are these not two different inventories?
  9. In my Wireless Crafting Terminal mod, as well as my /dank/null item and BedrockMiner's tutorial on the subject @ http://bedrockminer.jimdo.com/modding-tutorials/advanced-modding/gui-container/ , there are multiple slots assigned with same ID's and they work perfectly. (slots 0-8 in BRM's tutorial are assigned IDs 0-8..slots 36-44 are also assigned ID's of 0-...I'm lost...
  10. check out https://github.com/p455w0rd/p455w0rds1.9Things/blob/master/src/java/p455w0rd/p455w0rdsthings/client/render/TESRCompressor.java#L145-L182 ..it doesn't "bob", but that would be simple enough to implement.
  11. I wish this were true, but those id's are setting the ID of the referenced inventory (TileEntity in this case), where the player inventory is a separate inventory with it's own set of IDs. The slot number of the container is set as slots are added (via the inventorySlots list in net.minecraft.inventory.Container).
  12. gif of what is happening: I had this working in 1.9 and somewhere along the way after updating to 1.9.4 it started doing this stuff. I'm assuming this is due to my lack of knowledge of TileEntities as I have no issues when I do this using a normal IInventory. I have been racking my brain for over a week on this. I don't know where I'm going wrong. ContainerCompressor public class ContainerCompressor extends Container { public TileEntityCompressor tileEntity; private final InventoryPlayer inventoryPlayer; public ContainerCompressor(InventoryPlayer inventoryPlayer, TileEntityCompressor te) { this.tileEntity = te; this.inventoryPlayer = inventoryPlayer; int xbase = 8; int ybase = 70; for (int i = 0; i < 9; i++) { addSlotToContainer(new Slot(this.inventoryPlayer, i, xbase + i * 18, ybase + 58)); } for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(this.inventoryPlayer, j + i * 9 + 9, xbase + j * 18, ybase + i * 18)); } } // Input Slot addSlotToContainer(new CompressorSlot(this.tileEntity, 0, 49, 18)); // Output Slot addSlotToContainer(new CompressorSlot(this.tileEntity, 1, 106, 18)); } @Override public boolean canInteractWith(EntityPlayer player) { return true; } @Override public ItemStack slotClick(int slotId, int dragType, ClickType clickTypeIn, EntityPlayer player) { System.out.println("Slot: "+slotId); ItemStack itemstack = null; InventoryPlayer inventoryplayer = player.inventory; if (slotId > 35) { return null; } return super.slotClick(slotId, dragType, clickTypeIn, player); } @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { ItemStack stack = null; try { Slot slotObject = (Slot) inventorySlots.get(slot); // null checks and checks if the item can be stacked (maxStackSize > // 1) if (slotObject != null && slotObject.getHasStack()) { ItemStack stackInSlot = slotObject.getStack(); stack = stackInSlot.copy(); // Block->Player Inventory if (slot > 35) { if (!this.mergeItemStack(stackInSlot, 0, 36, true)) { return null; } // Player->Block Inventory } else if (!this.mergeItemStack(stackInSlot, 36, 37, false)) { return null; } if (stackInSlot.stackSize <= 0) { slotObject.putStack(null); } else { slotObject.onSlotChanged(); } if (stackInSlot.stackSize == stack.stackSize) { return null; } slotObject.onPickupFromSlot(player, stackInSlot); } } catch (Exception e) { } return stack; } } TileEntityCompressor public class TileEntityCompressor extends TileEntity implements IPEnergyBlock, ISidedInventory, IPEnergyBlock.Receiver { protected ItemStack[] compressorInv; protected int capacity; protected int maxReceive; protected int maxExtract; protected EnergyStorage energyStorage; private boolean isProcessing; private float pctCompleted; public float ticks = 0; public float rotation = 0; public boolean rev = false; public TileEntityCompressor() { capacity = 1600000; maxReceive = 2000; maxExtract = 2000; compressorInv = new ItemStack[2]; energyStorage = new EnergyStorage(capacity, maxReceive); } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound nbtTag = new NBTTagCompound(); this.writeToNBT(nbtTag); return new SPacketUpdateTileEntity(getPos(), 0, nbtTag); } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) { this.readFromNBT(packet.getNbtCompound()); } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound updateTag = super.getUpdateTag(); writeToNBT(updateTag); return updateTag; } public boolean isProcessing() { return isProcessing; } public void setProcessing(boolean t) { this.isProcessing = t; } public String getName() { return "compressorBlock"; } @Override public int getSizeInventory() { return 2; } @Override public ItemStack getStackInSlot(int index) { return compressorInv[index]; } @Override public ItemStack decrStackSize(int index, int count) { ItemStack stack = ((ItemStack) compressorInv[index]); if (stack.stackSize >= count) { setInventorySlotContents(index, null); } else { setInventorySlotContents(index, new ItemStack(stack.getItem(), count)); stack.stackSize -= count; } markDirty(); return stack; } @Override public ItemStack removeStackFromSlot(int index) { ItemStack itemStack = getStackInSlot(index); if (itemStack != null) { setInventorySlotContents(index, null); } markDirty(); return itemStack; } public static boolean isSameItem(@Nullable final ItemStack left, @Nullable final ItemStack right) { return left != null && right != null && left.isItemEqual(right); } @Override public void setInventorySlotContents(final int slot, final ItemStack newItemStack) { final ItemStack oldStack = this.compressorInv[slot]; this.compressorInv[slot] = newItemStack; ItemStack removed = oldStack; ItemStack added = newItemStack; if (oldStack != null && newItemStack != null && isSameItem(oldStack, newItemStack)) { if (oldStack.stackSize > newItemStack.stackSize) { removed = removed.copy(); removed.stackSize -= newItemStack.stackSize; added = null; } else if (oldStack.stackSize < newItemStack.stackSize) { added = added.copy(); added.stackSize -= oldStack.stackSize; removed = null; } else { removed = added = null; } } this.markDirty(); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return true; } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) { } @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) { } @Override public int getFieldCount() { return 0; } @Override public void clear() { } @Override public boolean hasCustomName() { return false; } @Override public ITextComponent getDisplayName() { return new TextComponentString(getName()); } @Override public boolean canConnectEnergy(EnumFacing from) { return true; } @Override public int getEnergyStored(EnumFacing from) { return this.energyStorage.getEnergyStored(); } public int getEnergy() { return getEnergyStored(EnumFacing.DOWN); } @Override public int getMaxEnergyStored(EnumFacing from) { return energyStorage.getMaxEnergyStored(); } public int getMaxExtract() { return maxExtract; } @Override public int[] getSlotsForFace(EnumFacing side) { int[] validSlots = { 0, 1 }; return validSlots; } @Override public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) { if (index == 0) { return true; } return false; } @Override public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) { if (index == 1) { return true; } return false; } @Override public int receiveEnergy(EnumFacing from, int maxExtract, boolean simulate) { int tosend = energyStorage.receiveEnergy(maxExtract, simulate); if (tosend > 0 && !simulate) { this.markDirty(); } return tosend; } @Override public void setEnergyStored(int energy) { this.energyStorage.setEnergyStored(energy); this.markDirty(); } public EnergyStorage getEnergyStorage() { return this.energyStorage; } public int getMaxCapacity() { return getMaxEnergyStored(EnumFacing.DOWN); } public boolean hasEnergy() { return getEnergy() > 0; } private void handleProcessing() { if (hasEnergy()) { if (getOutputSlotStack() == null || getOutputSlotStack().stackSize < getOutputSlotStack().getMaxStackSize()) { } } } public ItemStack getInputSlotStack() { return compressorInv[0]; } public ItemStack getOutputSlotStack() { return compressorInv[1]; } @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagCompound energyTag = tagCompound.getCompoundTag("Energy"); this.energyStorage.readFromNBT(energyTag); NBTTagList nbtTL = tagCompound.getTagList(this.getName(), 10); for (int i = 0; i < nbtTL.tagCount(); i++) { NBTTagCompound nbtTC = (NBTTagCompound) nbtTL.getCompoundTagAt(i); if (nbtTC == null) { continue; } int slot = nbtTC.getInteger("Slot"); this.compressorInv[slot] = ItemStack.loadItemStackFromNBT(nbtTC); } } @Override public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) { tagCompound = super.writeToNBT(tagCompound); NBTTagCompound energyTag = new NBTTagCompound(); this.energyStorage.writeToNBT(energyTag); tagCompound.setTag("Energy", energyTag); NBTTagList nbtTL = new NBTTagList(); for (int i = 0; i < this.compressorInv.length; i++) { if (compressorInv[i] == null) { continue; } NBTTagCompound nbtTC = new NBTTagCompound(); nbtTC.setInteger("Slot", i); compressorInv[i].writeToNBT(nbtTC); nbtTL.appendTag(nbtTC); } tagCompound.setTag(this.getName(), nbtTL); return tagCompound; } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { /* if (index == 0 && CompressorRecipeRegistry.INSTANCE.getInputList() != null) { List<ItemStack> inputList = CompressorRecipeRegistry.INSTANCE.getInputList(); for (int i = 0; i < inputList.size(); i++) { if (ItemUtils.areItemsEqual(stack, inputList.get(i))) { return true; } } } return false; */ return true; } @Override public void update() { if (getWorld().isRemote) { return; } handleReceivingEnergy(); getWorld().markAndNotifyBlock(getPos(), getWorld().getChunkFromBlockCoords(getPos()), getWorld().getBlockState(getPos()), getWorld().getBlockState(getPos()), 3); } private void handleReceivingEnergy() { if (!worldObj.isRemote) { if (getEnergy() >= getMaxCapacity()) { return; } for (EnumFacing dir : EnumFacing.values()) { BlockPos targetBlock = getPos().add(dir.getDirectionVec()); TileEntity tile = worldObj.getTileEntity(targetBlock); if (tile instanceof IEnergyProvider) { IEnergyProvider provider = (IEnergyProvider) tile; if (provider.canConnectEnergy(dir.getOpposite())) { int toget = energyStorage.receiveEnergy(this.maxReceive, true); int received = ((IEnergyProvider) tile).extractEnergy(dir.getOpposite(), toget, false); if (received > 0) { this.markDirty(); } energyStorage.receiveEnergy(received, false); } } } } } } CompressorSlot public class CompressorSlot extends Slot { public final int xDisplayPosition; public final int yDisplayPosition; private final int slotIndex; public int slotNumber; public final IInventory inventory; public CompressorSlot(final IInventory inv, final int idx, final int x, final int y) { super(inv, idx, x, y); this.slotIndex = idx; this.xDisplayPosition = x; this.yDisplayPosition = y; this.inventory = inv; } public String getTooltip() { return null; } public void clearStack() { putStack(null); } @Override public boolean isItemValid(final ItemStack itemStackIn) { return inventory.isItemValidForSlot(getSlotIndex(), itemStackIn); } @Override public ItemStack getStack() { if (this.inventory.getSizeInventory() <= this.getSlotIndex()) { return null; } return this.inventory.getStackInSlot(this.slotIndex); } @Override public int getSlotIndex() { return this.slotIndex; } @Override public void onPickupFromSlot(EntityPlayer playerIn, ItemStack stack) { this.onSlotChanged(); } @SideOnly(Side.CLIENT) public boolean canBeHovered() { return true; } @Override public boolean getHasStack() { return this.getStack() != null; } @Override public void putStack(ItemStack stack) { this.inventory.setInventorySlotContents(this.slotIndex, stack); this.onSlotChanged(); } @Override public void onSlotChanged() { if (this.inventory instanceof InventoryDankNull) { this.inventory.markDirty(); } } @Override public int getSlotStackLimit() { return this.inventory.getInventoryStackLimit(); } @Override public int getItemStackLimit(ItemStack stack) { return this.getSlotStackLimit(); } @Override public ItemStack decrStackSize(int amount) { return this.inventory.decrStackSize(this.slotIndex, amount); } @Override public boolean canTakeStack(EntityPlayer playerIn) { return true; } public int getX() { return this.xDisplayPosition; } public int getY() { return this.yDisplayPosition; } } GuiHandler public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer playerIn, World worldIn, int x, int y, int z) { if (ID == Globals.GUINUM_DANKNULL) { return new ContainerDankNull(playerIn); } else { TileEntity te = worldIn.getTileEntity(new BlockPos(x, y, z)); if (te == null) { return null; } if (ID == Globals.GUINUM_COMPRESSOR) { return new ContainerCompressor(playerIn.inventory, (TileEntityCompressor) te); } else if (ID == Globals.GUINUM_FURNACE) { return new ContainerFurnace(playerIn.inventory, (TileEntityFurnace) te); } else if (ID == Globals.GUINUM_BATTERY) { return new ContainerBattery(playerIn.inventory, (TileEntityBattery) te); } } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer playerIn, World worldIn, int x, int y, int z) { if (ID == Globals.GUINUM_DANKNULL) { return new GuiDankNull(new ContainerDankNull(playerIn), playerIn.inventory); } else { TileEntity te = worldIn.getTileEntity(new BlockPos(x, y, z)); if (te == null) { return null; } if (ID == Globals.GUINUM_COMPRESSOR) { return new GuiCompressor(new ContainerCompressor(playerIn.inventory, (TileEntityCompressor) te)); } else if (ID == Globals.GUINUM_FURNACE) { return new GuiFurnace(new ContainerFurnace(playerIn.inventory, (TileEntityFurnace) te)); } else if (ID == Globals.GUINUM_BATTERY) { return new GuiBattery(new ContainerBattery(playerIn.inventory, (TileEntityBattery) te)); } else if (ID == Globals.GUINUM_SOLARPANEL) { return new GuiSolarPanel((TileEntitySolarPanel) te); } } return null; } public static void launchGui(final int ID, final EntityPlayer playerIn, final World worldIn, final int x, final int y, final int z) { playerIn.openGui(P455w0rdsThings.INSTANCE, ID, worldIn, x, y, z); } }
  13. I'm trying to create a wrench function for my blocks. I'm trying to retrieve the tile's NBT via getTileData(). getTileData() always returns an empty tag. The tile retains the NBT data so long as the block is placed. I can verify this because the block is a solar panel that generates RF. It retains the RF data through logging out and restarting the client. I have implemented packet handling to send the server data to the client as well. Following are the relevant methods: BlockSolarPanel#onBlockActivated public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { TileEntitySolarPanel te = getTE(worldIn, pos); if (te != null) { if (!playerIn.isSneaking()) { if (worldIn.isRemote) { GuiHandler.launchGui(Globals.GUINUM_SOLARPANEL, playerIn, worldIn, pos.getX(), pos.getY(), pos.getZ()); } } else { BlockUtils.wrenchBlock(worldIn, pos, state, te); } } return true; } BlockSolarPanel#getTE private TileEntitySolarPanel getTE(World worldIn, BlockPos pos) { return (TileEntitySolarPanel) BlockUtils.getTE(worldIn, pos); } BlockUtils#wrenchBlock public static void wrenchBlock(World worldIn, BlockPos pos, IBlockState state, TileEntity te) { if (!worldIn.isRemote) { ItemStack blockStack = new ItemStack(Item.getItemFromBlock(worldIn.getBlockState(pos).getBlock()), 1); if (te.getBlockMetadata() > 0) { blockStack.setItemDamage(te.getBlockMetadata()); } if (te.getTileData() != null) { NBTTagCompound nbt = te.getTileData(); blockStack.setTagCompound(nbt); } EntityItem entityItem = new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), blockStack); if (te != null) { worldIn.spawnEntityInWorld(entityItem); dropTEItems(worldIn, pos); worldIn.setBlockToAir(pos); } } }
  14. look into Block#getSubBlocks & blockstates/metadata, register using GameRegistry#register ..also Choonster's TestMod 3 is an amazing resource for learning 1.9+ stuff (I believe he has updated to 1.9.4 now)
  15. There is still a console log which could only help. Post (within BBCode CODE tags) each of the relevant class codes. (Main mod file, proxy classes, item class, etc)
  16. the best post for this can be found here: http://www.minecraftforge.net/forum/index.php?topic=20135.0
  17. You need to set up packet handling. The container doesn't handle packet handling automatically. So imo, you should send a packet to the client in an overridden Container#detectAndSendChanges method within your container.
  18. i had this same problem..it was because I hadn't updated my gradle buildscript to use ForgeGradle 2.2 was: dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT' } worked after I changed it to: dependencies { classpath 'net.minecraftforge.gradle:ForgeGradle:2.2-SNAPSHOT' }
  19. I was just going to keep my mouth shut, but like Draco pointed out, that particular mod must support Ore Dictionary for it to work. If they don't, you should check if the mod in question has an API for such things. Most of the 'bigger' mods have API's for their recipe systems. While this may be tedious, it sometimes can be the only way (other than ASM/Reflection/etc) to incorporate your item as an ingredient using their recipe system. You mentioned BuildCraft. The recipe-specific portion of their API can be found at https://github.com/BuildCraft/BuildCraftAPI/tree/9cd0add7220d6356299754bed75e1a7dfe09f74a/api/buildcraft/api/recipes
  20. you give very little to go on, so it is hard to say..also note potential..it is possible that this isn't a memory leak, just that forge is detecting the right conditions for one..the only reason I posted a reply is because I just had and fixed this same issue in my own mod about 3 hours ago...i'll let someone more experienced reply to try and help you
  21. this is detected when a lot of packets are sent successively without a break in the flow...you need to cache whatever the data is that you're trying to update and only send a packet if that data has changed
  22. Okay, so I've added packet handling and I am trying to update the GUI via detectAndSendChanges in the applicable container..still not getting anything..it is my understanding that in my current situation, I only need for the Battery TE to implement ITickable and do the handling of giving out energy as the handleReceivingEnergy method in the Battery TE calls the corresponding TE's receiveEnergy method..so I extract from bettery TE and receive on the connected (adjacent) TE..I have updated the repo reflect most recent changes...I was told that I simply need to update the client side instance of EnergyStorage, which is what I'm trying to do in the packet, but it just isn't working
  23. also..do this only on the client side (clientproxy)
  24. add the following method to your item class: @SideOnly(Side.CLIENT) public void initModel() { ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(this.getRegistryName(), "inventory")); } then in preinit after you have registered the item call the initModel() method...it seems that the JSON is finding the texture ok since there are no errors, so this is the only thing I can think of..make sure when you call GameRegistry.registerItem(), that it has the same name (not class name, but registered name) of the texture..I never really modded for 1.8, but I think 1.8.9 has this functionality..at any rate, you really should just move up to 1.9.4 as it is general consensus that 1.9.4 will be the defacto version for a while
  25. add the final one back..i read too quickly..sorry about that..also for future reference, EOFException is End Of File exception..so yeah..the JSON file was essentially "unterminated" aka no closing bracket
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.