Jump to content

Cyclonit

Members
  • Posts

    12
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

Cyclonit's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Well fabricator77 in this post http://www.minecraftforge.net/forum/index.php/topic,9792.msg49877.html was right. modids having upper case letters, don't work...
  2. Hi, the textures of my TileEntities are not loading properly. This is the full error: 2013-07-03 13:22:44 [WARNING] [Minecraft-Client] Failed to load texture: advancedChests:textures/models/ironChest.png java.io.FileNotFoundException: advancedChests:textures/models/ironChest.png at net.minecraft.client.resources.SimpleReloadableResourceManager.func_110536_a(SimpleReloadableResourceManager.java:66) at net.minecraft.client.renderer.texture.SimpleTexture.func_110551_a(SimpleTexture.java:32) at net.minecraft.client.renderer.texture.TextureManager.func_110579_a(TextureManager.java:84) at net.minecraft.client.renderer.texture.TextureManager.func_110577_a(TextureManager.java:41) at cyclonit.advancedChests.client.ItemAdvancedChestRenderer.render(ItemAdvancedChestRenderer.java:62) at cyclonit.advancedChests.client.ItemAdvancedChestRenderer.renderItem(ItemAdvancedChestRenderer.java:52) at net.minecraftforge.client.ForgeHooksClient.renderInventoryItem(ForgeHooksClient.java:146) at net.minecraft.client.renderer.entity.RenderItem.func_110797_b(RenderItem.java:423) at net.minecraft.client.gui.GuiIngame.renderInventorySlot(GuiIngame.java:976) at net.minecraftforge.client.GuiIngameForge.renderHotbar(GuiIngameForge.java:206) at net.minecraftforge.client.GuiIngameForge.renderGameOverlay(GuiIngameForge.java:141) at net.minecraft.client.renderer.EntityRenderer.updateCameraAndRender(EntityRenderer.java:1014) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:930) at net.minecraft.client.Minecraft.run(Minecraft.java:822) at net.minecraft.client.main.Main.main(Main.java:93) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:57) at net.minecraft.launchwrapper.Launch.main(Launch.java:18) This is how I am setting up the ResourceLocations: this.modelTexture = new ResourceLocation(Constants.MODID, "textures/models/" + realName + ".png"); Constants.MODID = "advancedChests" realName = "ironChest" The texture I'd like to load is located in "mcp\src\minecraft\assets\advancedChests\textures\models\ironChest.png" What am I doing wrong?
  3. My solution: Setting the output true is trivial. Simply set a variable whenever you like to. Turning it off after x seconds is possible by using scheduled block updates. We therefore use the function World.scheduleBlockUpdate(x, y, z, blockID, delay) to update the block at (x,y,z) in <delay> ticks. The called function in your block will be updateTick(World world, int x, int y, int z, Random rand).
  4. I have a chest which is supposed to emit a redstone pulse whenever an item was put in or taken out. I have everything aside from the actual pulse ready and have everything connected to a function, which is supposed to do the redstone stuff. I am familiar with how the basics of redstone work (isProvidingWeakPower(), ...), but I do not understand how to deactivate the signal after a certain period of time.
  5. Hi, I could not find any resources or open source projects to answer this question for myself: How can I trigger a redstone pulse on a block? Cyclonit
  6. Thank you both for your input In readFromNBT accessing the block's metadata directly is impossible because neither this.getBlockMetadata() nor this.getWorldObj() are available. But working around this is fairly straight forward: writeToNBT can access the block's metadata. I thus store the block's metadata alongside the chest's inventory and load it in readFromNBT. Here is my full solution: package cyclonit.advancedChests; import cyclonit.advancedChests.core.AdvancedChestType; 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.NBTTagInt; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class TileEntityAdvancedChest extends TileEntity implements IInventory { private AdvancedChestType type; private ItemStack[] inv; private int size; /* * Constructors * * We need the default constructor to bypass the first instantiation * by TileEntity.createAndLoadEntity(). */ public TileEntityAdvancedChest() { super(); } public TileEntityAdvancedChest(AdvancedChestType type) { this.type = type; this.size = type.rows * type.columns; this.inv = new ItemStack[this.size]; } public AdvancedChestType getType() { return this.type; } @Override public int getSizeInventory() { return this.size; } @Override public ItemStack getStackInSlot(int i) { return this.inv[i]; } @Override public String getInvName() { return "container." + this.type.realName; } @Override public int getInventoryStackLimit() { return 64; } @Override public ItemStack decrStackSize(int slot, int amount) { if (this.inv[slot] != null) { ItemStack stack; if (this.inv[slot].stackSize <= amount) { stack = this.inv[slot]; this.inv[slot] = null; } else { stack = this.inv[slot].splitStack(amount); } this.onInventoryChanged(); return stack; } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int i) { // If there is something in the selected slot, drop it. if (this.inv[i] != null) { ItemStack itemstack = this.inv[i]; this.inv[i] = null; return itemstack; } else { return null; } } @Override public void setInventorySlotContents(int i, ItemStack itemStack) { this.inv[i] = itemStack; if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { itemStack.stackSize = this.getInventoryStackLimit(); } this.onInventoryChanged(); } @Override public boolean isInvNameLocalized() { return false; } @Override public boolean isUseableByPlayer(EntityPlayer entityPlayer) { return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; } @Override public boolean isStackValidForSlot(int i, ItemStack itemstack) { return true; } @Override public void openChest() { } @Override public void closeChest() { } /* * NBT * * In addition to storing the chest's inventory, we use the NBT * to store the chest's metadata. We can thus always load the * correct type without having to use different classes for every * kind of chest. */ @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); // Load the type int meta = tagCompound.getInteger("Metadata"); this.type = AdvancedChestType.values()[meta]; this.size = this.type.rows * this.type.columns; this.inv = new ItemStack[this.size]; // Load the inventory NBTTagList tagList = tagCompound.getTagList("Inventory"); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < inv.length) { inv[slot] = ItemStack.loadItemStackFromNBT(tag); } } } @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); // Save the inventory NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { ItemStack stack = inv[i]; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } tagCompound.setTag("Inventory", itemList); // Save the metadata tagCompound.setInteger("Metadata", this.getBlockMetadata()); } }
  7. What do you mean by that? The problem is, that the default constructor is being called during chunk loading. It does however not know (yet) what kind of a chest it is supposed to create (it would need the block's metadata). Here is my TE: package cyclonit.advancedChests; import cyclonit.advancedChests.core.AdvancedChestType; 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.minecraft.world.World; public class TileEntityAdvancedChest extends TileEntity implements IInventory { private AdvancedChestType type; private ItemStack[] inv; private int size; /* * Constructors * * We need the default constructor to bypass the first instantiation * by TileEntity.createAndLoadEntity(). */ public TileEntityAdvancedChest(AdvancedChestType type) { this.type = type; this.size = type.rows * type.columns; this.inv = new ItemStack[this.size]; } public AdvancedChestType getType() { return this.type; } @Override public int getSizeInventory() { return this.size; } @Override public ItemStack getStackInSlot(int i) { return this.inv[i]; } @Override public String getInvName() { return "container." + this.type.realName; } @Override public int getInventoryStackLimit() { return 64; } @Override public ItemStack decrStackSize(int slot, int amount) { if (this.inv[slot] != null) { ItemStack stack; if (this.inv[slot].stackSize <= amount) { stack = this.inv[slot]; this.inv[slot] = null; } else { stack = this.inv[slot].splitStack(amount); } this.onInventoryChanged(); return stack; } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int i) { // If there is something in the selected slot, drop it. if (this.inv[i] != null) { ItemStack itemstack = this.inv[i]; this.inv[i] = null; return itemstack; } else { return null; } } @Override public void setInventorySlotContents(int i, ItemStack itemStack) { this.inv[i] = itemStack; if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit()) { itemStack.stackSize = this.getInventoryStackLimit(); } this.onInventoryChanged(); } @Override public boolean isInvNameLocalized() { return false; } @Override public boolean isUseableByPlayer(EntityPlayer entityPlayer) { return this.worldObj.getBlockTileEntity(this.xCoord, this.yCoord, this.zCoord) != this ? false : entityPlayer.getDistanceSq((double)this.xCoord + 0.5D, (double)this.yCoord + 0.5D, (double)this.zCoord + 0.5D) <= 64.0D; } @Override public boolean isStackValidForSlot(int i, ItemStack itemstack) { return true; } @Override public void openChest() { } @Override public void closeChest() { } /* * NBT */ @Override public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tagList = tagCompound.getTagList("Inventory"); for (int i = 0; i < tagList.tagCount(); i++) { NBTTagCompound tag = (NBTTagCompound) tagList.tagAt(i); byte slot = tag.getByte("Slot"); if (slot >= 0 && slot < inv.length) { inv[slot] = ItemStack.loadItemStackFromNBT(tag); } } } @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); NBTTagList itemList = new NBTTagList(); for (int i = 0; i < inv.length; i++) { ItemStack stack = inv[i]; if (stack != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag); itemList.appendTag(tag); } } tagCompound.setTag("Inventory", itemList); } }
  8. I'm doing that already. The metadata is being resolved to a type and then passed on to the TE constructor. The issue is this: 2013-05-04 09:45:51 [iNFO] [sTDERR] java.lang.InstantiationException: cyclonit.advancedChests.TileEntityAdvancedChest 2013-05-04 09:45:51 [iNFO] [sTDERR] at java.lang.Class.newInstance0(Unknown Source) 2013-05-04 09:45:51 [iNFO] [sTDERR] at java.lang.Class.newInstance(Unknown Source) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.tileentity.TileEntity.createAndLoadEntity(TileEntity.java:137) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.world.chunk.storage.AnvilChunkLoader.readChunkFromNBT(AnvilChunkLoader.java:432) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.world.chunk.storage.AnvilChunkLoader.checkedReadChunkFromNBT(AnvilChunkLoader.java:103) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadChunk(AnvilChunkLoader.java:83) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.world.gen.ChunkProviderServer.safeLoadChunk(ChunkProviderServer.java:182) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:118) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:281) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:88) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:105) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:429) 2013-05-04 09:45:51 [iNFO] [sTDERR] at net.minecraft.server.ThreadMinecraftServer.run(ThreadMinecraftServer.java:16) The function TileEntity.createAndLoadEntity calls (TileEntity)oclass.newInstance(); and thus not my constructor but the default one.
  9. Of course: package cyclonit.advancedChests; import java.util.List; import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import cyclonit.advancedChests.core.AdvancedChestType; import cyclonit.advancedChests.core.Constants; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Icon; import net.minecraft.world.World; public class BlockAdvancedChest extends Block { private AdvancedChestType type; public BlockAdvancedChest(int blockID, AdvancedChestType type) { super(blockID, Material.iron); this.type = type; this.setCreativeTab(CreativeTabs.tabDecorations); this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F); } @Override public void getSubBlocks(int blockID, CreativeTabs creativeTabs, List itemList) { for (AdvancedChestType type : AdvancedChestType.values()) { itemList.add(new ItemStack(blockID, 1, type.ordinal())); } } /* * Textures * * We are using a single block-ID to store several blocks. Thus we * must provide the block's texture based on the metadata instead * of using just the ID. */ @SideOnly(Side.CLIENT) public void registerIcons(IconRegister iconRegister) { for (AdvancedChestType type : AdvancedChestType.values()) { type.registerIcons(iconRegister); } } @SideOnly(Side.CLIENT) @Override public Icon getBlockTextureFromSideAndMetadata(int side, int meta) { return AdvancedChestType.values()[meta].getTexture(side); } /* * TileEntity * * Using a single block-ID for several blocks requires using the * metadata for deciding what kind of a TileEntity we need. We * therefore use createTileEntity(World, int) instead of the usual * createNewTileEntity(World). */ @Override public boolean hasTileEntity(int meta) { return meta < AdvancedChestType.values().length; } @Override public TileEntity createTileEntity(World world, int meta) { return new TileEntityAdvancedChest(AdvancedChestType.values()[meta]); } /* * Container */ @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int a, float b, float c, float d) { TileEntity tileEntity = world.getBlockTileEntity(x, y, z); if (tileEntity == null || player.isSneaking()) { return false; } // open GUI 0 player.openGui(AdvancedChests.instance, 0, world, x, y, z); return true; } }
  10. Writing it this way: public TileEntityAdvancedChest() { int meta = this.getWorldObj().getBlockMetadata(this.xCoord, this.yCoord, this.zCoord); this(AdvancedChestType.values()[meta]); } Isn't possible because the constructor call must be the first line in the default constructor. public TileEntityAdvancedChest() { this(AdvancedChestType.values()[this.getWorldObj().getBlockMetadata(this.xCoord, this.yCoord, this.zCoord]); } Doesn't work because you cannot use "this" (or super) while calling a constructor for the class itself.
  11. I'd need the block's coordinates for that and I cannot use "this" in the constructor to get something.
  12. Hi, I just started working on my very first mod. Its the second Java project I'm working on, thus I do have some basic knowledge about the language itself. The mod is very similar to CPWs IronChest. In fact his code was among the many I looked at the one I learned most from. He is using a single block for all of his chests. So am I. He however is using separate TileEntity classes for every kind of chest. I guess he decided to do it this way because the chunk system calls a block's TileEntity's default constructor and does thus not supply any information about the block (metadata). This is the code of interest: public TileEntityAdvancedChest() { // problem area } public TileEntityAdvancedChest(ChestType type) { this.type = type; this.size = type.rows * type.columns; this.inv = new ItemStack[this.size]; } Using the block's metadata to create the desired TileEntity is easy as long as the right constructor is being called (the second one). But is there some way to get the block's metadata whenever the default constructor is being called? I don't like the solution of having a lot of different classes flying around. One idea I've had was creating classes during runtime, based on the different chest types (using a class template), but I don't have a clue how to achieve something like this in Java. The search for enum based generic classes didn't help to much, because they were using the enumerator class, whilst I'd like to somehow use the values. The registry would look like this: for (AdvancedChestType type : AdvancedChestType.values()) { type.registerName(advancedChestBlock); GameRegistry.registerTileEntity(TileEntityAdvancedChest<type>.class, "tileEntity" + type.realName); } Maybe someone around here knows a neat way for this to work out. Cyclonit
×
×
  • Create New...

Important Information

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