Jump to content

jtmnf

Members
  • Posts

    56
  • Joined

  • Last visited

Everything posted by jtmnf

  1. Thanks larsgerrits and Draco18s!
  2. So, if I use that, what are the changes in the container? I need to specific an IInventory in the Slots...
  3. Here it is: TileEntity public class CrusherTileEntity extends TileEntity implements IInventory { private ItemStack[] inventory; private String customName; public CrusherTileEntity() { this.inventory = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < inventory.length; i++) { inventory[i] = new ItemStack(Blocks.AIR); } } public String getCustomName() { return this.customName; } public void setCustomName(String customName) { this.customName = customName; } @Override public String getName() { return this.hasCustomName() ? this.customName : "container:crusher_tile_entity"; } @Override public boolean hasCustomName() { return this.customName != null && !this.customName.equals(""); } @Nullable @Override public ITextComponent getDisplayName() { return this.hasCustomName() ? new TextComponentString(this.getName()) : new TextComponentTranslation(this.getName()); } @Override public int getSizeInventory() { return 27; } @Override public ItemStack getStackInSlot(int index) { if (index < 0 || index >= this.getSizeInventory()) { return null; } return this.inventory[index]; } @Override public ItemStack decrStackSize(int index, int count) { if (this.getStackInSlot(index) != null) { ItemStack itemstack; if (this.getStackInSlot(index).func_190916_E() <= count) { itemstack = this.getStackInSlot(index); this.setInventorySlotContents(index, null); this.markDirty(); return itemstack; } else { itemstack = this.getStackInSlot(index).splitStack(count); if (this.getStackInSlot(index).func_190916_E() <= 0) { this.setInventorySlotContents(index, null); } else { //Just to show that changes happened this.setInventorySlotContents(index, this.getStackInSlot(index)); } this.markDirty(); return itemstack; } } else { return null; } } @Override public void setInventorySlotContents(int index, ItemStack stack) { if (index < 0 || index >= this.getSizeInventory()) return; if (stack != null && stack.func_190916_E() > this.getInventoryStackLimit()) stack.func_190920_e(this.getInventoryStackLimit()); if (stack != null && stack.func_190916_E() == 0) stack = null; this.inventory[index] = stack; this.markDirty(); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.getPos()) == this && player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5)) <= 64; } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) { } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } @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() { for (int i = 0; i < this.getSizeInventory(); i++) this.setInventorySlotContents(i, null); } @Override public boolean func_191420_l() { return false; } @Override public ItemStack removeStackFromSlot(int index) { return null; } } Container of the TileEntity public class ContainerCrusher extends Container { private CrusherTileEntity crusherTileEntity; public ContainerCrusher(IInventory iInventory, CrusherTileEntity crusherTileEntity) { this.crusherTileEntity = crusherTileEntity; int numRows = crusherTileEntity.getSizeInventory() / 9; int i = (numRows - 4) * 18; for (int j = 0; j < numRows; ++j) { for (int k = 0; k < 9; ++k) { this.addSlotToContainer(new Slot(crusherTileEntity, k + j * 9, 8 + k * 18, 18 + j * 18)); } } for (int y = 0; y < 3; ++y) { for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(iInventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18)); } } for (int x = 0; x < 9; ++x) { this.addSlotToContainer(new Slot(iInventory, x, 8 + x * 18, 142)); } } @Override public boolean canInteractWith(EntityPlayer playerIn) { return crusherTileEntity.isUseableByPlayer(playerIn); } } Gui of the TileEntity public class GuiCrusher extends GuiContainer { private IInventory playerInv; private CrusherTileEntity crusherTileEntity; public GuiCrusher(IInventory playerInv, CrusherTileEntity crusherTileEntity) { super(new ContainerCrusher(playerInv, crusherTileEntity)); this.playerInv = playerInv; this.crusherTileEntity = crusherTileEntity; this.xSize = 176; this.ySize = 166; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f); this.mc.getTextureManager().bindTexture(new ResourceLocation("pureadditions:textures/gui/container/crusher.png")); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { String s = this.crusherTileEntity.getDisplayName().getUnformattedText(); this.fontRendererObj.drawString(s, 88 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752); //#404040 this.fontRendererObj.drawString(this.playerInv.getDisplayName().getUnformattedText(), 8, 72, 4210752); //#404040 } }
  4. The rendering error? I haven't solved it yet :\
  5. I didn't knew that, thanks! After fixing that, now it just crashes with a rendering problem...
  6. Hi guys! So, if I have this piece of code on the Container, it crashes the game (but it doesn't close it). for (int y = 0; y < 3; ++y) { for (int x = 0; x < 3; ++x) { this.addSlotToContainer(new Slot(this.crusherTileEntity, x + y * 3, 62 + x * 18, 17 + y * 18)); } } If the addSlotToContainer is commented, the GUI opens normally and it doesn't crash the game. I already saw the implementation of the chest, by the way. The error is:
  7. Thanks for the answr diesieben07! So, according to the offical wiki, for andesite, minecraft:stone{variant=5} is correct, right? But it returns null when I try to getBlockFromName... João Fernandes
  8. I have a XML file which can be filled by block's name, but for some blocks (basically all the blocks with metada), it fails to convert to the block... Imagine this: <registry_name>minecraft:stone:5</registry_name> <registry_name>immersiveengineering:ore:1</registry_name> And in the code, I need to convert the first one to Andesite and the second one to Bauxite Ore... If I shouldn't be using metadata, how can I have a proper XML element to deal with this situations? João Fernandes
  9. Hi, How can I detect that minecraft:stone:5 is andesite? I'm not able to do that, even with Block.getBlockFromName() or Block.REGISTRY... My mod is failing on this, on metadata blocks, and I'm not getting the way that this should be done :\ Am I forgetting something? Thanks, João Fernandes
  10. Yap, I called myself stupid
  11. You want to laught a bit? You know what my problem was? I saw it in your post... Do you see that line with the super.detectAndSendChanges();? @Override public void detectAndSendChanges() { super.detectAndSendChanges(); } Well... In my code you couldn't see it because I erase it... Don't ask me why... I personally don't know either... Now it's working ^^ thanks
  12. The problem with the ContainerFurnace is that it only uses sendProgressBarUpdate()... That means that is something in the TileEntity or GUI that I'm missing, but I'm actually not discovering what is it :\
  13. Don't worry you tryed to help me and I like that Thanks ^^ maybe somebody else can look at my code and say "this guy is stupid, look at that error there"...
  14. The (ICrafting p_75132_1_) does not have anything like that! Am I doing something wrong? Only these 3: void sendContainerAndContentsToPlayer(Container p_71110_1_, List p_71110_2_); void sendSlotContents(Container p_71111_1_, int p_71111_2_, ItemStack p_71111_3_); void sendProgressBarUpdate(Container p_71112_1_, int p_71112_2_, int p_71112_3_);
  15. "machine" is not a "list", I cannot put it in the 2nd argument :\
  16. Maybe with this, is better to people help me... This is my TileEntityClass... package jtmnf.forestryextension.tileentity; import cofh.api.energy.EnergyStorage; import cofh.api.energy.IEnergyHandler; import forestry.api.recipes.ICentrifugeRecipe; import forestry.api.recipes.RecipeManagers; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import java.util.Collection; import java.util.Iterator; import java.util.Map; import java.util.Random; public class CentrifugeTileEntity extends TileEntity implements IInventory, ICentrifugeRecipe, IEnergyHandler { private ItemStack[] items; private boolean isCombThere = true; private boolean active = false; public int time; public static int TIME_TO_PROCESS_COMBS = 24 * 8; //24 ticks per second * 8 seconds = 192 ticks; public EnergyStorage energyStorage; public static int COST_PER_COMB = 3500; public boolean isEnergy = false; /* =================================================================================== */ /* =================================== Constructor =================================== */ /* =================================================================================== */ public CentrifugeTileEntity() { items = new ItemStack[8]; energyStorage = new EnergyStorage(1000000); energyStorage.setMaxReceive(10000); energyStorage.setEnergyStored(0); } /* ================================================================================== */ /* =================================== IInventory =================================== */ /* ================================================================================== */ @Override public int getSizeInventory() { return items.length; } @Override public ItemStack getStackInSlot(int slot) { return items[slot]; } @Override public ItemStack decrStackSize(int i, int count) { ItemStack itemstack = getStackInSlot(i); if (itemstack != null) { if (itemstack.stackSize <= count) { setInventorySlotContents(i, null); }else{ itemstack = itemstack.splitStack(count); markDirty(); } } return itemstack; } @Override public ItemStack getStackInSlotOnClosing(int slot) { if (this.items[slot] != null) { ItemStack itemstack = this.items[slot]; this.items[slot] = null; return itemstack; } else { return null; } } @Override public void setInventorySlotContents(int slot, ItemStack itemStack) { items[slot] = itemStack; if(itemStack != null && itemStack.stackSize > getInventoryStackLimit()){ itemStack.stackSize = getInventoryStackLimit(); } markDirty(); } @Override public String getInventoryName() { return null; } @Override public boolean hasCustomInventoryName() { return false; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) <= 64; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { return true; } @Override public void updateEntity() { if(!worldObj.isRemote){ if(getStackInSlot(0) != null){ setInventorySlotContents(1, getStackInSlot(0)); setInventorySlotContents(0, null); } } /*if(getStackInSlot(0) != null && isCombThere && !worldObj.isRemote) { ItemStack itemStack = getStackInSlotOnClosing(0); Object[] products = getProductsByComb(itemStack); if((COST_PER_COMB * itemStack.stackSize) > energyStorage.getEnergyStored() && !active){ isEnergy = true; isCombThere = false; return ; } else{ isEnergy = false; active = true; } if (products != null) { if ((time / TIME_TO_PROCESS_COMBS) != 1) { time++; active = true; energyStorage.setEnergyStored(energyStorage.getEnergyStored() - ((COST_PER_COMB * itemStack.stackSize)/TIME_TO_PROCESS_COMBS)); } else { for (int i = 0; i < products.length; ++i) { active = false; boolean isInserted = false; boolean isEverythingOk = simulate((ItemStack) products[i], itemStack.stackSize); if (!isEverythingOk || products == null) { isCombThere = false; return ; } for (int j = 1; j < getSizeInventory() && !isInserted; ++j) { ItemStack product = (ItemStack) products[i]; if (getStackInSlot(j) == null) { setInventorySlotContents(j, new ItemStack(product.getItem(), itemStack.stackSize)); isInserted = true; } else { ItemStack stack = getStackInSlot(j); if (stack.getUnlocalizedName().equals(product.getUnlocalizedName()) && stack.stackSize < 64) { int stackSize = stack.stackSize; if ((stackSize + itemStack.stackSize) > 64) { setInventorySlotContents(j, new ItemStack(product.getItem(), 64)); for (int z = 1; z < getSizeInventory() && !isInserted; ++z) { if (getStackInSlot(z) == null) { setInventorySlotContents(z, new ItemStack(product.getItem(), (stackSize + itemStack.stackSize) - 64)); isInserted = true; } } } else { setInventorySlotContents(j, new ItemStack(product.getItem(), (stackSize + itemStack.stackSize))); isInserted = true; } } } } } setInventorySlotContents(0, null); isCombThere = false; LogHelper.info("Tell me that this works..."); markDirty(); } } } else if(getStackInSlot(0) == null && !worldObj.isRemote){ isCombThere = true; }*/ } /* ================================================================================= */ /* =================================== NBT Stuff =================================== */ /* ================================================================================= */ @Override public void writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); NBTTagList items = new NBTTagList(); for(int i = 0; i < getSizeInventory(); ++i){ ItemStack itemStack = getStackInSlot(i); if(itemStack != null){ NBTTagCompound item = new NBTTagCompound(); item.setByte("Slot", (byte) i); itemStack.writeToNBT(item); items.appendTag(item); } } compound.setTag("Items", items); energyStorage.writeToNBT(compound); } @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); NBTTagList items = compound.getTagList("Items", compound.getId()); for (int i = 0; i < items.tagCount(); i++) { NBTTagCompound item = items.getCompoundTagAt(i); int slot = item.getByte("Slot"); if(slot >= 0 && slot < getSizeInventory()){ setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(item)); } } energyStorage.readFromNBT(compound); } /* ================================================================================= */ /* =================================== markDirty =================================== */ /* ================================================================================= */ @Override public void markDirty() { if(getStackInSlot(0) == null){ time = 0; } isCombThere = true; } /* ========================================================================================= */ /* =================================== ICentrifugeRecipe =================================== */ /* ========================================================================================= */ @Override public ItemStack getInput() { return null; } @Override public int getProcessingTime() { return 0; } @Override public Collection<ItemStack> getProducts(Random random) { return null; } @Override public Map<ItemStack, Float> getAllProducts() { return null; } /* ======================================================================================= */ /* =================================== ProperFunctions =================================== */ /* ======================================================================================= */ private Object[] getProductsByComb(ItemStack itemStack){ Iterator<Map.Entry<Object[], Object[]>> iterator = RecipeManagers.centrifugeManager.getRecipes().entrySet().iterator(); while(iterator.hasNext()){ Map.Entry<Object[], Object[]> aux = iterator.next(); ItemStack product = (ItemStack) aux.getKey()[0]; if(product.getUnlocalizedName().equals(itemStack.getUnlocalizedName())){ return aux.getValue(); } } return null; } /** * @param product item to be analyzed * @return true if can proceed correctly, false if there is something wrong */ private boolean simulate(ItemStack product, int number){ for(int i = 1; i < getSizeInventory(); ++i){ ItemStack itemStack = getStackInSlot(i); if(itemStack == null){ return true; } else{ if(itemStack.getUnlocalizedName().equals(product.getUnlocalizedName())){ if((itemStack.stackSize + number) <= 64){ return true; } else{ for(int z = 1; z < getSizeInventory(); ++z){ if(getStackInSlot(z) == null){ return true; } } } } } } return false; } /* ====================================================================================== */ /* =================================== IEnergyHandler =================================== */ /* ====================================================================================== */ @Override public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) { return energyStorage.receiveEnergy(maxReceive, simulate); } @Override public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) { return 0; } @Override public int getEnergyStored(ForgeDirection from) { return energyStorage.getEnergyStored(); } @Override public int getMaxEnergyStored(ForgeDirection from) { return energyStorage.getMaxEnergyStored(); } @Override public boolean canConnectEnergy(ForgeDirection from) { return true; } } Container: package jtmnf.forestryextension.containers; import jtmnf.forestryextension.containers.slots.SlotZero; import jtmnf.forestryextension.tileentity.CentrifugeTileEntity; import jtmnf.forestryextension.util.LogHelper; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import java.util.ArrayList; import java.util.List; public class CentrifugeContainer extends Container { private CentrifugeTileEntity machine; public static int energy; public static boolean isEnergy; public CentrifugeContainer(InventoryPlayer inventoryPlayer, CentrifugeTileEntity centrifugeTileEntity) { this.machine = centrifugeTileEntity; for(int i = 0; i < 9; ++i){ addSlotToContainer(new Slot(inventoryPlayer, i, 20 + 18*i, 107)); } for(int i = 0; i < 3; ++i){ for(int j = 0; j < 9; ++j){ addSlotToContainer(new Slot(inventoryPlayer, j + i*9 + 9, 20 + 18*j, 49 + i*18)); } } addSlotToContainer(new Slot(machine, 0, 20, 18)); addSlotToContainer(new SlotZero(machine, 1, 56, ); addSlotToContainer(new SlotZero(machine, 2, 75, ); addSlotToContainer(new SlotZero(machine, 3, 94, ); addSlotToContainer(new SlotZero(machine, 4, 56, 27)); addSlotToContainer(new SlotZero(machine, 5, 75, 27)); addSlotToContainer(new SlotZero(machine, 6, 94, 27)); addSlotToContainer(new Slot(machine, 7, 164, ); } @Override public boolean canInteractWith(EntityPlayer player) { return machine.isUseableByPlayer(player); } @Override public ItemStack transferStackInSlot(EntityPlayer player, int i) { return null; } @Override public void addCraftingToCrafters(ICrafting p_75132_1_) { super.addCraftingToCrafters(p_75132_1_); p_75132_1_.sendContainerAndContentsToPlayer(this, this.getInventory()); } }
  17. So, I did this: @Override public void addCraftingToCrafters(ICrafting p_75132_1_) { super.addCraftingToCrafters(p_75132_1_); p_75132_1_.sendContainerAndContentsToPlayer(this, this.getInventory()); } And the result was the same :\
  18. Hi! I have a stupid question... One day I was working on a "custom furnace" and everything was ok! But now, the client does not get an update on the GUI... I have this (for testing only - this is not the actual method): @Override public void updateEntity() { if (!worldObj.isRemote) { if (getStackInSlot(0) != null) { setInventorySlotContents(1, getStackInSlot(0)); setInventorySlotContents(0, null); } } } The markDirty() is on the setInventorySlotContents()... I cannot make the client being updated when this part is done... If tryed with packets, but to be honest, I actually need help in this and if someone can help me, I'll be very happy! Thanks, João Fernandes
  19. No worries ^^ I never actually learn well how to work with the packets, but I tryed to! Thanks
  20. It worked ^^ Using detectAndSendChanges(), I could retrieve the energy and pass it to the interface! Thanks
  21. I'll try to do that! I'll use ContainerFurnace as my guide! Thanks
  22. I saw the GuiFurnace and I opened the Container... There are some things diferent, and that might be the case of this not working... public class CentrifugeContainer extends Container { private CentrifugeTileEntity machine; public CentrifugeContainer(InventoryPlayer inventoryPlayer, CentrifugeTileEntity centrifugeTileEntity) { this.machine = centrifugeTileEntity; for(int i = 0; i < 9; ++i){ addSlotToContainer(new Slot(inventoryPlayer, i, 20 + 18*i, 107)); } for(int i = 0; i < 3; ++i){ for(int j = 0; j < 9; ++j){ addSlotToContainer(new Slot(inventoryPlayer, j + i*9 + 9, 20 + 18*j, 49 + i*18)); } } addSlotToContainer(new Slot(machine, 0, 20, 18)); addSlotToContainer(new SlotZero(machine, 1, 56, ); addSlotToContainer(new SlotZero(machine, 2, 75, ); addSlotToContainer(new SlotZero(machine, 3, 94, ); addSlotToContainer(new SlotZero(machine, 4, 56, 27)); addSlotToContainer(new SlotZero(machine, 5, 75, 27)); addSlotToContainer(new SlotZero(machine, 6, 94, 27)); addSlotToContainer(new Slot(machine, 7, 164, ); } @Override public boolean canInteractWith(EntityPlayer player) { return machine.isUseableByPlayer(player); } @Override public ItemStack transferStackInSlot(EntityPlayer player, int i) { return null; } }
  23. I'm having trouble passing the messages... I implemented the classes correctly, but I don't know how to send the energy through the network... Should I do Mod.network.sendToServer(message)?
  24. I'll do that I'll comment the results later thanks!
  25. Forestry Engines... When I had the static in the EnergyStorage, it charged... But now, it doesn't charge...
×
×
  • Create New...

Important Information

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