Jump to content

abused_master

Members
  • Posts

    235
  • Joined

  • Last visited

Everything posted by abused_master

  1. Do you by any chance have a simple example of some data being saved to athe ItemStack's NBT with getDrops? if not thats all right, but thanks for the info will see what happens.
  2. Hey guys, so i was wondering how would i go about storing data to a block after its broken? in that sense i have an EnergyBank, when broken id like the block to retain its energy, how would i go about doing that?
  3. Aha, missed that, fixed
  4. Derp, yeah i forgot about the null in 1.11, so i fixed that up as well as updated my mappings, but the code doesnt seem to work how id like it to, it doesnt transfer the item/block to the slot on shift click only to the top left slot or the one next to it in the inventory, and back and forth. code with updated mappings: @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = ItemStack.EMPTY; Slot slot = (Slot)this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (par2 != 0) { if (itemstack1.getItem() instanceof IEnergyContainerItem) { if (!this.mergeItemStack(itemstack1, 0, 0+1, false)) { return ItemStack.EMPTY; } } else if (par2 >= 1 && par2 < 28) { if (!this.mergeItemStack(itemstack1, 28, 37, false)) { return ItemStack.EMPTY; } } else if (par2 >= 28 && par2 < 37 && !this.mergeItemStack(itemstack1, 1, 28, false)) { return ItemStack.EMPTY; } } else if (!this.mergeItemStack(itemstack1,1, 37, false)) { return ItemStack.EMPTY; } if (itemstack1.getCount() == 0) { slot.putStack((ItemStack)ItemStack.EMPTY); } else { slot.onSlotChanged(); } if (itemstack1.getCount() == itemstack.getCount()) { return ItemStack.EMPTY; } slot.onTake(par1EntityPlayer, itemstack1); } return itemstack; }
  5. Hey everyone, so im currently having some trouble with my container. Its 1 slot to charge an item and only items that are an instance of IEnergyContainerItem can be shift clicked into it. The problem is i cant seem to figure out how to get transferStackInSlot correct, iv looked at some code from other mods and tried to make my own: @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { ItemStack itemstack = null; Slot slot = (Slot)this.inventorySlots.get(par2); if (slot != null && slot.getHasStack()) { ItemStack itemstack1 = slot.getStack(); itemstack = itemstack1.copy(); if (par2 != 0) { if (itemstack1.getItem() instanceof IEnergyContainerItem) { if (!this.mergeItemStack(itemstack1, 0, 0+1, false)) { return null; } } else if (par2 >= 1 && par2 < 28) { if (!this.mergeItemStack(itemstack1, 28, 37, false)) { return null; } } else if (par2 >= 28 && par2 < 37 && !this.mergeItemStack(itemstack1, 1, 28, false)) { return null; } } else if (!this.mergeItemStack(itemstack1,1, 37, false)) { return null; } if (itemstack1.func_190916_E() == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } if (itemstack1.func_190916_E() == itemstack.func_190916_E()) { return null; } slot.func_190901_a(par1EntityPlayer, itemstack1); } return itemstack; } What iv been getting is either it doesn't actually work or with this one it crashes with this crash report: java.lang.NullPointerException: Updating screen events at net.minecraft.inventory.Container.slotClick(Container.java:256) at net.minecraft.client.multiplayer.PlayerControllerMP.windowClick(PlayerControllerMP.java:594) at net.minecraft.client.gui.inventory.GuiContainer.handleMouseClick(GuiContainer.java:687) at net.minecraft.client.gui.inventory.GuiContainer.mouseClicked(GuiContainer.java:429) at net.minecraft.client.gui.GuiScreen.handleMouseInput(GuiScreen.java:611) at net.minecraft.client.gui.GuiScreen.handleInput(GuiScreen.java:576) at net.minecraft.client.Minecraft.runTick(Minecraft.java:1792) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1119) at net.minecraft.client.Minecraft.run(Minecraft.java:407) at net.minecraft.client.main.Main.main(Main.java:118) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) at GradleStart.main(GradleStart.java:26) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147) Can anyone tell me what i'm doing wrong/how i can actually do this to suite my needs/how to make it better
  6. TE: public class TileLeadEnergyBank extends TileEntityInventoryBase { public EnergyStorage storage = new EnergyStorage(50000); public static int SENDPERTICK = 8000; private NonNullList<ItemStack> bankInv = NonNullList.<ItemStack>func_191197_a(1, ItemStack.field_190927_a); int energyStored = storage.getEnergyStored(); int maxEnergyStored = storage.getMaxEnergyStored(); @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList inventory = (NBTTagList) nbt.getTag("Items"); for(int i = 0; i < inventory.tagCount(); i++) { NBTTagCompound itemTag = inventory.getCompoundTagAt(i); ItemStack stack = new ItemStack(itemTag); bankInv.set(itemTag.getByte("Slot"), stack); } storage.readFromNBT(nbt); } @Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); NBTTagList inventory = new NBTTagList(); for(byte slot = 0; slot < bankInv.size(); slot++) { ItemStack stack = bankInv.get(slot); if(!stack.func_190926_b()) { NBTTagCompound itemTag = new NBTTagCompound(); stack.writeToNBT(itemTag); itemTag.setByte("Slot", slot); inventory.appendTag(itemTag); } } nbt.setTag("Items", inventory); return storage.writeToNBT(nbt); } @Override public boolean canConnectEnergy(EnumFacing from) { return true; } @Override public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) { return storage.receiveEnergy(maxReceive, simulate); } @Override public int getEnergyStored(EnumFacing from) { return storage.getEnergyStored(); } @Override public int getMaxEnergyStored(EnumFacing from) { return storage.getMaxEnergyStored(); } public boolean canInteractWith(EntityPlayer playerIn) { return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D; } private net.minecraftforge.items.IItemHandler itemHandler; protected net.minecraftforge.items.IItemHandler createUnSidedHandler() { return new net.minecraftforge.items.wrapper.InvWrapper(this); } @SuppressWarnings("unchecked") @Override @javax.annotation.Nullable public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @javax.annotation.Nullable net.minecraft.util.EnumFacing facing) { if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) (itemHandler == null ? (itemHandler = createUnSidedHandler()) : itemHandler); return super.getCapability(capability, facing); } @Override public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @javax.annotation.Nullable net.minecraft.util.EnumFacing facing) { return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); } @Override public int getSizeInventory() { return this.bankInv.size(); } @Override public ItemStack getStackInSlot(int index) { return (ItemStack)this.bankInv.get(index); } @Override public ItemStack decrStackSize(int index, int count) { return ItemStackHelper.getAndSplit(this.bankInv, index, count); } @Override public ItemStack removeStackFromSlot(int index) { return ItemStackHelper.getAndRemove(this.bankInv, index); } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; } @Override public int getField(int id) { switch (id) { case 0: return this.energyStored; case 1: return this.maxEnergyStored; default: return 0; } } @Override public void setField(int id, int value) { switch (id) { case 0: this.energyStored = value; break; case 1: this.maxEnergyStored = value; } } @Override public int getFieldCount() { return 2; } @Override public void clear() { this.bankInv.clear(); } @Override public String getName() { return ModBlocks.LeadInfusedEnergyBank.getUnlocalizedName(); } @Override public boolean canInsertItem(int index, net.minecraft.item.ItemStack itemStackIn, EnumFacing direction) { return this.isItemValidForSlot(index, itemStackIn); } @Override public boolean canExtractItem(int index, net.minecraft.item.ItemStack stack, EnumFacing direction) { return true; } @Override public void update() { if(!worldObj.isRemote) { PacketHandler.INSTANCE.sendToAll(new MessageTEUpdate(this)); this.chargeItem(); } int energyStored = getEnergyStored(EnumFacing.DOWN); for (EnumFacing facing : EnumFacing.values()) { BlockPos pos = getPos().offset(facing); TileEntity te = worldObj.getTileEntity(pos); if (isEnergyTE(te)) { EnumFacing opposite = facing.getOpposite(); int rfToGive = SENDPERTICK <= energyStored ? SENDPERTICK : energyStored; int received; if (te instanceof IEnergyConnection) { IEnergyConnection connection = (IEnergyConnection) te; if (connection.canConnectEnergy(opposite)) { received = receiveEnergy(te, opposite, rfToGive); } else { received = 0; } } else { received = receiveEnergy(te, opposite, rfToGive); } energyStored -= storage.extractEnergy(received, false); if (energyStored <= 0) { break; } } } } @Override public boolean func_191420_l() { for (ItemStack itemstack : this.bankInv) { if (!itemstack.func_190926_b()) { return false; } } return true; } @Override public void setInventorySlotContents(int index, net.minecraft.item.ItemStack stack) { ItemStack itemstack = (ItemStack)this.bankInv.get(index); boolean flag = !stack.func_190926_b() && stack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(stack, itemstack); this.bankInv.set(index, stack); if (stack.func_190916_E() > this.getInventoryStackLimit()) { stack.func_190920_e(this.getInventoryStackLimit()); } if (index == 0 && !flag) { this.markDirty(); } } @Override public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) { return 0; } public static boolean isEnergyTE(TileEntity te) { return te instanceof IEnergyHandler || (te != null && te.hasCapability(CapabilityEnergy.ENERGY, null)); } public static int receiveEnergy(TileEntity tileEntity, EnumFacing from, int maxReceive) { if (tileEntity instanceof IEnergyReceiver) { return ((IEnergyReceiver) tileEntity).receiveEnergy(from, maxReceive, false); } else if (tileEntity != null && tileEntity.hasCapability(CapabilityEnergy.ENERGY, from)) { IEnergyStorage capability = tileEntity.getCapability(CapabilityEnergy.ENERGY, from); if (capability.canReceive()) { return capability.receiveEnergy(maxReceive, false); } } return 0; } public boolean canCharge() { if(bankInv.get(0).getItem() instanceof IEnergyContainerItem && storage.getEnergyStored() >= 500) { int itemMaxStored = ((IEnergyContainerItem) bankInv.get(0).getItem()).getMaxEnergyStored(bankInv.get(0)); int itemStored = ((IEnergyContainerItem) bankInv.get(0).getItem()).getEnergyStored(bankInv.get(0)); if(itemStored != itemMaxStored) { return true; } else { return false; } } else { return false; } } public void chargeItem() { if (this.canCharge()) { storage.setEnergyStored(storage.getEnergyStored() - 500); ((IEnergyContainerItem) bankInv.get(0).getItem()).receiveEnergy(bankInv.get(0), 500, false); } } } ~Edit did see the other half of the msg, for my text and energybar i switched to this: @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { mc.getTextureManager().bindTexture(gui); this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); if(this.energyBank.storage.getEnergyStored() > 0){ int i = getEnergyScaled(40); this.drawTexturedModalRect(width + 82, height + 21, 178, 4, 12, i); } String LeadBank = I18n.translateToLocal(energyBank.storage.getEnergyStored() + " / " + energyBank.storage.getMaxEnergyStored() + " RF"); mc.fontRendererObj.drawStringWithShadow(LeadBank, guiLeft + xSize / 2 - mc.fontRendererObj.getStringWidth(LeadBank) / 2, guiTop + 4, 0xFFFFFF); if (this.isPointInRegion(82, 21, 14, 40, mouseX, mouseY)) { List<String> rf = new ArrayList<String>(); rf.add(energyBank.getField(0) + " / " + energyBank.getField(1) + " RF"); GuiUtils.drawHoveringText(rf, mouseX, mouseY, 25, 120, -10, mc.fontRendererObj); } } private int getEnergyScaled(int i) { return energyBank.getField(0) * i / energyBank.getField(1); }
  7. Aite, public void detectAndSendChanges() { super.detectAndSendChanges(); for (int i = 0; i < this.listeners.size(); ++i) { IContainerListener icontainerlistener = (IContainerListener)this.listeners.get(i); if (this.energyStored != this.tileLeadBank.getField(0)) { icontainerlistener.sendProgressBarUpdate(this, 0, this.tileLeadBank.getField(0)); } if (this.maxEnergyStored != this.tileLeadBank.getField(1)) { icontainerlistener.sendProgressBarUpdate(this, 1, this.tileLeadBank.getField(1)); } } this.energyStored = this.tileLeadBank.getField(0); this.maxEnergyStored = this.tileLeadBank.getField(1); } @SideOnly(Side.CLIENT) public void updateProgressBar(int id, int data) { this.tileLeadBank.setField(id, data); }
  8. Ahh all right will fix that problem. As for the synchronization in the container iv already tried that method with the getField, setField and detectAndSendChanges but still no luck with it.
  9. Hey everyone, its me again, so i'm having some more trouble with TE Syncing and Gui's. So what i'm doing currently is PacketHandler.INSTANCE.sendToAll(new MessageTEUpdate(this)); with the packet being: http://pastebin.com/K3Gx7N6Z and also adding these http://pastebin.com/SAnEPq6S in my TE, the problem i'm having is my GUI isn't rendering or displaying the correct information... When i say that i mean, i have 2 methods, 1 to render the energy bar, and one to make it so when a player is hovering over a certain location it will display the energy stored, how i'm doing that: http://pastebin.com/UHgVbFpg In game however, the energy bar isn't being rendered, and the hovering text for energy is staying at 0, however i know it is storing energy and has energy using an item to detect energy storage from a block on shift click. Am i missing a step to top it all off or did i mess this up in some way? any help is appreciated.
  10. The packet is for syncing the server to client, so that energy would display correctly, and since im only adding cookTime and totalCookTime to getField and setField, so im not calling upon it in the gui yet directly calling upon the energy stored and max stored
  11. I was doing this in my container public void detectAndSendChanges() { super.detectAndSendChanges(); for (int i = 0; i < this.listeners.size(); ++i) { IContainerListener icontainerlistener = (IContainerListener)this.listeners.get(i); if (this.cookTime != this.tileCrusher.getField(1)) { icontainerlistener.sendProgressBarUpdate(this, 1, this.tileCrusher.getField(1)); } if (this.totalCookTime != this.tileCrusher.getField(2)) { icontainerlistener.sendProgressBarUpdate(this, 2, this.tileCrusher.getField(2)); } } this.cookTime = this.tileCrusher.getField(1); this.totalCookTime = this.tileCrusher.getField(2); } @SideOnly(Side.CLIENT) public void updateProgressBar(int id, int data) { this.tileCrusher.setField(id, data); }
  12. Hey guys, so i'm having some issues with my TileEntity updating. So with my TE i'm rending a power bar and a progress bar, as its a crusher. I have a packet that updates my TE. The problem is when i call upon that packet, the power bar renders just fine but the progress bar doesn't render. But on removing it the progress bar is fine but power isn't. Packet: public class MessageTEUpdate implements IMessage { public NBTTagCompound tag = new NBTTagCompound(); public MessageTEUpdate(){ } public MessageTEUpdate(TileEntity tile){ this.tag = tile.getUpdateTag(); } @Override public void fromBytes(ByteBuf buf) { tag = ByteBufUtils.readTag(buf); } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeTag(buf, tag); } public static class MessageHolder implements IMessageHandler<MessageTEUpdate,IMessage> { @SideOnly(Side.CLIENT) @Override public IMessage onMessage(final MessageTEUpdate message, final MessageContext ctx) { Minecraft.getMinecraft().addScheduledTask(()-> { if ((Minecraft.getMinecraft().thePlayer.getEntityWorld()).getTileEntity(new BlockPos(message.tag.getInteger("x"),message.tag.getInteger("y"),message.tag.getInteger("z"))) != null){ Minecraft.getMinecraft().thePlayer.getEntityWorld().getTileEntity(new BlockPos(message.tag.getInteger("x"),message.tag.getInteger("y"),message.tag.getInteger("z"))).readFromNBT(message.tag); Minecraft.getMinecraft().thePlayer.getEntityWorld().getTileEntity(new BlockPos(message.tag.getInteger("x"),message.tag.getInteger("y"),message.tag.getInteger("z"))).markDirty(); } }); return null; } } } Progress bar & Power Bar private int getEnergyScaled(int i) { return crusher.storage.getEnergyStored() * i / crusher.storage.getMaxEnergyStored(); } public void renderEnergy() { int i = getEnergyScaled(40); this.drawTexturedModalRect(guiLeft + 10, guiTop + 9, 178, 4, 12, i); } public void renderProgress() { int l = this.getCookProgressScaled(24); this.drawTexturedModalRect(guiLeft + 81, guiTop + 26, 176, 46, l, 16); } and then i'm calling those in my drawGuiContainerBackgroundLayer any help in fixing this is appreciated
  13. Try adding this in your TE @Nullable @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound data = new NBTTagCompound(); writeToNBT(data); return new SPacketUpdateTileEntity(this.pos, 1, data); } @Override @SideOnly(Side.CLIENT) public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity s35PacketUpdateTileEntity) { readFromNBT(s35PacketUpdateTileEntity.getNbtCompound()); worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos); markForUpdate(); } public void markForUpdate() { if (this.worldObj != null) { Block block = worldObj.getBlockState(this.pos).getBlock(); this.worldObj.notifyBlockUpdate(this.pos, worldObj.getBlockState(this.pos), worldObj.getBlockState(this.pos), 3); } } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound nbtTagCompound = new NBTTagCompound(); writeToNBT(nbtTagCompound); return nbtTagCompound; }
  14. Its actually pretty simple, you can see how im doing it here to enable jetpack flight https://github.com/abused/Tech-Expansion/blob/master/src/main/java/abused_master/TechExpansion/registry/KeybindHandler.java and then i call KeybindHandler.init(); in the preInit in my client proxy, using it is easy too how im doing it is checking if its being used as so: if(KeybindHandler.keybind.isKeyDown()) { }
  15. I haven't messed with .obj much but yes from what iv tried iv had to scale it down in blender, resize it down to just one of the squares like where that circle is: https://gyazo.com/d8765a05d4f7f32f5fcc42d03628f9d5
  16. Aww for fuck's sake, haven't you see anything on these forums about Capabilities? To expand on this slightly: The whole point of the Capability System is that you don't implement every interface on your Entity / TileEntity / Item , instead you store an instance of the interface and provide it from the ICapabilityProvider methods. The Capability System is documented here. do you have an example of this being done? im reading up on the documentation right now but id also like an example to follow along to see how someone else has done it for reference
  17. Tile: public class TileRFFurnace extends TileEntity implements ITickable, IInventory, ISidedInventory, IEnergyReceiver, IEnergyProvider{ public EnergyStorage storage = new EnergyStorage(50000); private NonNullList<ItemStack> furnaceInv= NonNullList.<ItemStack>func_191197_a(2, ItemStack.field_190927_a); private int cookTime; private int totalCookTime; @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList inventory = (NBTTagList) nbt.getTag("Items"); for(int i = 0; i < inventory.tagCount(); i++) { NBTTagCompound itemTag = inventory.getCompoundTagAt(i); ItemStack stack = new ItemStack(itemTag); furnaceInv.set(itemTag.getByte("Slot"), stack); } this.cookTime = nbt.getInteger("CookTime"); this.totalCookTime = nbt.getInteger("TotalCookTime"); storage.readFromNBT(nbt); } @Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); NBTTagList inventory = new NBTTagList(); for(byte slot = 0; slot < furnaceInv.size(); slot++) { ItemStack stack = furnaceInv.get(slot); if(!stack.func_190926_b()) { NBTTagCompound itemTag = new NBTTagCompound(); stack.writeToNBT(itemTag); itemTag.setByte("Slot", slot); inventory.appendTag(itemTag); } } nbt.setTag("Items", inventory); nbt.setInteger("cookTime", (short)this.cookTime); nbt.setInteger("TotalCookTime", (short)this.totalCookTime); return storage.writeToNBT(nbt); } @Override public boolean canConnectEnergy(EnumFacing from) { return true; } @Override public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) { return storage.receiveEnergy(maxReceive, simulate); } @Override public int getEnergyStored(EnumFacing from) { return storage.getEnergyStored(); } @Override public int getMaxEnergyStored(EnumFacing from) { return storage.getMaxEnergyStored(); } public boolean canInteractWith(EntityPlayer playerIn) { return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D; } private net.minecraftforge.items.IItemHandler itemHandler; protected net.minecraftforge.items.IItemHandler createUnSidedHandler() { return new net.minecraftforge.items.wrapper.InvWrapper(this); } @SuppressWarnings("unchecked") @Override @javax.annotation.Nullable public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @javax.annotation.Nullable net.minecraft.util.EnumFacing facing) { if (capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return (T) (itemHandler == null ? (itemHandler = createUnSidedHandler()) : itemHandler); return super.getCapability(capability, facing); } @Override public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @javax.annotation.Nullable net.minecraft.util.EnumFacing facing) { return capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing); } @Override public int getSizeInventory() { return this.furnaceInv.size(); } @Override public ItemStack getStackInSlot(int index) { return (ItemStack)this.furnaceInv.get(index); } @Override public ItemStack decrStackSize(int index, int count) { return ItemStackHelper.getAndSplit(this.furnaceInv, index, count); } @Override public ItemStack removeStackFromSlot(int index) { return ItemStackHelper.getAndRemove(this.furnaceInv, index); } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { return this.worldObj.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D; } @Override public void openInventory(EntityPlayer player) { } @Override public void closeInventory(EntityPlayer player) { } @Override public boolean isItemValidForSlot(int index, ItemStack stack) { { if (index == 2) { return false; } else if (index != 1) { return true; }else { return true; } } } @Override public int getField(int id) { switch (id) { case 0: return this.cookTime; case 1: return this.totalCookTime; default: return 0; } } @Override public void setField(int id, int value) { switch (id) { case 0: this.cookTime = value; break; case 1: this.totalCookTime = value; } } @Override public int getFieldCount() { return 4; } @Override public void clear() { this.furnaceInv.clear(); } @Override public String getName() { return ModBlocks.furnaceInv.getUnlocalizedName(); } @Override public boolean hasCustomName() { return false; } @Override public int[] getSlotsForFace(EnumFacing side) { return null; } @Override public boolean canInsertItem(int index, net.minecraft.item.ItemStack itemStackIn, EnumFacing direction) { return this.isItemValidForSlot(index, itemStackIn); } @Override public boolean canExtractItem(int index, net.minecraft.item.ItemStack stack, EnumFacing direction) { if (direction == EnumFacing.DOWN && index == 1) { Item item = stack.getItem(); if (item != Items.WATER_BUCKET && item != Items.BUCKET) { return false; } } return true; } public boolean canSmelt() { if (((ItemStack)this.furnaceInv.get(0)).func_190926_b()) { return false; }else { return true; } } @Override public void update() { if(!getWorld().isRemote) { PacketHandler.INSTANCE.sendToAll(new MessageTEUpdate(this)); } boolean flag1 = false; if (!this.worldObj.isRemote) { ItemStack itemstack = (ItemStack)this.furnaceInv.get(1); if (storage.getEnergyStored() > 50 || !itemstack.func_190926_b() && !((ItemStack)this.furnaceInv.get(0)).func_190926_b()) { if (!(storage.getEnergyStored() > 50) && this.canSmelt()) { if (storage.getEnergyStored() > 50) { flag1 = true; if (!itemstack.func_190926_b()) { Item item = itemstack.getItem(); itemstack.func_190918_g(1); if (itemstack.func_190926_b()) { ItemStack item1 = item.getContainerItem(itemstack); this.furnaceInv.set(1, item1); } } } } if (storage.getEnergyStored() > 50 && this.canSmelt()) { ++this.cookTime; if (this.cookTime == this.totalCookTime) { this.cookTime = 0; this.totalCookTime = this.getCookTime((ItemStack)this.furnaceInv.get(0)); this.SmeltItem(); flag1 = true; } } else { this.cookTime = 0; } } else if (!(storage.getEnergyStored() > 50) && this.cookTime > 0) { this.cookTime = MathHelper.clamp_int(this.cookTime - 2, 0, this.totalCookTime); } } if (flag1) { this.markDirty(); } } public void SmeltItem() { if (this.canSmelt()) { ItemStack itemstack = (ItemStack) this.furnaceInv.get(0); ItemStack itemstack1 = FurnaceRecipes.instance().getSmeltingResult(itemstack); ItemStack itemstack2 = (ItemStack) this.furnaceInv.get(1); if (storage.getEnergyStored() >= 50 && !itemstack1.func_190926_b()) { storage.setEnergyStored(storage.getEnergyStored() - 50); if (itemstack2.func_190926_b()) { this.furnaceInv.set(1, itemstack1.copy()); } else if (itemstack2.getItem() == itemstack1.getItem()) { itemstack2.func_190917_f(itemstack1.func_190916_E()); } itemstack.func_190918_g(1); } } } @Override public boolean func_191420_l() { for (ItemStack itemstack : this.furnaceInv) { if (!itemstack.func_190926_b()) { return false; } } return true; } @Override public void setInventorySlotContents(int index, net.minecraft.item.ItemStack stack) { ItemStack itemstack = (ItemStack)this.furnaceInv.get(index); boolean flag = !stack.func_190926_b() && stack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(stack, itemstack); this.furnaceInv.set(index, stack); if (stack.func_190916_E() > this.getInventoryStackLimit()) { stack.func_190920_e(this.getInventoryStackLimit()); } if (index == 0 && !flag) { this.totalCookTime = this.getCookTime(stack); this.cookTime = 0; this.markDirty(); } } @Nullable @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound data = new NBTTagCompound(); writeToNBT(data); return new SPacketUpdateTileEntity(this.pos, 1, data); } @Override @SideOnly(Side.CLIENT) public void onDataPacket(NetworkManager networkManager, SPacketUpdateTileEntity s35PacketUpdateTileEntity) { readFromNBT(s35PacketUpdateTileEntity.getNbtCompound()); worldObj.markBlockRangeForRenderUpdate(this.pos, this.pos); markForUpdate(); } public void markForUpdate() { if (this.worldObj != null) { Block block = worldObj.getBlockState(this.pos).getBlock(); this.worldObj.notifyBlockUpdate(this.pos, worldObj.getBlockState(this.pos), worldObj.getBlockState(this.pos), 3); } } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound nbtTagCompound = new NBTTagCompound(); writeToNBT(nbtTagCompound); return nbtTagCompound; } @Override public void handleUpdateTag(NBTTagCompound tag) { this.readFromNBT(tag); } @Override public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) { return 0; } public int getCookTime(ItemStack stack) { return 200; } } GUI: public class GuiRFFurnace extends GuiContainer { public static final ResourceLocation RFFurance= new ResourceLocation(Info.MODID, "textures/gui/furnace_gui.png"); public static final int WIDTH = 176; public static final int HEIGHT = 166; TileRFFurnace furnace; public GuiRFFurnace (TileRFFurnace tileEntity, RFFurnacecontainer, TileEntity te) { super(container); xSize = WIDTH; ySize = HEIGHT; furnace = (TileRFFurnace) tileEntity; } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { mc.getTextureManager().bindTexture(RFFurnace); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); int l = this.getCookProgressScaled(24); this.drawTexturedModalRect(guiLeft + 81, guiTop + 27, 176, 46, l, 16); if (this.isPointInRegion(10, 9, 14, 42, mouseX, mouseY)) { List<String> rf = new ArrayList<String>(); rf.add(furnace.storage.getEnergyStored() + "/50000 RF"); GuiUtils.drawHoveringText(rf, mouseX, mouseY, 25, 120, -10, mc.fontRendererObj); } } private int getCookProgressScaled(int pixels) { int i = this.furnace.getField(0); int j = this.furnace.getField(1); return j != 0 && i != 0 ? i * pixels / j : 0; } }
  18. Im pretty sure it isnt possible to convert .obj to .json but if you need a tutorial on how to use .obj for rendering: [removed link to adware site]
  19. Hey guys, so i was wondering how i can fully sync my gui with the client, the reason being is my gui for my furnace works fine except for 2 problems, #1 when i take out all the stuff it has smelted and put them in my inventory the amount that was there stays until you click it or reopen the gui, another thing is my progress bar, its not rendering correctly because of this.
  20. Hey all, so today i was working on a mod thats sole purpose was a new dimension, but ran into some problems, minecraft starts up just fine but creating a world crashed, Crash Report: http://pastebin.com/tNFjthiY Code: ChunkProvider: public class CaveChunkProvider implements IChunkGenerator { public static final int FLOOR_HEIGHT = 62; public static final int CEILING_HEIGHT = 120; static int seedOffset = 0; static ImmutableSet<OreGenEvent.GenerateMinable.EventType> bannedOres = ImmutableSet.of(OreGenEvent.GenerateMinable.EventType.DIRT, OreGenEvent.GenerateMinable.EventType.GRAVEL, OreGenEvent.GenerateMinable.EventType.ANDESITE, OreGenEvent.GenerateMinable.EventType.DIORITE, OreGenEvent.GenerateMinable.EventType.GRANITE); private final World worldObj; static { MinecraftForge.ORE_GEN_BUS.register(CaveChunkProvider.class); } private final List<MapGenStructure> structureGenerators = Lists.newArrayList(); private final List<MapGenBase> generators = Lists.newArrayList(); Random random = new Random(); GenStates[] nextState; Biome[] biomes = null; private WorldGenLakes waterLakeGenerator; private WorldGenLakes lavaLakeGenerator; public CaveChunkProvider(World worldIn, long seed) { int length = GenStates.values().length; this.nextState = new GenStates[length - 1]; System.arraycopy(GenStates.values(), 1, this.nextState, 0, length - 1); this.worldObj = worldIn; this.structureGenerators.add(new MapGenScatteredFeature()); this.structureGenerators.add(new MapGenMineshaft()); this.generators.add(TerrainGen.getModdedMapGen(new MapGenCaves(), InitMapGenEvent.EventType.CAVE)); this.generators.add(TerrainGen.getModdedMapGen(new MapGenRavine(), InitMapGenEvent.EventType.RAVINE)); this.waterLakeGenerator = new WorldGenLakes(Blocks.WATER); this.lavaLakeGenerator = new WorldGenLakes(Blocks.LAVA); } @SubscribeEvent public static void preventOres(OreGenEvent.GenerateMinable event) { OreGenEvent.GenerateMinable.EventType type = event.getType(); } @Nonnull public Chunk provideChunk(int x, int z) { ChunkPrimer chunkprimer = new ChunkPrimer(); this.random.setSeed(this.worldObj.getSeed() + (x >> 2) * 65535 + (z >> 2)); int spire_x = (x >> 2) * 64 + (8 + this.random.nextInt(48)) - x * 16; int spire_z = (z >> 2) * 64 + (8 + this.random.nextInt(48)) - z * 16; this.random.setSeed(x * 341873128712L + z * 132897987541L); GenStates[] values = GenStates.values(); for (int dx = 0; dx < 16; dx++) { for (int dz = 0; dz < 16; dz++) { int rs = (spire_x - dx) * (spire_x - dx) + (spire_z - dz) * (spire_z - dz); double spire_dist = rs < 256 ? Math.sqrt(rs) : Double.MAX_VALUE; GenStates curState = GenStates.FLOOR_BEDROCK; for (int dy = 0; dy < 256; dy++) { IBlockState state = curState.state; if ((curState == GenStates.AIR) && (rs < 256)) { int m = Math.min(dy - 62, 120 - dy); double t = spire_dist; if (m < 9) { t -= Math.sqrt(9 - m); } if ((t <= 4.0D) || ((t <= 5.0D) && (this.random.nextBoolean()))) { state = Blocks.COBBLESTONE.getDefaultState(); } } if (dy >= 253) { state = Blocks.BEDROCK.getDefaultState(); } chunkprimer.setBlockState(dx, dy, dz, state); boolean advance; switch (curState) { case FLOOR_BEDROCK: advance = (dy > 2) || ((dy > 0) && (this.random.nextBoolean())); break; case GROUND: advance = (dy >= 64) || ((dy >= 62) && (this.random.nextInt(4) != 0)); break; case AIR: advance = (dy >= 90) && ((dy >= 120) || (this.random.nextInt(1 + 2 * (120 - dy) * (120 - dy)) == 0)); break; case CEILING: advance = (dy >= 120) && (this.random.nextInt(40) == 0); break; case CEILING_STONE: advance = dy >= 253; break; case CEILING_BEDROCK: advance = false; break; default: throw new RuntimeException("Invalid State " + curState); } if (advance) { curState = values[(curState.ordinal() + 1)]; } } } } for (MapGenBase generator : this.generators) { generator.generate(this.worldObj, x, z, chunkprimer); } for (MapGenBase mapgenbase : this.structureGenerators) { mapgenbase.generate(this.worldObj, x, z, chunkprimer); } for (int dx = 0; dx < 16; dx++) { for (int dz = 0; dz < 16; dz++) { for (int dy = 62; dy < 65; dy++) { if (chunkprimer.getBlockState(dx, dy, dz) == Blocks.STONE.getDefaultState()) { chunkprimer.setBlockState(dx, dy, dz, Blocks.COBBLESTONE.getDefaultState()); } } } } Chunk chunk = new Chunk(this.worldObj, chunkprimer, x, z); this.biomes = this.worldObj.getBiomeProvider().getBiomesForGeneration(this.biomes, x * 16, z * 16, 16, 16); byte[] biomeIDs = chunk.getBiomeArray(); for (int l = 0; l < biomeIDs.length; l++) { biomeIDs[l] = ((byte)Biome.getIdForBiome(this.biomes[l])); } chunk.generateSkylightMap(); return chunk; } public void populate(int x, int z) { BlockFalling.fallInstantly = true; int i = x * 16; int j = z * 16; BlockPos blockpos = new BlockPos(i, 0, j); Biome biome = this.worldObj.getBiomeForCoordsBody(new BlockPos(i + 16, 0, j + 16)); boolean flag = false; this.random.setSeed(this.worldObj.getSeed()); long k = this.random.nextLong() / 2L * 2L + 1L; long l = this.random.nextLong() / 2L * 2L + 1L; this.random.setSeed(x * k + z * l ^ this.worldObj.getSeed()); ChunkPos chunkpos = new ChunkPos(x, z); ForgeEventFactory.onChunkPopulate(true, this, this.worldObj, this.random, x, z, false); for (MapGenStructure mapgenstructure : this.structureGenerators) { boolean flag1 = mapgenstructure.generateStructure(this.worldObj, this.random, chunkpos); if ((mapgenstructure instanceof MapGenVillage)) { flag |= flag1; } } if ((this.waterLakeGenerator != null) && (!flag) && (this.random.nextInt(4) == 0)) { this.waterLakeGenerator.generate(this.worldObj, this.random, blockpos.add(this.random.nextInt(16) + 8, this.random.nextInt(256), this.random.nextInt(16) + ); } if ((this.lavaLakeGenerator != null) && (!flag) && (this.random.nextInt( == 0)) { BlockPos blockpos1 = blockpos.add(this.random.nextInt(16) + 8, this.random.nextInt(this.random.nextInt(248) + , this.random.nextInt(16) + ; } for (int i1 = 0; i1 < 8; i1++) { new WorldGenDungeons().generate(this.worldObj, this.random, blockpos.add(this.random.nextInt(16) + 8, this.random.nextInt(256), this.random.nextInt(16) + ); } for (int i2 = 0; i2 < 2; i2++) { seedOffset = i2; biome.decorate(this.worldObj, this.random, blockpos); } seedOffset = 0; ForgeEventFactory.onChunkPopulate(false, this, this.worldObj, this.random, x, z, flag); BlockFalling.fallInstantly = false; seedOffset = 1; GameRegistry.generateWorld(x, z, this.worldObj, this, this.worldObj.getChunkProvider()); seedOffset = 0; } public boolean generateStructures(@Nonnull Chunk chunkIn, int x, int z) { return false; } @Nonnull public List<Biome.SpawnListEntry> getPossibleCreatures(@Nonnull EnumCreatureType creatureType, @Nonnull BlockPos pos) { Biome biome = this.worldObj.getBiomeForCoordsBody(pos); return biome.getSpawnableList(creatureType); } @Nullable public BlockPos getStrongholdGen(@Nonnull World worldIn, @Nonnull String structureName, @Nonnull BlockPos position) { return null; } public void recreateStructures(@Nonnull Chunk chunkIn, int x, int z) { for (MapGenStructure mapgenstructure : this.structureGenerators) { mapgenstructure.generate(this.worldObj, x, z, null); } } static enum GenStates { FLOOR_BEDROCK(Blocks.BEDROCK.getDefaultState()), GROUND(Blocks.STONE.getDefaultState()), AIR(Blocks.AIR.getDefaultState()), CEILING(Blocks.COBBLESTONE.getDefaultState()), CEILING_STONE(Blocks.STONE.getDefaultState()), CEILING_BEDROCK(Blocks.BEDROCK.getDefaultState()); final IBlockState state; private GenStates(IBlockState state) { this.state = state; } } } World Provider: public class CaveWorldProvider extends OvercaveWorldProvider { static { MinecraftForge.EVENT_BUS.register(CaveWorldProvider.class); } public CaveWorldProvider() { super(OvercaveEntries.over_cave); this.isHellWorld = false; this.hasNoSky = true; } public long getSeed() { int i = CaveChunkProvider.seedOffset; if (i != 0) { return super.getSeed() * 31L + i; } return super.getSeed(); } public int getHeight() { return 81; } public boolean canCoordinateBeSpawn(int x, int z) { return true; } public boolean canRespawnHere() { return true; } public boolean isSurfaceWorld() { return false; } public boolean isSkyColored() { return false; } public boolean doesXZShowFog(int x, int z) { return false; } @Nullable public float[] calcSunriseSunsetColors(float celestialAngle, float partialTicks) { return null; } @Nonnull public Vec3d getFogColor(float p_76562_1_, float p_76562_2_) { return new Vec3d(1.0E-5D, 1.0E-5D, 1.0E-5D); } public float calculateCelestialAngle(long par1, float par3) { int j = 18000; float f1 = (j + par3) / 24000.0F - 0.25F; if (f1 < 0.0F) { f1 += 1.0F; } if (f1 > 1.0F) { f1 -= 1.0F; } float f2 = f1; f1 = 1.0F - (float)((Math.cos(f1 * 3.141592653589793D) + 1.0D) / 2.0D); f1 = f2 + (f1 - f2) / 3.0F; return f1; } @Nonnull public IChunkGenerator createChunkGenerator() { return new CaveChunkProvider(this.worldObj, getSeed()); } protected void generateLightBrightnessTable() { float f = 0.0F; for (int i = 0; i <= 15; i++) { float p = i / 15.0F; float f1 = 1.0F - p; this.lightBrightnessTable[i] = (p / (f1 * 3.0F + 1.0F)); if (this.lightBrightnessTable[i] < 0.2F) { this.lightBrightnessTable[i] *= this.lightBrightnessTable[i] / 0.2F; } } } } OverCaveWorldProvider: public class OvercaveWorldProvider extends WorldProvider { final DimensionEntry entry; public OvercaveWorldProvider(DimensionEntry entry) { this.entry = entry; } @Nonnull public DimensionType getDimensionType() { return (DimensionType) this.entry.value; } }
  21. Tried a few different ways but nothing really worked, still randomly blinking the progress but not fully showing it, https://gyazo.com/f1a6ef32246c42b7de0741023840c2b9
  22. sure: for the Container public void detectAndSendChanges() { super.detectAndSendChanges(); for (int i = 0; i < this.listeners.size(); ++i) { IContainerListener icontainerlistener = (IContainerListener)this.listeners.get(i); if (this.cookTime != this.tileTestFurnace.getField(0)) { icontainerlistener.sendProgressBarUpdate(this, 0, this.tileTestFurnace.getField(0)); } if (this.totalCookTime != this.tileTestFurnace.getField(1)) { icontainerlistener.sendProgressBarUpdate(this, 1, this.tileTestFurnace.getField(1)); } } this.cookTime = this.tileTestFurnace.getField(0); this.totalCookTime = this.tileTestFurnace.getField(1); } @SideOnly(Side.CLIENT) public void updateProgressBar(int id, int data) { this.tileTestFurnace.setField(id, data); } Gui: //in the drawGuiContainerBackgroundLayer int l = this.getCookProgressScaled(24); this.drawTexturedModalRect(guiLeft + 81, guiTop + 27, 176, 46, l + 1, 16); private int getCookProgressScaled(int pixels) { int i = this.tileTestFurnace.getField(0); int j = this.tileTestFurnace.getField(1); return j != 0 && i != 0 ? i * pixels / j : 0; } and the getField and setField: @Override public int getField(int id) { switch (id) { case 0: return this.cookTime; case 1: return this.totalCookTime; default: return 0; } } @Override public void setField(int id, int value) { switch (id) { case 0: this.cookTime = value; break; case 1: this.totalCookTime = value; } } @Override public int getFieldCount() { return 4; }
  23. The exact same as a vanilla furnace, if u mean the flickering, its always random
  24. yeah i found the mistake after i posted, now what ends up happening is the progress bar flickers on sometimes the progress when working but doesnt stay on the entire time it works, example: https://gyazo.com/a5b6a3b85575992e7e9a49b2b23db499
×
×
  • Create New...

Important Information

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