Jump to content

kenoba10

Members
  • Posts

    127
  • Joined

  • Last visited

Everything posted by kenoba10

  1. It doesn't look like you commented out all of your code and you have a GameRegistry.ObjectHolder annotation somewhere it shouldn't be. Remove that and it should work
  2. yes in the direction it faces, I got it figured out by doing what you said and if the meta = 0, render it the way I want it to
  3. I have a block that has a few different textures and I hae gotten it so, the front texture faces you when it is placed. But how would I make the icon when it is in my inventory display similar to how the furnace does? Here is my code: @SideOnly(Side.CLIENT) private IIcon blockTop; @SideOnly(Side.CLIENT) private IIcon blockSide; public BlockFactoryTerminal() { super(); this.setBlockName("factoryFactoryTerminal"); } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) { int l = MathHelper.floor_double((double) (player.rotationYaw * 4f / 360f) + .5d) & 3; if(l == 0) world.setBlockMetadataWithNotify(x, y, z, 2, 2); if(l == 1) world.setBlockMetadataWithNotify(x, y, z, 5, 2); if(l == 2) world.setBlockMetadataWithNotify(x, y, z, 3, 2); if(l == 3) world.setBlockMetadataWithNotify(x, y, z, 4, 2); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { blockIcon = iconRegister.registerIcon(String.format("%s", getUnWrappedUnlocalizedName(this.getUnlocalizedName()))); blockTop = iconRegister.registerIcon(String.format("%s", getUnWrappedUnlocalizedName(ElectricFactoryBlocks.factoryFactoryStructureBlock.getUnlocalizedName() + "Top"))); blockSide = iconRegister.registerIcon(String.format("%s", getUnWrappedUnlocalizedName(ElectricFactoryBlocks.factoryFactoryStructureBlock.getUnlocalizedName()))); } @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int meta) { if(side == 0 || side == 1) return blockTop; else if(side != meta) return blockSide; else return blockIcon; }
  4. I may have figured it out but the fix is a bit weird. I have another block that on every update edits the internal power and if I wait to manipulate the variables until the end of the method, it works more often. I think I should be able to get it working now though.
  5. This is strange. I tried what you said and it actually loaded up correctly. Then I loaded up the world again and it crashed saying that the tile entity was null. Also, I have done this on separate worlds and they all do this.
  6. That is most likely not the issue because it only happens when buildcraft energy pipes are connected to it. Here is my tile entity code though: public class PowerFactoryTileEntity extends TileEntity implements IInventory, IFluidHandler { private ItemStack[] itemInventory; private FluidTank tankWater; private FluidTank tankLava; private int energy = 0; public PowerFactoryTileEntity() { itemInventory = new ItemStack[8]; tankWater = new FluidTank(FluidRegistry.WATER, 0, FluidContainerRegistry.BUCKET_VOLUME * 4); tankLava = new FluidTank(FluidRegistry.LAVA, 0, FluidContainerRegistry.BUCKET_VOLUME * 4); } public String getInventoryName() { return "container.electricfactory:factoryPower"; } public boolean hasCustomInventoryName() { return false; } public int getSizeInventory() { return itemInventory.length; } public int getInventoryStackLimit() { return 64; } public boolean isUseableByPlayer(EntityPlayer player) { return true; } public void openInventory() { } public void closeInventory() { } public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } public ItemStack getStackInSlot(int index) { return itemInventory[index]; } public ItemStack getStackInSlotOnClosing(int index) { if(itemInventory[index] != null) { itemInventory[index] = null; return itemInventory[index]; } return null; } public ItemStack decrStackSize(int index, int amount) { ItemStack stack = getStackInSlot(index); if(stack != null) { if(stack.stackSize <= amount) { setInventorySlotContents(index, null); } else { stack = stack.splitStack(amount); if(stack.stackSize == 0) setInventorySlotContents(index, null); } } return stack; } public void setInventorySlotContents(int index, ItemStack stack) { itemInventory[index] = stack; if(stack != null && stack.stackSize > getInventoryStackLimit()) stack.stackSize = getInventoryStackLimit(); markDirty(); } public int fill(ForgeDirection side, FluidStack stack, boolean fill) { int filled; if(stack.getFluid() == FluidRegistry.WATER) filled = tankWater.fill(stack, fill); else if(stack.getFluid() == FluidRegistry.LAVA) filled = tankLava.fill(stack, fill); else filled = 0; if(!worldObj.isRemote) Packets.INSTANCE.sendToAll(new PowerFactoryPacket(this)); return filled; } public FluidStack drain(ForgeDirection side, FluidStack stack, boolean drain) { return null; } public FluidStack drain(ForgeDirection side, int max, boolean drain) { return null; } public boolean canFill(ForgeDirection side, Fluid fluid) { return fluid == FluidRegistry.WATER || fluid == FluidRegistry.LAVA; } public boolean canDrain(ForgeDirection side, Fluid fluid) { return false; } public FluidTankInfo[] getTankInfo(ForgeDirection side) { return new FluidTankInfo[] {tankWater.getInfo(), tankLava.getInfo()}; } public Packet getDescriptionPacket() { return Packets.INSTANCE.getPacketFrom(new PowerFactoryPacket(this)); } public void updateEntity() { super.updateEntity(); } public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tags = tagCompound.getTagList("items", 10); for(int i = 0; i < tags.tagCount(); i++) { NBTTagCompound tag = tags.getCompoundTagAt(i); byte index = tag.getByte("slot"); if(index >= 0 && index < itemInventory.length) itemInventory[index] = ItemStack.loadItemStackFromNBT(tag); } NBTTagCompound tagWater = tagCompound.getCompoundTag("water"); NBTTagCompound tagLava = tagCompound.getCompoundTag("lava"); tankWater.readFromNBT(tagWater); tankLava.readFromNBT(tagLava); energy = tagCompound.getInteger("energy"); } public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); NBTTagList tags = new NBTTagList(); for(int i = 0; i < itemInventory.length; i++) { if(itemInventory[i] != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("slot", (byte)i); itemInventory[i].writeToNBT(tag); tags.appendTag(tag); } } tagCompound.setTag("items", tags); NBTTagCompound tagWater = new NBTTagCompound(); NBTTagCompound tagLava = new NBTTagCompound(); tankWater.writeToNBT(tagWater); tankLava.writeToNBT(tagLava); tagCompound.setTag("water", tagWater); tagCompound.setTag("lava", tagLava); tagCompound.setInteger("energy", energy); } public int getEnergy() { return energy; } public void setEnergy(int energy) { if(energy > PowerFactoryMultiBlock.getPowerCells(worldObj, xCoord, yCoord, zCoord) * 200000) return; this.energy = energy; if(!worldObj.isRemote) Packets.INSTANCE.sendToAll(new PowerFactoryPacket(this)); } public void addEnergy(int energy) { if(this.energy + energy > PowerFactoryMultiBlock.getPowerCells(worldObj, xCoord, yCoord, zCoord) * 200000) return; this.energy += energy; if(!worldObj.isRemote) Packets.INSTANCE.sendToAll(new PowerFactoryPacket(this)); } public void removeEnergy(int energy) { if(this.energy - energy > PowerFactoryMultiBlock.getPowerCells(worldObj, xCoord, yCoord, zCoord) * 200000) return; this.energy -= energy; if(!worldObj.isRemote) Packets.INSTANCE.sendToAll(new PowerFactoryPacket(this)); } }
  7. In my mod, I setup a packet to handle fluids before and it worked just fine. However, now that I added energy along with BuildCraft support, the world crashes when it loads if pipes from BuildCraft are next to the block. Here is my crash log. [18:40:16] [Client thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception java.lang.NullPointerException at com.kenoba10.electricfactory.network.packet.PowerFactoryPacket.onMessage(PowerFactoryPacket.java:69) ~[PowerFactoryPacket.class:?] at com.kenoba10.electricfactory.network.packet.PowerFactoryPacket.onMessage(PowerFactoryPacket.java:11) ~[PowerFactoryPacket.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:34) ~[simpleChannelHandlerWrapper.class:?] at cpw.mods.fml.common.network.simpleimpl.SimpleChannelHandlerWrapper.channelRead0(SimpleChannelHandlerWrapper.java:14) ~[simpleChannelHandlerWrapper.class:?] at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98) ~[simpleChannelInboundHandler.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103) [MessageToMessageDecoder.class:?] at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111) [MessageToMessageCodec.class:?] at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:337) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:323) [DefaultChannelHandlerContext.class:?] at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785) [DefaultChannelPipeline.class:?] at io.netty.channel.embedded.EmbeddedChannel.writeInbound(EmbeddedChannel.java:169) [EmbeddedChannel.class:?] at cpw.mods.fml.common.network.internal.FMLProxyPacket.processPacket(FMLProxyPacket.java:86) [FMLProxyPacket.class:?] at net.minecraft.network.NetworkManager.processReceivedPackets(NetworkManager.java:247) [NetworkManager.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.updateController(PlayerControllerMP.java:321) [PlayerControllerMP.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1693) [Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1039) [Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:961) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:164) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_60] at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_60] at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_60] at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_60] at GradleStart.bounce(GradleStart.java:108) [start/:?] at GradleStart.startClient(GradleStart.java:101) [start/:?] at GradleStart.main(GradleStart.java:66) [start/:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_60] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_60] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_60] at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_60] at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134) [idea_rt.jar:?] My packet code is: public class PowerFactoryPacket implements IMessage, IMessageHandler<PowerFactoryPacket, IMessage> { public int x; public int y; public int z; public int amountWater; public int amountLava; public int energy; public PowerFactoryPacket() { } public PowerFactoryPacket(PowerFactoryTileEntity tileentity) { x = tileentity.xCoord; y = tileentity.yCoord; z = tileentity.zCoord; amountWater = tileentity.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid.amount; amountLava = tileentity.getTankInfo(ForgeDirection.UNKNOWN)[1].fluid.amount; energy = tileentity.getEnergy(); } public void fromBytes(ByteBuf buf) { x = buf.readInt(); y = buf.readInt(); z = buf.readInt(); amountWater = buf.readInt(); amountLava = buf.readInt(); energy = buf.readInt(); } public void toBytes(ByteBuf buf) { buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); buf.writeInt(amountWater); buf.writeInt(amountLava); buf.writeInt(energy); } public IMessage onMessage(PowerFactoryPacket message, MessageContext context) { PowerFactoryTileEntity tileentity = (PowerFactoryTileEntity)FMLClientHandler.instance().getClient().theWorld.getTileEntity(message.x, message.y, message.z); tileentity.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid.amount = message.amountWater; tileentity.getTankInfo(ForgeDirection.UNKNOWN)[1].fluid.amount = message.amountLava; tileentity.setEnergy(message.energy); return null; } }
  8. I decided to just setup a packet and I set it as the description packet and it works. Thank You!
  9. public FluidTank steamTank = new FluidTank({fluid}, 0, this.tankCapacity); the {fluid} is your steam fluid similar to how if it were water it would be FluidRegistry.WATER
  10. when your checking if it is not null and then using it, you also have an else which still used the variable if it is null. if it is null the fluid itself does not exist including the amount, so you would need to either do nothing with the variable or set the fluid to be the fluid you want it to be.
  11. if it is null your still using the variable, if it is null you can't use it at all
  12. Thank You! I ran a test and it is correctly reading the data, just not displaying it in the gui. Do I want to setup a packet to send the information to the clients then in readFromNBT after I have read in the values?
  13. your tank does not have a default fluid in it so when you get the amount of fluid in it there sometimes is no fluid so it returns null. since it is null when you call it, it crashes your game
  14. I have my gui show me a bar with how much of the liquid is stored. The gui works just fine and shows me how much lava and water is stored when I put water and lava into it. However, when I close the world and reopen it, all fluid in it disappears from what I had last time.
  15. if it isn't that it is probably the tank.getFluid() being null then s diesieben07 said
  16. public class PowerFactoryTileEntity extends TileEntity implements IInventory, IFluidHandler { private ItemStack[] itemInventory; private FluidTank tankWater; private FluidTank tankLava; public PowerFactoryTileEntity() { itemInventory = new ItemStack[8]; tankWater = new FluidTank(FluidRegistry.WATER, 0, FluidContainerRegistry.BUCKET_VOLUME * 4); tankLava = new FluidTank(FluidRegistry.LAVA, 0, FluidContainerRegistry.BUCKET_VOLUME * 4); } public String getInventoryName() { return "container.electricfactory:factoryPower"; } public boolean hasCustomInventoryName() { return false; } public int getSizeInventory() { return itemInventory.length; } public int getInventoryStackLimit() { return 64; } public boolean isUseableByPlayer(EntityPlayer player) { return true; } public void openInventory() { } public void closeInventory() { } public boolean isItemValidForSlot(int index, ItemStack stack) { return true; } public ItemStack getStackInSlot(int index) { return itemInventory[index]; } public ItemStack getStackInSlotOnClosing(int index) { if(itemInventory[index] != null) { itemInventory[index] = null; return itemInventory[index]; } return null; } public ItemStack decrStackSize(int index, int amount) { ItemStack stack = getStackInSlot(index); if(stack != null) { if(stack.stackSize <= amount) { setInventorySlotContents(index, null); } else { stack = stack.splitStack(amount); if(stack.stackSize == 0) setInventorySlotContents(index, null); } } return stack; } public void setInventorySlotContents(int index, ItemStack stack) { itemInventory[index] = stack; if(stack != null && stack.stackSize > getInventoryStackLimit()) stack.stackSize = getInventoryStackLimit(); markDirty(); } public int fill(ForgeDirection side, FluidStack stack, boolean fill) { if(stack.getFluid() == FluidRegistry.WATER) return tankWater.fill(stack, fill); else if(stack.getFluid() == FluidRegistry.LAVA) return tankLava.fill(stack, fill); return 0; } public FluidStack drain(ForgeDirection side, FluidStack stack, boolean drain) { return null; } public FluidStack drain(ForgeDirection side, int max, boolean drain) { return null; } public boolean canFill(ForgeDirection side, Fluid fluid) { return fluid == FluidRegistry.WATER || fluid == FluidRegistry.LAVA; } public boolean canDrain(ForgeDirection side, Fluid fluid) { return false; } public FluidTankInfo[] getTankInfo(ForgeDirection side) { return new FluidTankInfo[] {tankWater.getInfo(), tankLava.getInfo()}; } public void updateEntity() { for(int i = 0; i < getSizeInventory(); i++) { drainBucket(i); } } public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); NBTTagList tags = tagCompound.getTagList("items", 10); for(int i = 0; i < tags.tagCount(); i++) { NBTTagCompound tag = tags.getCompoundTagAt(i); byte index = tag.getByte("slot"); if(index >= 0 && index < itemInventory.length) itemInventory[index] = ItemStack.loadItemStackFromNBT(tag); } NBTTagCompound tagWater = tagCompound.getCompoundTag("water"); NBTTagCompound tagLava = tagCompound.getCompoundTag("lava"); tankWater.readFromNBT(tagWater); tankLava.readFromNBT(tagLava); } public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); NBTTagList tags = new NBTTagList(); for(int i = 0; i < itemInventory.length; i++) { if(itemInventory[i] != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setByte("slot", (byte)i); itemInventory[i].writeToNBT(tag); tags.appendTag(tag); } } tagCompound.setTag("items", tags); NBTTagCompound tagWater = new NBTTagCompound(); NBTTagCompound tagLava = new NBTTagCompound(); tankWater.writeToNBT(tagWater); tankLava.writeToNBT(tagLava); tagCompound.setTag("water", tagWater); tagCompound.setTag("lava", tagLava); } private void drainBucket(int index) { Fluid WATER = FluidRegistry.WATER; Fluid LAVA = FluidRegistry.LAVA; ItemStack bucket = getStackInSlot(index); if(bucket == null || !FluidContainerRegistry.isBucket(bucket) || FluidContainerRegistry.isEmptyContainer(bucket)) return; if(FluidContainerRegistry.getFluidForFilledItem(bucket).getFluid() == WATER) { if(tankWater.getFluid().amount + FluidContainerRegistry.getFluidForFilledItem(bucket).amount <= tankWater.getInfo().capacity) { fill(ForgeDirection.UNKNOWN, FluidContainerRegistry.getFluidForFilledItem(bucket), true); setInventorySlotContents(index, new ItemStack(Items.bucket)); } } else if(FluidContainerRegistry.getFluidForFilledItem(bucket).getFluid() == LAVA) { if(tankLava.getFluid().amount + FluidContainerRegistry.getFluidForFilledItem(bucket).amount <= tankLava.getInfo().capacity) { fill(ForgeDirection.UNKNOWN, FluidContainerRegistry.getFluidForFilledItem(bucket), true); setInventorySlotContents(index, new ItemStack(Items.bucket)); } } else { return; } } }
  17. I believe your problem is you aren't defining the default values such as 0 on the cook and burn time variables inside of your tile entity, so that in your container's updateProgressBar, the value is null and crashes the game
  18. I have an IFluidHandler with 2 tanks in it which both work as there supposed to, however, the tanks will not save to nbt correctly. Here is my code: Reading Tank Data: NBTTagCompound tagWater = tagCompound.getCompoundTag("water"); NBTTagCompound tagLava = tagCompound.getCompoundTag("lava"); tankWater.readFromNBT(tagWater); tankLava.readFromNBT(tagLava); Writing Tank Data: NBTTagCompound tagWater = new NBTTagCompound(); NBTTagCompound tagLava = new NBTTagCompound(); tankWater.writeToNBT(tagWater); tankLava.writeToNBT(tagLava); tagCompound.setTag("water", tagWater); tagCompound.setTag("lava", tagLava);
  19. I am working on a tile entity that holds 2 tanks of fluids that is shown when opening the gui, how would I allow fluids to be stored inside of the tile entity and put in by right clicking and fluid pipes?
  20. I have an idea that might work: Create a random number on getIcon and then make the block a tile entity and make it require the random number argument, the tile entity can then save it so it has the same one when the world is loaded back up, doubt this will work as I just thought of it in my head a few seconds ago, but it may give you an idea of how you could do it.
  21. I have been working the past few days on this in my mod and it was rather simple, what you need to do is add the texture of the fluid to the gui in a separate area similar to the progress bar on the furnace gui and then find out how much is stored from the tileentity and decide the height of it based on that
  22. This may take awhile but look over the Minecraft source code and look at mods that are open source such as BuildCraft and EE3. Almost anything you want to do you can probably find something similar in the Minecraft source. Pahimar has just about the only good series that I know about for learning how to mod, but it is on delay because of his daughter.
  23. A power system is a very complex topic and I don't recommend trying to make one unless you are very experienced in Java and have been making mods for Minecraft for a decent amount of time. However, what I would recommend is having the thing that extracts power handle everything and then have the thing that extracts power check how long the line is and if anything is requesting power send power. That is a very simple explanation but hopefully you can get somewhere from there. I will help you more if you make some progress by yourself .
×
×
  • Create New...

Important Information

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