-
Posts
161 -
Joined
-
Last visited
Everything posted by AnZaNaMa
-
So a little while back, I made this tileentity called TileEntityEnergizer and it was working great! It looked for items above it and if it found them, 'absorbed' them and created energy. Then, it would transfer the energy to a player if they stepped on it with a redstone signal. All was good. Then, one day, I decided "I want to make this a multiblock." So, I went and I added some fields and a method to check if it was surrounded by a certain type of block and such. The purpose of that was so that the multiblock would give the player more energy for each item. Now that I've talked all about my troubles, here's the problem: For some reason, whenever I use this.pos or pos or pos.getX() etc... it tells me that the block is at the coordinates 0, 0, 0. This is really weird because it never used to do that. Can someone look through the class and try and help me figure out whats going on with it? I'm not sure if this is the cause, but I also have a method in the block for the tileentity that prints the energy stored to the chat when you click it. Whenever this method runs, it would seem, is when the block begins to think it's at position 0, 0, 0. TileEntityEnergizer: https://github.com/AnZaNaMa/ExpTools/blob/master/src/main/java/com/AnZaNaMa/ExpTools/Entity/TileEntity/TileEntityEnergizer.java Energizer Block: https://github.com/AnZaNaMa/ExpTools/blob/master/src/main/java/com/AnZaNaMa/ExpTools/Block/Energizer.java
-
put the GameRegistry.registerBlock() inside the constructor of your BlockApple, so it would be: public BlockApple(String name) { super(Material.plants); this.setUnlocalizedName(Growthcraft.MODID + "." + name); this.setDefaultState(...); GameRegistry.registerBlock(this, "apple_block"); } It would probably also be better practice to use the variable passed into the constructor called 'name' instead of "apple_block".
-
Thanks for your help. I never really think about static when I'm writing it. I know what it does and how it works but I am so used to using it that I kind of just throw it into variable declarations. Also, thanks for the tutorial on syncing tile entities, because I never really thought about that..
-
I'm not quite sure why this is so, but the NBT value for my TileEntityEnergizer does not save and load back in when the world is saved and loaded again. I have used readFromNbt and writeToNBT, but the data does not stay. here is a link to the TileEntityEnergizer class: https://github.com/AnZaNaMa/ExpTools/blob/master/src/main/java/com/AnZaNaMa/ExpTools/Entity/TileEntity/TileEntityEnergizer.java'>https://github.com/AnZaNaMa/ExpTools/blob/master/src/main/java/com/AnZaNaMa/ExpTools/Entity/TileEntity/TileEntityEnergizer.java and the repository of the whole mod (if needed): https://github.com/AnZaNaMa/ExpTools
-
So, I have a tile entity I've been working on that can take any item and turn it into pure energy that gets stored in the block (or in the Tile Entity to be exact). If a player then steps on it with a redstone signal, the player will draw out all of the energy into themself. The only problem is that as long as the energy is transferring, the server does not tick. The client can still move and look around, but cannot interact with the world, because the tile entity transfers energy using a for loop. Do i somehow need to run this on another thread, and how might I go about that? Tile entity update method: @Override public void update(){ if(!this.worldObj.isRemote) this.repetitions++; if(this.repetitions >= 20){ this.repetitions = 0; List entities = this.worldObj.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), new BlockPos(pos.getX() + 1, pos.getY() + 2, pos.getZ() + 1)), IEntitySelector.selectAnything); for(int i=0; i < entities.size(); i++){ if(entities.get(i) instanceof EntityItem){ ItemStack items = new ItemStack(((EntityItem) entities.get(i)).getEntityItem().getItem(), ((EntityItem) entities.get(i)).getEntityItem().stackSize, ((EntityItem) entities.get(i)).getEntityItem().getMetadata()); int energyToMachine = Energy.getItemEnergyValue(items.getItem()); ((EntityItem) entities.get(i)).setInfinitePickupDelay(); this.energyContained += (energyToMachine * ((EntityItem) entities.get(i)).getEntityItem().stackSize); ((EntityItem) entities.get(i)).getEntityItem().stackSize = 0; } else if(entities.get(i) instanceof EntityPlayer){ while(this.energyContained > 0 && RedstoneHelper.isPoweredByRedstone(this.worldObj, this.getPos())){ Energy.tryMoveEnergy(this, (EntityPlayer) entities.get(i), 1); try { TimeUnit.MILLISECONDS.sleep(1); } catch(InterruptedException e){} } } } } } Energy.tryMoveEnergy(): public static void tryMoveEnergy(TileEntity tileEntity, EntityPlayer player, int amount){ if(canMoveEnergy(tileEntity, player, amount)){ ((TileEntityEnergizer)tileEntity).subtractEnergyContained(amount); PlayerTotalEnergy += amount; } } Let me know if there's anything important I didn't provide.
-
Thanks for your help. I haven't really been able to find any good tutorials for OpenGL. Anyone know a good one? Also, if you have it, I would love a good directx tutorial, though that's not related to this question at all
-
I've been working on my mod for minecraft 1.8 and so far, everything has been going fine, but I just can't seem to figure out why my tileentity will not render. I have a blockstate json file for it, a json in models under item AND block, the texture is in the correct place, but for some reason the block will not render in the world. It does render as an item, but as soon as it is placed, I just get a completely transparent texture. I have tried using a custom TESR and that is not working either, please help me figure this out. Block class: public class Energizer extends BlockContainer { public Energizer(Material material, String unlocalizedName, float localhardness, float localresistance){ super(material); GameRegistry.registerBlock(this, unlocalizedName); setCreativeTab(ExpTools.creativeTab); setHardness(localhardness); setResistance(localresistance); setUnlocalizedName(unlocalizedName); } public TileEntity createNewTileEntity(World world, int number){ return new TileEntityEnergizer(); } @Override public void onBlockClicked(World world, BlockPos position, EntityPlayer player){ TileEntity entity = world.getTileEntity(position); if(entity instanceof TileEntityEnergizer) { player.addChatMessage(new ChatComponentText("Energy Stored: " + ((TileEntityEnergizer)world.getTileEntity(position)).getEnergyContained())); } } @Override public boolean isOpaqueCube(){ return true; } } TileEntity Class: public class TileEntityEnergizer extends TileEntity implements IUpdatePlayerListBox { private static int energyContained; private static BlockPos position; private static byte repetitions; public TileEntityEnergizer(){ super(); this.energyContained = 0; this.position = BlockPos.ORIGIN; this.repetitions = 0; } @Override public void update(){ if(!this.worldObj.isRemote) this.repetitions++; if(this.repetitions >= 20){ this.repetitions = 0; LogHelper.info("Looking for Entities from position (" + pos.getX() + ", " + pos.getY() + ", " + pos.getZ() + ") to (" + pos.getX() + ", " + (pos.getY()+1) + ", " + pos.getZ() + ")"); List entities = this.worldObj.getEntitiesWithinAABB(Entity.class, new AxisAlignedBB(new BlockPos(pos.getX(), pos.getY(), pos.getZ()), new BlockPos(pos.getX() + 1, pos.getY() + 2, pos.getZ() + 1)), IEntitySelector.selectAnything); LogHelper.info("Found Entities:"); for(int i=0; i < entities.size(); i++){ LogHelper.info(entities.get(i).toString()); } for(int i=0; i < entities.size(); i++){ if(entities.get(i) instanceof EntityItem){ LogHelper.info("Entity is EntityItem"); ItemStack items = new ItemStack(((EntityItem) entities.get(i)).getEntityItem().getItem(), ((EntityItem) entities.get(i)).getEntityItem().stackSize, ((EntityItem) entities.get(i)).getEntityItem().getMetadata()); LogHelper.info("ItemStack UnlocalizedName: " + items.getItem().getUnlocalizedName()); int energyToMachine = Energy.getItemEnergyValue(items.getItem()); LogHelper.info("ItemStack Energy Value found to be: " + energyToMachine); ((EntityItem) entities.get(i)).setInfinitePickupDelay(); this.energyContained += (energyToMachine * ((EntityItem) entities.get(i)).getEntityItem().stackSize); ((EntityItem) entities.get(i)).getEntityItem().stackSize = 0; LogHelper.info("Item Removed"); } else if(entities.get(i) instanceof EntityPlayer){ Energy.tryMoveEnergy(this, (EntityPlayer)entities.get(i), 100); } } } } @Override public void readFromNBT(NBTTagCompound compound){ this.energyContained = compound.getInteger("Energy"); } @Override public void writeToNBT(NBTTagCompound compound){ compound.setInteger("Energy", this.energyContained); } public int getEnergyContained(){ return this.energyContained; } public void setEnergyContained(int amount){ this.energyContained = amount; } public void addEnergyContained(int amount){ this.energyContained += amount; } public void subtractEnergyContained(int amount){ this.energyContained -= amount; } } Tile Entity Special Renderer Class: public class EnergyToolsTESR extends TileEntitySpecialRenderer{ public EnergyToolsTESR(){ } @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f, int number){ ResourceLocation image = new ResourceLocation(Reference.MODID + ":textures/blocks/energizer.png"); this.bindTexture(image); Tessellator tessellator = Tessellator.getInstance(); GL11.glPushMatrix(); GL11.glTranslated(x, y + 1, z); tessellator.getWorldRenderer().addVertexWithUV(0, 0, 0, 0, 0); tessellator.getWorldRenderer().addVertexWithUV(0, 1, 0, 0, 1); tessellator.getWorldRenderer().addVertexWithUV(1, 1, 0, 1, 1); tessellator.getWorldRenderer().addVertexWithUV(1, 0, 0, 1, 0); tessellator.getWorldRenderer().addVertexWithUV(0, 0, 0, 0, 0); tessellator.getWorldRenderer().addVertexWithUV(1, 0, 0, 1, 0); tessellator.getWorldRenderer().addVertexWithUV(1, 1, 0, 1, 1); tessellator.getWorldRenderer().addVertexWithUV(0, 1, 0, 0, 1); tessellator.getWorldRenderer().startDrawingQuads(); tessellator.draw(); GL11.glPopMatrix(); } } I have registered the block icon and bound the TESR in the init() method of my ClientProxy.