dude22072
-
Posts
185 -
Joined
-
Last visited
Posts posted by dude22072
-
-
As the title says, what would the replacement be for "ItemRenderer.renderItemIn2D" and the getMin/MaxU/V of IIcon?
-
I can't seem to find any tutorials on how to create RetroGen. What classes do i need to extend/implement?
-
Did you register the Generator?
The int chunkX is the number of the chunk that is getting generated. Which is NOT equals to the xPos of the first block.. remember each chunk is 16x16 so some simple math will bring you there
Besides that.. There are some things in your coding style which you should REALLY work on.
Your method generateBacteria is returning a boolean. Which is ALWAYS true, and you arent event using that value. Why not make your method a void then?
You have a a loop in your generateBacteria method which is defining a variable i1 as counter variable. But you are never using that variable. If u want to check if y>128 maybe you should use a while loop, so you dont define useless variables?
Greetz Fail
Yes, it's registered.
Didn't know that, will fix.
Finally, generateBacteria is an exact copy of Minecraft's vine generation with the function name changed. So go yell at Jeb_ or whoever makes Minecraft nowadays.
-
I'm attempting to make world gen for a custom block that works the same as vines. The following is my IWorldGenerator code:
package dudesmods.fancycheeses.world.gen.feature; import java.util.Random; import cpw.mods.fml.common.IWorldGenerator; import dudesmods.fancycheeses.FancyCheeses; import net.minecraft.util.Direction; import net.minecraft.util.Facing; import net.minecraft.world.World; import net.minecraft.world.chunk.IChunkProvider; public class WorldGenBacteraLactococcus implements IWorldGenerator { @Override public void generate(Random random, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider) { if(world.provider.dimensionId == 0) { int firstBlockXCoord = chunkX + random.nextInt(16); int firstBlockYCoord = 64; int firstBlockZCoord = chunkZ + random.nextInt(16); generateBacteria(world, random, firstBlockXCoord, firstBlockYCoord, firstBlockZCoord); } } public boolean generateBacteria(World world, Random rand, int x, int y, int z) { int l = x; for (int i1 = z; y < 128; ++y) { if (world.isAirBlock(x, y, z)) { for (int j1 = 2; j1 <= 5; ++j1) { if (FancyCheeses.bacteria_lactococcus.canPlaceBlockOnSide(world, x, y, z, j1)) { world.setBlock(x, y, z, FancyCheeses.bacteria_lactococcus, 1 << Direction.facingToDirection[Facing.oppositeSide[j1]], 2); break; } } } else { x = l + rand.nextInt(4) - rand.nextInt(4); z = i1 + rand.nextInt(4) - rand.nextInt(4); } } return true; } }
but nothing is generating.
-
ItemStacks have the method getItem(), but they don't seem to have getBlock(). Is it one of the func_s or does it simply not exist?
-
You have to do it yourself, you get the currently selected slot (0- with player.inventory.currentItem.
And then how would I consume the item? ConsumeItem doesn't take a slot.
-
In the code below i'm making it so a milk bucket acts as a normal bucket. But when "event.entityPlayer.inventory.consumeInventoryItem(Items.milk_bucket);" is called it will consume any milk bucket on the hotbar (in order from left to right) instead of the one in hand.
@SubscribeEvent public void onPlayerInteraction(PlayerInteractEvent event) { if(event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) { if(event.entityPlayer.getHeldItem().getItem() != null && event.entityPlayer.getHeldItem().getItem() == Items.milk_bucket) { if(!event.entityPlayer.capabilities.isCreativeMode) { event.entityPlayer.inventory.consumeInventoryItem(Items.milk_bucket); event.entityPlayer.inventory.addItemStackToInventory(new ItemStack(Items.bucket, 1)); } switch (event.face) { case 0: event.world.setBlock(event.x, event.y-1, event.z, FancyCheeses.block_cow_milk); //y-1 case 1: event.world.setBlock(event.x, event.y+1, event.z, FancyCheeses.block_cow_milk); //y+1 case 2: event.world.setBlock(event.x, event.y, event.z-1, FancyCheeses.block_cow_milk); //z-1 case 3: event.world.setBlock(event.x, event.y, event.z+1, FancyCheeses.block_cow_milk); //z+1 case 4: event.world.setBlock(event.x-1, event.y, event.z, FancyCheeses.block_cow_milk); //x-1 case 5: event.world.setBlock(event.x+1, event.y, event.z, FancyCheeses.block_cow_milk); //x+1 } } } }
-
I was wondering how to make my TileEntity compatible with fluid pipes such as BuildCraft's Waterproof pipes or Thermal Expansion's Liquiducts.
-
I was wondering how to overwrite the vanilla milk bucket so I can make milk a fluid, as MFR does. Also, If it's possible, have my mod detect if MFR is installed and use it's fluid instead of adding my own.
-
where do i get fontRenderer from?
Edit: Found it, It's ment to be fontRendererObj
-
In mods such as Tinker's Construct and Thermal Expansion when you hover over a liquid in a gui it tells you the name of the liquid and the amount in mB. How is this accomplished?
-
Ernio is right, Im sorry to misunderstand your question. Nevertheless it is still a thing you might want to change.
Anyway, on to the problem, you are adding the buttons to the buttonlist. but Im not sure if thats the correct list to be honest. I used controlList.add(), maybe that will give the buttons acces to actionPerformed().
This man is correct. buttonList is deprecated. use controlList instead.
-
I was wondering how to make something happen in onItemUse when the player Shift+Right Clicks, but not if the player is holding right-click and then hits shift.
-
Warning: This is only for 1.7.10. I haven't figured out what the equivalent for 1.8 is yet.
You may want to draw the texture of an Item in a custom GuiScreen. Items don't directly have a ResourceLocation for their texture. Instead, they have an IIcon object which holds the UV-coordinates of the texture on a giant image which holds all the Item textures. The ResourceLocation is located at TextureMap.locationItemsTexture. If you want to use this in a GUI, you have to get the IIcon of the Item first, bind the TextureMap.locationItemsTexture, and then call the drawTexturedModelRectFromIcon() method to draw the IIcon of the item.
So, something like this?
protected void guiDrawIcon(Item item, int x, int y) { Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); IIcon icon = item.getIconFromDamage(0); GL11.glEnable(GL11.GL_BLEND); this.drawTexturedModelRectFromIcon(x, y, icon, 16, 16); GL11.glDisable(GL11.GL_BLEND); }
-
I was wondering how I could get an item's icon to display in a GUI. (Or a fake slot would work too, but I don't know how to do that either.)
-
This includes 3 methods:
addCraftingToCrafters(ICrafting crafting)
detectAndSendChanges
updateProgressBar(int id, int amount)
OK, using these has solved some most of my problems.
Sorry for being vague earlier.
At the moment, the issue is that when I click a button on my gui, it doesn't seem to do anything.
My System.out.println()s are telling me the IMessage class is receiving the message, but then the functions in the TileEntity class that they call don't seem to do anything.
-
Whenever I close Minecraft and re-launch it the TileEntity is missing some data, but not all?
Also it seems the GUI is not updating on certain things.
Block:
package dudesmods.fancycheeses.block; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; public class CheeseMaker extends BlockContainer { private boolean isActive; @SideOnly(Side.CLIENT) private IIcon iconFront; @SideOnly(Side.CLIENT) private IIcon iconTop; private static boolean keepInventory; private Random rand = new Random(); public CheeseMaker() { super(Material.iron); setHardness(3.5F); setCreativeTab(FancyCheeses.tabfancycheeses); } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon("fancycheeses:milkmaker_side"); this.iconFront = iconRegister.registerIcon("fancycheeses:milkmaker_front"); this.iconTop = iconRegister.registerIcon("fancycheeses:milkmaker_top"); } @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int metadata) { return metadata == 0 && side == 3 ? this.iconFront : side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side == metadata ? this.iconFront : this.blockIcon)); //return side == 1 ? this.iconTop : (side == 0 ? this.iconTop : (side != metadata ? this.blockIcon : this.iconFront)); } public Item getItemDropped(int i, Random random, int j) { return Item.getItemFromBlock(FancyCheeses.cheeseMakerIdle); } public void onBlockAdded(World world, int x, int y, int z) { super.onBlockAdded(world, x, y, z); this.setDefaultDirection(world, x, y, z); } private void setDefaultDirection(World world, int x, int y, int z) { if(!world.isRemote) { Block b1 = world.getBlock(x, y, z - 1); Block b2 = world.getBlock(x, y, z + 1); Block b3 = world.getBlock(x - 1, y, z); Block b4 = world.getBlock(x + 1, y, z); byte b0 = 3; if (b1.func_149730_j() && !b2.func_149730_j()) { b0 = 3; } if (b2.func_149730_j() && !b1.func_149730_j()) { b0 = 2; } if (b3.func_149730_j() && !b4.func_149730_j()) { b0 = 5; } if (b4.func_149730_j() && !b3.func_149730_j()) { b0 = 4; } world.setBlockMetadataWithNotify(x, y, z, b0, 2); } } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if(!world.isRemote) { FMLNetworkHandler.openGui(player, FancyCheeses.instance, FancyCheeses.guiCheeseMaker, world, x, y, z); } return true; } @Override public TileEntity createNewTileEntity(World world, int i) { return new TileEntityCheeseMaker(); } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityplayer, ItemStack itemstack) { int l = MathHelper.floor_double((double)(entityplayer.rotationYaw * 4.0F / 360.0F) + 0.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); } if(itemstack.hasDisplayName()) { ((TileEntityCheeseMaker)world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName()); } } public static void updateCheeseMakerBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord) { int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); TileEntity tileentity = worldObj.getTileEntity(xCoord, yCoord, zCoord); if(tileentity != null) { tileentity.validate(); worldObj.setTileEntity(xCoord, yCoord, zCoord, tileentity); } } public void breakBlock(World world, int x, int y, int z, Block oldblock, int oldMetadata) { if(!keepInventory) { TileEntityCheeseMaker tileentity = (TileEntityCheeseMaker) world.getTileEntity(x, y, z); if(tileentity != null) { for(int i = 0; i < tileentity.getSizeInventory(); i++) { ItemStack itemstack = tileentity.getStackInSlot(i); if(itemstack != null) { float f = this.rand.nextFloat() * 0.8F + 0.1F; float f1 = this.rand.nextFloat() * 0.8F + 0.1F; float f2 = this.rand.nextFloat() * 0.8F + 0.1F; while(itemstack.stackSize > 0) { int j = this.rand.nextInt(21) + 10; if(j > itemstack.stackSize) { j = itemstack.stackSize; } itemstack.stackSize -= j; EntityItem item = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage())); if(itemstack.hasTagCompound()) { item.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); } world.spawnEntityInWorld(item); } } } world.func_147453_f(x, y, z, oldblock); } } super.breakBlock(world, x, y, z, oldblock, oldMetadata); } public Item getItem(World world, int x, int y, int z) { return Item.getItemFromBlock(FancyCheeses.cheeseMakerIdle); } }
Container
package dudesmods.fancycheeses.container; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.Container; import net.minecraft.inventory.ICrafting; import net.minecraft.inventory.Slot; import net.minecraft.inventory.SlotFurnace; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.tileentity.TileEntityFurnace; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.inventory.CheeseMakerSlot; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; public class ContainerCheeseMaker extends Container { private TileEntityCheeseMaker cheeseMaker; public ContainerCheeseMaker(InventoryPlayer inventory, TileEntityCheeseMaker tileentity) { this.cheeseMaker = tileentity; this.addSlotToContainer(new CheeseMakerSlot(tileentity, 0, 8, 54, new Item[]{Items.bucket, Items.milk_bucket})); //Input 1 (Cow Milk?) this.addSlotToContainer(new CheeseMakerSlot(tileentity, 1, 133, 54, new Item[]{FancyCheeses.time_piece})); //Time Piece this.addSlotToContainer(new SlotFurnace(inventory.player, tileentity, 2, 133, 17)); //Output this.addSlotToContainer(new CheeseMakerSlot(tileentity, 3, 29, 54, new Item[]{Items.bucket, FancyCheeses.sheep_milk_bucket})); //Input 2 (Sheep Milk?) this.addSlotToContainer(new CheeseMakerSlot(tileentity, 4, 50, 54, new Item[]{Items.bucket, FancyCheeses.goat_milk_bucket})); //Input 3 (Goat Milk?) for(int i = 0; i < 3; i++) { for(int j = 0; j < 9; j++){ this.addSlotToContainer(new Slot(inventory, j + i*9 + 9, 8 + j*18, 84 + i * 18)); } } for(int i = 0; i < 9; i++) { this.addSlotToContainer(new Slot(inventory, i, 8 + i * 18, 142)); } } 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 == 2) { if (!this.mergeItemStack(itemstack1, 3, 39, true)) { return null; } slot.onSlotChange(itemstack1, itemstack); } else if (par2 != 1 && par2 != 0) { if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null) { if (!this.mergeItemStack(itemstack1, 0, 1, false)) { return null; } } else if (TileEntityFurnace.isItemFuel(itemstack1)) { if (!this.mergeItemStack(itemstack1, 1, 2, false)) { return null; } } else if (par2 >= 3 && par2 < 30) { if (!this.mergeItemStack(itemstack1, 30, 39, false)) { return null; } } else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false)) { return null; } } else if (!this.mergeItemStack(itemstack1, 3, 39, false)) { return null; } if (itemstack1.stackSize == 0) { slot.putStack((ItemStack)null); } else { slot.onSlotChanged(); } if (itemstack1.stackSize == itemstack.stackSize) { return null; } slot.onPickupFromSlot(par1EntityPlayer, itemstack1); } return itemstack; } @Override public boolean canInteractWith(EntityPlayer var1) { return true; } }
Custom Slot:
package dudesmods.fancycheeses.inventory; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class CheeseMakerSlot extends Slot { Item[] items; boolean shouldCheck; boolean valid; public CheeseMakerSlot(IInventory p_i1824_1_, int p_i1824_2_,int p_i1824_3_, int p_i1824_4_, Item[] validItems) { super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_); this.items = validItems; shouldCheck = true; } public CheeseMakerSlot(IInventory p_i1824_1_, int p_i1824_2_,int p_i1824_3_, int p_i1824_4_, boolean valid) { super(p_i1824_1_, p_i1824_2_, p_i1824_3_, p_i1824_4_); shouldCheck = true; this.valid = valid; } @Override public boolean isItemValid(ItemStack p_75214_1_) { if (shouldCheck){ int i; for(i=0;i<=(items.length)-1;i++) { if(p_75214_1_.getItem() == items[i]) { return true; } } return false; } else { return valid; } } }
GUI:
package dudesmods.fancycheeses.gui; import org.lwjgl.opengl.GL11; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.container.ContainerCheeseMaker; import dudesmods.fancycheeses.proxy.CheesingMessage; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; public class GuiCheeseMaker extends GuiContainer { public static final ResourceLocation bground = new ResourceLocation("fancycheeses", "textures/gui/GuiCheeseMaker.png"); public static final ResourceLocation goudaCheese = new ResourceLocation("fancycheeses", "textures/items/gouda_cheese_wheel.png"); public TileEntityCheeseMaker cheeseMaker; public static String error = "none"; public GuiCheeseMaker(InventoryPlayer inventoryPlayer, TileEntityCheeseMaker entity) { super(new ContainerCheeseMaker(inventoryPlayer, entity)); this.cheeseMaker = entity; this.xSize = 176; this.ySize = 166; } @Override public void initGui() { super.initGui(); this.buttonList.add(new GuiButton(0, guiLeft + 78, guiTop + 13, 10, 18, "<")); //Cheese Left this.buttonList.add(new GuiButton(1, guiLeft + 108, guiTop + 13, 10, 18, ">")); //Cheese Right this.buttonList.add(new GuiButton(2, guiLeft + 78, guiTop + 32, 40, 18, "Cheese")); //Cheese Make this.buttonList.add(new GuiButton(3, guiLeft + 78, guiTop + 50, 10, 18, "<")); //Time Left this.buttonList.add(new GuiButton(4, guiLeft + 108, guiTop + 50, 10, 18, ">")); //Time Right } @Override public void actionPerformed(GuiButton button) { switch(button.id) { case 0: //Cheese Left FancyCheeses.network.sendToServer(new CheesingMessage("cheeseleft", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; case 1: //Cheese Right FancyCheeses.network.sendToServer(new CheesingMessage("cheeseright", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; case 2: //Cheese Make FancyCheeses.network.sendToServer(new CheesingMessage("docheese", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; case 3: //Time Left FancyCheeses.network.sendToServer(new CheesingMessage("timeleft", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; case 4: //Time Right FancyCheeses.network.sendToServer(new CheesingMessage("timeright", cheeseMaker.xCoord, cheeseMaker.yCoord, cheeseMaker.zCoord)); break; default: break; } } public void drawGuiContainerForegroundLayer(int par1, int par2) { String name = this.cheeseMaker.hasCustomInventoryName() ? this.cheeseMaker.getInventoryName() : I18n.format(this.cheeseMaker.getInventoryName(), new Object[0]); this.fontRendererObj.drawString(name, (this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2) + 40, 4, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); this.fontRendererObj.drawString(cheeseMaker.cheeses[cheeseMaker.cheeseToMake], 95, 15, 4210752); //Debugging this.fontRendererObj.drawString(Integer.toString(cheeseMaker.timeAmounts[cheeseMaker.cheeseToMake][cheeseMaker.timeAmount]), 95, 55, 4210752); this.fontRendererObj.drawString(I18n.format("container.cheesemaker.error." + error, new Object[0]), 68, 72, 4210752); this.fontRendererObj.drawString(String.valueOf(cheeseMaker.cowMilkAmount), 13, 20, 4210752); this.fontRendererObj.drawString(String.valueOf(cheeseMaker.sheepMilkAmount), 34, 20, 4210752); this.fontRendererObj.drawString(String.valueOf(cheeseMaker.goatMilkAmount), 55, 20, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { guiDraw(bground); guiDrawLiquid("water", guiLeft + 8, guiTop + 33, cheeseMaker.cowMilkAmount, 50); //TODO:Cow Milk guiDrawLiquid("sheep_milk", guiLeft + 29, guiTop + 33, cheeseMaker.sheepMilkAmount, 50); //Sheep Milk guiDrawLiquid("goat_milk", guiLeft + 50, guiTop + 33, cheeseMaker.goatMilkAmount, 50); //Goat Milk if(cheeseMaker.cheeseToMake == 0) { guiDrawCheeseIcon(this.goudaCheese); } } protected void guiDraw(ResourceLocation var1) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(var1); this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); } protected void guiDrawCheeseIcon(ResourceLocation var1) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(var1); this.drawTexturedModalRect(guiLeft + 90, guiTop + 13, 0, 0, 16, 16); } protected void guiDrawLiquid(String fluidName, int x, int y, int fluidAmount, int fluidCapacity) { if(fluidAmount > 50) { fluidAmount = 50; System.out.println("ERROR: Cheese Maker conatins more " + fluidName + " than it possibly should!"); } Fluid fluid = FluidRegistry.getFluid(fluidName); Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); //RenderUtil.setIntColor3(fluid.getColor()); IIcon icon = fluid.getStillIcon(); double height = 1; height = fluidAmount; height = height / fluidCapacity; height = height * 100; height = height / 2.33; GL11.glEnable(GL11.GL_BLEND); this.drawTexturedModelRectFromIcon(x, (int) ((y - (20 * 65 / 50))), icon != null ? icon : fluid.getBlock().getIcon(0, 0), 16, (int) Math.round(height)); GL11.glDisable(GL11.GL_BLEND); } }
GUI Handler:
package dudesmods.fancycheeses.gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import cpw.mods.fml.common.network.IGuiHandler; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.container.ContainerCheeseMaker; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; public class GuiHandler implements IGuiHandler { @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch(ID) { case FancyCheeses.guiCheeseMaker: if(entity instanceof TileEntityCheeseMaker) { return new ContainerCheeseMaker(player.inventory, (TileEntityCheeseMaker) entity); } } } return null; } @Override public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { TileEntity entity = world.getTileEntity(x, y, z); if(entity != null) { switch(ID) { case FancyCheeses.guiCheeseMaker: if(entity instanceof TileEntityCheeseMaker) { return new GuiCheeseMaker(player.inventory, (TileEntityCheeseMaker) entity); } } } return null; } }
TileEntity:
package dudesmods.fancycheeses.tileentity; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import cpw.mods.fml.common.registry.GameRegistry; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.block.CheeseMaker; import dudesmods.fancycheeses.gui.GuiCheeseMaker; public class TileEntityCheeseMaker extends TileEntity implements ISidedInventory { private String localizedName; private static final int[] slots_top = new int[]{3, 4, 0}; private static final int[] slots_bottom = new int[]{2, 1}; private static final int[] slots_side = new int[]{1}; public ItemStack[] slots = new ItemStack [5]; public int cheeseToMake; public int cowMilkAmount; public int sheepMilkAmount; public int goatMilkAmount; public int timeAmount; public String[] cheeses = {"gouda", "", "", "", ""}; public Item[] itemCheeses = {FancyCheeses.gouda_cheese_wheel, FancyCheeses.time_piece, FancyCheeses.time_piece, FancyCheeses.time_piece, FancyCheeses.time_piece}; public int[][] timeAmounts = {new int[]{4, 48}, new int[]{40}, new int[]{40}, new int[]{40}, new int[]{40}}; public int[][] milkAmounts = {new int[]{10,0,0}, new int[]{0,0,0}, new int[]{0,0,0}, new int[]{0,0,0}, new int[]{0,0,0}}; public void setGuiDisplayName(String displayName) { this.localizedName = displayName; } public String getInventoryName() { return this.hasCustomInventoryName() ? this.localizedName : "container.cheesemaker"; } public boolean hasCustomInventoryName() { return this.localizedName != null && this.localizedName.length() > 0; } public int getSizeInventory() { return this.slots.length; } @Override public ItemStack getStackInSlot(int var1) { return this.slots[var1]; } @Override public ItemStack decrStackSize(int var1, int var2) { ItemStack itemstack = getStackInSlot(var1); if(this.slots[var1] != null) { if(this.slots[var1].stackSize <= var2 ){ itemstack = this.slots[var1]; this.slots[var1] = null; return itemstack; }else{ itemstack = this.slots[var1].splitStack(var2); if(this.slots[var1].stackSize == 0){ this.slots[var1] = null; } return itemstack; } }else { return itemstack; } } @Override public ItemStack getStackInSlotOnClosing(int var1) { if(this.slots[var1] != null) { ItemStack itemstack = this.slots[var1]; this.slots[var1] = null; return itemstack; } return null; } /** * Increases the counter specifying the cheese to make (output). */ public void incCheese() { if(this.cheeseToMake > 0) { this.cheeseToMake--; } this.markDirty(); } /** * Decreases the counter specifying the cheese to make (output). */ public void decCheese() { if(this.cheeseToMake < 4) { this.cheeseToMake++; } this.markDirty(); } /** * Increases the counter specifying the alternate aging amounts. */ public void incTime() { if(this.timeAmount > 0) { this.timeAmount--; } this.markDirty(); } /** * Decreases the counter specifying the alternate aging amounts. */ public void decTime() { if(this.timeAmount <(this.timeAmounts[this.cheeseToMake].length - 1)) { this.timeAmount++; } this.markDirty(); } /** * Checks to see if the item can be output, and outputs it. If not, tells the error. */ public void doCheese() { if(this.cowMilkAmount >= this.milkAmounts[this.cheeseToMake][0]) { if(this.sheepMilkAmount >= this.milkAmounts[this.cheeseToMake][1]) { if(this.goatMilkAmount >= this.milkAmounts[this.cheeseToMake][2]) { if(this.slots[1] != null && this.slots[1].getItem() == FancyCheeses.time_piece) { if((this.slots[1].getMaxDamage() - this.slots[1].getItemDamage()) >= this.timeAmounts[this.cheeseToMake][this.timeAmount]) { ItemStack itemstack = new ItemStack(this.itemCheeses[this.cheeseToMake], 1); if(this.slots[2] == null) { this.cowMilkAmount = this.cowMilkAmount - this.milkAmounts[this.cheeseToMake][0]; this.sheepMilkAmount = this.sheepMilkAmount - this.milkAmounts[this.cheeseToMake][1]; this.goatMilkAmount = this.goatMilkAmount - this.milkAmounts[this.cheeseToMake][2]; this.slots[1].attemptDamageItem(this.timeAmounts[this.cheeseToMake][this.timeAmount], new Random()); this.setInventorySlotContents(2, itemstack); } else if (this.slots[2].getItem() == this.itemCheeses[this.cheeseToMake]) { this.cowMilkAmount = this.cowMilkAmount - this.milkAmounts[this.cheeseToMake][0]; this.sheepMilkAmount = this.sheepMilkAmount - this.milkAmounts[this.cheeseToMake][1]; this.goatMilkAmount = this.goatMilkAmount - this.milkAmounts[this.cheeseToMake][2]; this.slots[1].attemptDamageItem(this.timeAmounts[this.cheeseToMake][this.timeAmount], new Random()); this.setInventorySlotContents(2, new ItemStack(this.itemCheeses[this.cheeseToMake], this.getStackInSlot(2).stackSize + 1)); } } else { GuiCheeseMaker.error = "timepiecedamage"; } } else { GuiCheeseMaker.error = "timepieceneed"; } } else { GuiCheeseMaker.error = "goatmilk"; } } else { GuiCheeseMaker.error = "sheepmilk"; } } else { GuiCheeseMaker.error = "cowmilk"; } this.markDirty(); } @Override public void setInventorySlotContents(int var1, ItemStack var2) { this.slots[var1] = var2; if(var2 != null && var2.stackSize > this.getInventoryStackLimit()) { var2.stackSize = this.getInventoryStackLimit(); } } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer var1) { return this.worldObj.getTileEntity(xCoord, yCoord, zCoord) != this ? false : var1.getDistanceSq((double)xCoord +0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64.0D; } @Override public void openInventory() { } @Override public void closeInventory() { } @Override public boolean isItemValidForSlot(int var1, ItemStack var2) { Item item = var2.getItem(); if(var1 == 0) { if(item == Items.bucket){return true;} else if(item == Items.milk_bucket){return true;} else{return false;} } else if(var1 == 1){ if(item == FancyCheeses.time_piece){return true;} else {return false;} } else if(var1 == 2) { return false; } else if(var1 == 3) { if(item == Items.bucket){return true;} else if(item == FancyCheeses.sheep_milk_bucket){return true;} else{return false;} } else if(var1 == 4) { if(item == Items.bucket){return true;} else if(item == FancyCheeses.goat_milk_bucket){return true;} else{return false;} } else { return false; } } public void updateEntity() { boolean flag1 = false; if(this.slots[0] != null) { if(this.slots[0].getItem() == Items.milk_bucket) { if(this.cowMilkAmount < 50) { this.slots[0] = new ItemStack(Items.bucket, 1); this.cowMilkAmount++; flag1 = true; } } } if(this.slots[3] != null) { if(this.slots[3].getItem() == FancyCheeses.sheep_milk_bucket) { if(this.sheepMilkAmount < 50) { this.slots[3] = new ItemStack(Items.bucket, 1); this.sheepMilkAmount++; flag1 = true; } } } if(this.slots[4] != null) { if(this.slots[4].getItem() == FancyCheeses.goat_milk_bucket) { if(this.goatMilkAmount < 50) { this.slots[4] = new ItemStack(Items.bucket, 1); this.goatMilkAmount++; flag1 = true; } } } if (flag1) { this.markDirty(); } } @Override public int[] getAccessibleSlotsFromSide(int var1) { return var1 == 0 ? slots_bottom : (var1 == 1 ? slots_top : slots_side); } @Override public boolean canInsertItem(int var1, ItemStack var2, int var3) { return this.isItemValidForSlot(var1, var2); } @Override public boolean canExtractItem(int var1, ItemStack var2, int var3) { //return var3 != 0 || var1 != 1 || var2.getItem() == Items.bucket; if(var1 == 0 || var1 == 3 || var1 == 4) { if(var2.getItem() == Items.bucket) { return true; } else { return false; } } else { return false; } } @Override public void readFromNBT(NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList list = nbt.getTagList("Items", 10); this.slots = new ItemStack[this.getSizeInventory()]; for(int i = 0; i < list.tagCount(); i++) { NBTTagCompound compound = (NBTTagCompound) list.getCompoundTagAt(i); byte b = compound.getByte("Slot"); if(b >= 0 && b < this.slots.length) { this.slots[b] = ItemStack.loadItemStackFromNBT(compound); } } this.cheeseToMake = (int)nbt.getShort("CheeseToMake"); this.cowMilkAmount = (int)nbt.getShort("CowMilkAmount"); this.sheepMilkAmount = (int)nbt.getShort("SheepMilkAmount"); this.goatMilkAmount = (int)nbt.getShort("GoatMilkAmount"); this.timeAmount = (int)nbt.getShort("TimeAmount"); if(nbt.hasKey("CustomName")) { this.localizedName = nbt.getString("CustomName"); } } @Override public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setShort("CheeseToMake", (short)this.cheeseToMake); nbt.setShort("CowMilkAmount", (short)this.cowMilkAmount); nbt.setShort("SheepMilkAmount", (short)this.sheepMilkAmount); nbt.setShort("GoatMilkAmount", (short)this.goatMilkAmount); nbt.setShort("TimeAmount", (short)this.timeAmount); NBTTagList list = new NBTTagList(); for(int i = 0; i< this.slots.length; i++) { if(this.slots[i] != null) { NBTTagCompound compound = new NBTTagCompound(); compound.setByte("Slot", (byte)i); this.slots[i].writeToNBT(compound); list.appendTag(compound); } } nbt.setTag("Items", list); if(this.hasCustomInventoryName()) { nbt.setString("CustomName", this.localizedName); } } }
IMessage Class:
package dudesmods.fancycheeses.proxy; import net.minecraft.world.World; import io.netty.buffer.ByteBuf; import cpw.mods.fml.common.network.ByteBufUtils; import cpw.mods.fml.common.network.simpleimpl.IMessage; import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; import cpw.mods.fml.common.network.simpleimpl.MessageContext; import dudesmods.fancycheeses.FancyCheeses; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; public class CheesingMessage implements IMessage { private String text; private static int x,y,z; public CheesingMessage() { } public CheesingMessage(String text) { this.text = text; } public CheesingMessage(String text, int x, int y, int z) { this.text = text; this.x = x; this.y = y; this.z = z; } @Override public void fromBytes(ByteBuf buf) { text = ByteBufUtils.readUTF8String(buf); // this class is very useful in general for writing more complex objects } @Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, text); } public static class Handler implements IMessageHandler<CheesingMessage, IMessage> { @Override public IMessage onMessage(CheesingMessage message, MessageContext ctx) { System.out.println(String.format("Received %s from %s", message.text, ctx.getServerHandler().playerEntity.getDisplayName())); World world = ctx.getServerHandler().playerEntity.worldObj; TileEntityCheeseMaker cheeseMaker = (TileEntityCheeseMaker) world.getTileEntity(x, y, z); if(message.text.startsWith("docheese")) { cheeseMaker.doCheese(); } else if (message.text.startsWith("cheeseleft")) { cheeseMaker.decCheese(); } else if (message.text.startsWith("cheeseright")) { cheeseMaker.incCheese(); } else if (message.text.startsWith("timeleft")) { cheeseMaker.decTime(); }else if (message.text.startsWith("timeright")) { cheeseMaker.incTime(); } return null; // no response in this case } } }
stuff from main class:
//... @EventHandler public void preInit(FMLPreInitializationEvent event) { //... network = NetworkRegistry.INSTANCE.newSimpleChannel("MyChannel"); network.registerMessage(CheesingMessage.Handler.class, CheesingMessage.class, 0, Side.SERVER); //... } @EventHandler public void init(FMLInitializationEvent event) { //... NetworkRegistry.INSTANCE.registerGuiHandler(this, new GuiHandler()); GameRegistry.registerTileEntity(TileEntityCheeseMaker.class, "CheeseMaker"); //... } //...
-
I know i'd do:
this.slots[1].damageItem(amount, /*?*/);
but I need the "/*?*/" bit. It needs an EntityLivingBase and I don't thinka TileEntity counts and I don't know how to get a player server-side.
-
Where are you calling your changes? That is the key.
The function is being called when a button on the GUI is pressed.
-
You are chainging slot contents client-side. Make sure to do that on server, it's the server that holds data, client is only a vessel.
What methods do I need to change it server-side?
-
When I use setInventorySlotContents to set a slot to an item the item disappears when removing it from the slot.
@Override public void setInventorySlotContents(int var1, ItemStack var2) { this.slots[var1] = var2; if(var2 != null && var2.stackSize > this.getInventoryStackLimit()) { var2.stackSize = this.getInventoryStackLimit(); } }
-
EDIT:Solved by calling "super.initGui();" in my initGUi();
Before adding my buttons, my GUI appears as such:
After adding buttons, it appears as this:
(also there's that weird brown thing on the gui aswell. Plus it seems to break NEI.)
My GUI class (with the buttons added):
package dudesmods.fancycheeses.gui; import org.lwjgl.opengl.GL11; import dudesmods.fancycheeses.container.ContainerCheeseMaker; import dudesmods.fancycheeses.tileentity.TileEntityCheeseMaker; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.texture.TextureMap; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.IIcon; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; public class GuiCheeseMaker extends GuiContainer { public static final ResourceLocation bground = new ResourceLocation("fancycheeses", "textures/gui/GuiCheeseMaker.png"); public TileEntityCheeseMaker cheeseMaker; public GuiCheeseMaker(InventoryPlayer inventoryPlayer, TileEntityCheeseMaker entity) { super(new ContainerCheeseMaker(inventoryPlayer, entity)); this.cheeseMaker = entity; this.xSize = 176; this.ySize = 166; } @Override public void initGui() { this.buttonList.add(new GuiButton(0, 70, 20, 10, 14, "<")); this.buttonList.add(new GuiButton(1, 98, 20, 10, 14, ">")); } @Override public void actionPerformed(GuiButton button) { switch(button.id) { case 0: if(cheeseMaker.cheeseToMake > 0) { cheeseMaker.cheeseToMake--; } break; case 1: if(cheeseMaker.cheeseToMake < 4) { cheeseMaker.cheeseToMake++; } break; default: break; } } public void drawGuiContainerForegroundLayer(int par1, int par2) { String name = this.cheeseMaker.hasCustomInventoryName() ? this.cheeseMaker.getInventoryName() : I18n.format(this.cheeseMaker.getInventoryName(), new Object[0]); this.fontRendererObj.drawString(name, (this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2) + 40, 4, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); } @Override protected void drawGuiContainerBackgroundLayer(float var1, int var2, int var3) { guiDraw(bground); guiDrawLiquid("sheep_milk", guiLeft + 29, guiTop + 33, 20, 50); guiDrawLiquid("goat_milk", guiLeft + 50, guiTop + 33, 20, 50); //TODO : Might re-use this stuff? /* //Flames if(this.cheeseMaker.isBurning()) { int k = this.cheeseMaker.getBurnTimeRemainingScaled(12); int j = 40 - k; this.drawTexturedModalRect(guiLeft + 26, guiTop + 50 + 12 - k, 176, 12 - k, 14, k + 2); } //Progress Arrow int k = this.cheeseMaker.getCookProgressScaled(24); this.drawTexturedModalRect(guiLeft + 95, guiTop + 18, 176, 14, k + 1, 16); */ } protected void guiDraw(ResourceLocation var1) { GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); Minecraft.getMinecraft().getTextureManager().bindTexture(var1); this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize); } protected void guiDrawLiquid(String fluidName, int x, int y, int fluidAmount, int fluidCapacity) { if(fluidAmount > 50) { fluidAmount = 50; System.out.println("ERROR: Cheese Maker conatins more " + fluidName + " than it possibly should!"); } Fluid fluid = FluidRegistry.getFluid(fluidName); Minecraft.getMinecraft().getTextureManager().bindTexture(TextureMap.locationBlocksTexture); //RenderUtil.setIntColor3(fluid.getColor()); IIcon icon = fluid.getStillIcon(); double height = 1; height = fluidAmount; height = height / fluidCapacity; height = height * 100; height = height / 2.33; GL11.glEnable(GL11.GL_BLEND); this.drawTexturedModelRectFromIcon(x, (int) ((y - (20 * 65 / 50))), icon != null ? icon : fluid.getBlock().getIcon(0, 0), 16, (int) Math.round(height)); GL11.glDisable(GL11.GL_BLEND); } }
-
Override
public boolean interact(EntityPlayer p_70085_1_)
in your entity. check that the player is holding a bucket, then do stuff.
What about a vanilla mob?
-
How would I make it so that a bucket gets filled with a fluid by right-clicking on a mob?
[1.10.2] Getting a long from player's nbt and displaying in a gui?
in Modder Support
Posted
Currently using the following code:
It always displays as 0. I know I am using the correct key for the long because I have added a chat command that checks it and it is returning the proper value.