Jump to content

cclloyd9785

Members
  • Posts

    23
  • Joined

  • Last visited

Converted

  • Gender
    Undisclosed
  • Personal Text
    I am new!

cclloyd9785's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Do you have any info on implementing IRecipe? I can't find any useful information anywhere.
  2. I want to make it so that you can craft any potion with any piece of my custom armor (8 variants from 1 class) and create a new instance of the armor based on the item in the crafting inventory. I want them to be able to craft any of the 8 possible variants of armor with any vanilla potion and have the recipe output be a new ItemStack using the potion constructor. But how would I get which potion is in the crafting? Default constructor for armor: public ItemArmorObsidian(int type, boolean reinforced) { super(ItemRegistry.armorObsidianReinforced, 0, type); this.reinforced = reinforced; this.type = type; setName(type, reinforced); } Constructor when potion available: public ItemArmorObsidian(int type, boolean reinforced, Potion potion) { super(ItemRegistry.armorObsidianReinforced, 0, type); this.type = type; this.reinforced = reinforced; this.potion = potion; setName(type, reinforced); }
  3. It helped a little bit but I figured it out. I didn't need to define the textures one at a time by copying the vanilla json, I just needed to have the json be a child of the vanilla block. blockCleanGlassPane_n { "parent": "block/pane_n", "textures": { "edge": "ccmodpack:blocks/blockCleanGlass", "pane": "ccmodpack:blocks/blockCleanGlass" } }
  4. It renders in the inventory fine but not in the world. (I only have nsew for now just to try and make it work) It also renders the correct shape and bounds of glass panels, just with the default texture. BlockCleanGlassPane.java package com.cclloyd.ccmodpack.block; import net.minecraft.block.Block; import net.minecraft.block.BlockPane; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockState; import net.minecraft.block.state.IBlockState; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.world.IBlockAccess; import com.cclloyd.ccmodpack.CCModpack; import com.cclloyd.ccmodpack.registry.BlockRegistry; public class BlockCleanGlassPane extends BlockPane { public static final String name = "blockCleanGlassPane"; private boolean ignoreSimilarity = true; public BlockCleanGlassPane() { super(Material.glass, true); setUnlocalizedName(CCModpack.MODID + "_" + name); setHardness(0.3F); setResistance(1.5F); } @Override public boolean shouldSideBeRendered(IBlockAccess worldIn, BlockPos pos, EnumFacing side) { IBlockState iblockstate = worldIn.getBlockState(pos); Block block = iblockstate.getBlock(); if (this == BlockRegistry.cleanGlass || this == BlockRegistry.cleanGlassPane) { if (worldIn.getBlockState(pos.offset(side.getOpposite())) != iblockstate) return true; if (block == this) return false; } return !this.ignoreSimilarity && block == this ? false : super.shouldSideBeRendered(worldIn, pos, side); } } blockstate blockCleanGlassPane.json: { "variants": { "east=false,north=false,south=false,west=false": { "model": "ccmodpack:blockCleanGlassPane_nsew" }, "east=false,north=true,south=false,west=false": { "model": "ccmodpack:blockCleanGlassPane_n" }, "east=true,north=false,south=false,west=false": { "model": "ccmodpack:blockCleanGlassPane_n", "y": 90 }, "east=false,north=false,south=true,west=false": { "model": "ccmodpack:blockCleanGlassPane_n", "y": 180 }, "east=false,north=false,south=false,west=true": { "model": "ccmodpack:blockCleanGlassPane_n", "y": 270 }, "east=true,north=true,south=false,west=false": { "model": "ccmodpack:blockCleanGlassPane_ne" }, "east=true,north=false,south=true,west=false": { "model": "ccmodpack:blockCleanGlassPane_ne", "y": 90 }, "east=false,north=false,south=true,west=true": { "model": "ccmodpack:blockCleanGlassPane_ne", "y": 180 }, "east=false,north=true,south=false,west=true": { "model": "ccmodpack:blockCleanGlassPane_ne", "y": 270 }, "east=false,north=true,south=true,west=false": { "model": "ccmodpack:blockCleanGlassPane_ns" }, "east=true,north=false,south=false,west=true": { "model": "ccmodpack:blockCleanGlassPane_ns", "y": 90 }, "east=true,north=true,south=true,west=false": { "model": "ccmodpack:blockCleanGlassPane_nse" }, "east=true,north=false,south=true,west=true": { "model": "ccmodpack:blockCleanGlassPane_nse", "y": 90 }, "east=false,north=true,south=true,west=true": { "model": "ccmodpack:blockCleanGlassPane_nse", "y": 180 }, "east=true,north=true,south=false,west=true": { "model": "ccmodpack:blockCleanGlassPane_nse", "y": 270 }, "east=true,north=true,south=true,west=true": { "model": "ccmodpack:blockCleanGlassPane_nsew" } } } model/block blockCleanGlassPane_nsew { "ambientocclusion": false, "textures": { "particle": "ccmodpack:blocks/blockCleanGlass" }, "elements": [ { "from": [ 7, 0, 0 ], "to": [ 9, 16, 16 ], "shade": false, "faces": { "down": { "uv": [ 7, 0, 9, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass" }, "up": { "uv": [ 7, 0, 9, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass" }, "north": { "uv": [ 7, 0, 9, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass", "cullface": "north" }, "south": { "uv": [ 7, 0, 9, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass", "cullface": "south" }, "west": { "uv": [ 0, 0, 16, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass" }, "east": { "uv": [ 0, 0, 16, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass" } } }, { "from": [ 0, 0, 7 ], "to": [ 16, 16, 9 ], "shade": false, "faces": { "down": { "uv": [ 7, 0, 9, 16 ], "rotation": 90, "texture": "ccmodpack:blocks/blockCleanGlass" }, "up": { "uv": [ 7, 0, 9, 16 ], "rotation": 90, "texture": "ccmodpack:blocks/blockCleanGlass" }, "north": { "uv": [ 0, 0, 16, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass" }, "south": { "uv": [ 0, 0, 16, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass" }, "west": { "uv": [ 7, 0, 9, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass", "cullface": "west" }, "east": { "uv": [ 7, 0, 9, 16 ], "texture": "ccmodpack:blocks/blockCleanGlass", "cullface": "east" } } } ] }
  5. Checked the .jar file to make sure it was packing correctly. And I found out that it was capitalizing the json files of the other hammers to ItemToolHammerX. So that's what the issue was. So I ran gradle clean then gradle build and it worked.
  6. I have a custom tool that is rendering in the development environment, but when I publish it and run it on real minecraft with the same forge version only the diamond one registers. It says in the game output [Client thread/ERROR] [FML]: Model definition for location ccmodpack:itemToolHammerIron#inventory not found For all but the diamond hammer. And I can't figure out why. Code: https://github.com/cclloyd/CCModpack/tree/master/src/main
  7. Not sure why, but my custom tool isn't rendering at all. Not sure what's wrong. Render statement: ItemModelMesher renderItem = Minecraft.getMinecraft().getRenderItem().getItemModelMesher(); public static ItemToolHammerDiamond itemToolHammerDiamond = new ItemToolHammerDiamond(); renderItem.register(itemToolHammerDiamond, 0, new ModelResourceLocation(CCModpack.MODID + ":" + ItemToolHammerDiamond.name, "inventory")); Hammer Base: package com.cclloyd.ccmodpack.itemtool; import java.util.Set; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemTool; import net.minecraft.util.BlockPos; import net.minecraft.world.World; import com.cclloyd.ccmodpack.BlockRegistry; import com.google.common.collect.Sets; public class ItemToolHammer extends ItemTool { public static final String name = "itemToolHammer"; static float attackDamage; static ToolMaterial material; @SuppressWarnings("rawtypes") static Set effectiveBlocks = Sets.newHashSet(new Block[] {Blocks.stone, Blocks.sand, Blocks.cobblestone, Blocks.brick_block}); public ItemToolHammer(float attackDamage, ToolMaterial material) { super(attackDamage, material, effectiveBlocks); final int WOOD_HARDNESS_LEVEL = 0; final int STONE_HARDNESS_LEVEL = 1; this.setHarvestLevel("axe", WOOD_HARDNESS_LEVEL); this.setHarvestLevel("pickaxe", STONE_HARDNESS_LEVEL); } @Override public float getStrVsBlock(ItemStack stack, Block block) { Float result = super.getStrVsBlock(stack, block); return result; } @Override public float getDigSpeed(ItemStack stack, IBlockState state) { Float result = super.getDigSpeed(stack, state); return result; } @Override public boolean onBlockStartBreak(ItemStack itemstack, BlockPos pos, EntityPlayer player) { Boolean result = true; result = super.onBlockStartBreak(itemstack, pos, player); return result; } @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn) { Boolean result = true; if(!worldIn.isRemote) { // Stone/Cobblestone > Gravel if (blockIn == Blocks.stone) spawnDifferentBlock(Blocks.gravel, worldIn, pos); else if (blockIn == Blocks.cobblestone) spawnDifferentBlock(Blocks.gravel, worldIn, pos); // Gravel > Sand else if (blockIn == Blocks.gravel) spawnDifferentBlock(Blocks.sand, worldIn, pos); // Sand > Dust else if (blockIn == Blocks.sand) spawnDifferentBlock(BlockRegistry.blockDust, worldIn, pos); // Brick Block > Bricks else if (blockIn == Blocks.brick_block) spawnDifferentBlockMulti(Items.brick, 4, worldIn, pos); // Stone brick > Cracked Stone Brick else if (blockIn == Blocks.stonebrick) spawnDifferentBlockMeta(Blocks.stonebrick, 2, worldIn, pos); // Netherrack > Soul Sand else if (blockIn == Blocks.netherrack) spawnDifferentBlock(Blocks.soul_sand, worldIn, pos); // Redstone block > redstone else if (blockIn == Blocks.redstone_block) spawnDifferentBlockMulti(Items.redstone, 9, worldIn, pos); // Lapis block > lapis else if (blockIn == Blocks.lapis_block) spawnDifferentBlockMultiMeta(Items.dye, 9, 4, worldIn, pos); // No special case else result = super.onBlockDestroyed(stack, worldIn, blockIn, pos, playerIn); } else result = super.onBlockDestroyed(stack, worldIn, blockIn, pos, playerIn); return result; } } Diamond Hammer: package com.cclloyd.ccmodpack.itemtool; import com.cclloyd.ccmodpack.CCModpack; public class ItemToolHammerDiamond extends ItemToolHammer { public static final String name = "itemToolHammerDiamond"; public static float attackDamage = 5.0F; public static ToolMaterial material = ToolMaterial.EMERALD; public ItemToolHammerDiamond() { super(attackDamage, material); setUnlocalizedName(CCModpack.MODID + "_" + name); } } assets/modid/models/item/itemToolHammerDiamond.json { "parent": "builtin/generated", "textures": { "layer0": "ccmodpack:items/itemToolHammerDiamond" }, "display": { "thirdperson": { "rotation": [ 0, 90, -35 ], "translation": [ 0, 1.25, -3.5 ], "scale": [ 0.85, 0.85, 0.85 ] }, "firstperson": { "rotation": [ 0, -135, 25 ], "translation": [ 0, 4, 2 ], "scale": [ 1.7, 1.7, 1.7 ] } } } And there's the png in textures/items/itemToolHammerDiamond.png
  8. I have a custom tool that is supposed to drop different items depending on the block destroyed, so I have the override method below. The issue I'm having is when I break a block of stone it drops 2 sand blocks as items, but you can only pickup 1 (1 of them doesn't actually exist). How can I make it only drop 1 sand? @Override public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn) { Boolean result = true; if (blockIn == Blocks.stone) { worldIn.spawnEntityInWorld(new EntityItem(worldIn, pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D, new ItemStack(Blocks.sand, 1))); worldIn.destroyBlock(pos, false); } else { result = super.onBlockDestroyed(stack, worldIn, blockIn, pos, playerIn); } return result; }
  9. I was looking at WorldSavedData and it seemed like it doesn't do what I want it to do exactly. It's more like is there a NBT tag associated with the map itself that I can access?
  10. Well I was going to modify the string to be MCDIR/saves/worldObj.getWorldInfo.getWorldName()/ but is there a simpler way to get the path of that?
  11. To save data not associated with any block/part of the map, I will have to write to a file, unless there is a way to do that. (Namely save ItemStacks not tied to a block/entity, and some custom datatypes).
  12. I want to be able to get the absolute path of the Minecraft directory. I tried Minecraft.getMinecraft().mcDataDir.getPath()); But it just returns a period. How can I get the path of Minecraft?
  13. So what I currently have is Entity: package com.cclloyd.ccmodpack; import java.util.Arrays; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ChatComponentText; import net.minecraft.util.ChatComponentTranslation; import net.minecraft.util.IChatComponent; public class WirelessChestEntity extends TileEntity implements IInventory { /** * This is a simple tile entity implementing IInventory that can store 9 item stacks */ // Create and initialize the items variable that will store store the items final int NUMBER_OF_SLOTS = 27; private ItemStack[] itemStacks = new ItemStack[NUMBER_OF_SLOTS]; private int frequency = 0; public final static String name = "wirelessChestEntity"; public WirelessChestEntity() { this.frequency = 0; } public int getFreq() { return this.frequency; } public String getFreqStr() { return Integer.toString(this.frequency); } public void setFreq(int freq) { this.frequency = freq; markDirty(); } /* The following are some IInventory methods you are required to override */ // Gets the number of slots in the inventory @Override public int getSizeInventory() { return itemStacks.length; } // Gets the stack in the given slot @Override public ItemStack getStackInSlot(int slotIndex) { return itemStacks[slotIndex]; } /** * Removes some of the units from itemstack in the given slot, and returns as a separate itemstack * @param slotIndex the slot number to remove the items from * @param count the number of units to remove * @return a new itemstack containing the units removed from the slot */ @Override public ItemStack decrStackSize(int slotIndex, int count) { ItemStack itemStackInSlot = getStackInSlot(slotIndex); if (itemStackInSlot == null) return null; ItemStack itemStackRemoved; if (itemStackInSlot.stackSize <= count) { itemStackRemoved = itemStackInSlot; setInventorySlotContents(slotIndex, null); } else { itemStackRemoved = itemStackInSlot.splitStack(count); if (itemStackInSlot.stackSize == 0) { setInventorySlotContents(slotIndex, null); } } markDirty(); return itemStackRemoved; } // overwrites the stack in the given slotIndex with the given stack @Override public void setInventorySlotContents(int slotIndex, ItemStack itemstack) { itemStacks[slotIndex] = itemstack; if (itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); } markDirty(); } // This is the maximum number if items allowed in each slot // This only affects things such as hoppers trying to insert items you need to use the container to enforce this for players // inserting items via the gui @Override public int getInventoryStackLimit() { return 64; } // Return true if the given player is able to use this block. In this case it checks that // 1) the world tileentity hasn't been replaced in the meantime, and // 2) the player isn't too far away from the centre of the block @Override public boolean isUseableByPlayer(EntityPlayer player) { if (this.worldObj.getTileEntity(this.pos) != this) return false; final double X_CENTRE_OFFSET = 0.5; final double Y_CENTRE_OFFSET = 0.5; final double Z_CENTRE_OFFSET = 0.5; final double MAXIMUM_DISTANCE_SQ = 8.0 * 8.0; return player.getDistanceSq(pos.getX() + X_CENTRE_OFFSET, pos.getY() + Y_CENTRE_OFFSET, pos.getZ() + Z_CENTRE_OFFSET) < MAXIMUM_DISTANCE_SQ; } // Return true if the given stack is allowed to go in the given slot. In this case, we can insert anything. // This only affects things such as hoppers trying to insert items you need to use the container to enforce this for players // inserting items via the gui @Override public boolean isItemValidForSlot(int slotIndex, ItemStack itemstack) { return true; } // This is where you save any data that you don't want to lose when the tile entity unloads // In this case, it saves the itemstacks stored in the container @Override public void writeToNBT(NBTTagCompound parentNBTTagCompound) { super.writeToNBT(parentNBTTagCompound); // The super call is required to save and load the tileEntity's location // to use an analogy with Java, this code generates an array of hashmaps // The itemStack in each slot is converted to an NBTTagCompound, which is effectively a hashmap of key->value pairs such // as slot=1, id=2353, count=1, etc // Each of these NBTTagCompound are then inserted into NBTTagList, which is similar to an array. parentNBTTagCompound.setInteger("ChestFrequency", this.frequency); NBTTagList dataForAllSlots = new NBTTagList(); for (int i = 0; i < this.itemStacks.length; ++i) { if (this.itemStacks[i] != null) { NBTTagCompound dataForThisSlot = new NBTTagCompound(); dataForThisSlot.setByte("Slot", (byte) i); this.itemStacks[i].writeToNBT(dataForThisSlot); dataForAllSlots.appendTag(dataForThisSlot); } } parentNBTTagCompound.setTag("Items", dataForAllSlots); } // This is where you load the data that you saved in writeToNBT @Override public void readFromNBT(NBTTagCompound parentNBTTagCompound) { super.readFromNBT(parentNBTTagCompound); // The super call is required to save and load the tiles location final byte NBT_TYPE_COMPOUND = 10; // See NBTBase.createNewByType() for a listing NBTTagList dataForAllSlots = parentNBTTagCompound.getTagList("Items", NBT_TYPE_COMPOUND); this.frequency = parentNBTTagCompound.getInteger("ChestFrequency"); Arrays.fill(itemStacks, null); // set all slots to empty for (int i = 0; i < dataForAllSlots.tagCount(); ++i) { NBTTagCompound dataForOneSlot = dataForAllSlots.getCompoundTagAt(i); int slotIndex = dataForOneSlot.getByte("Slot") & 255; if (slotIndex >= 0 && slotIndex < this.itemStacks.length) { this.itemStacks[slotIndex] = ItemStack.loadItemStackFromNBT(dataForOneSlot); } } } // set all slots to empty @Override public void clear() { Arrays.fill(itemStacks, null); } // will add a key for this container to the lang file so we can name it in the GUI @Override public String getName() { return "container.wirelessChestEntity.name"; } @Override public boolean hasCustomName() { return false; } // standard code to look up what the human-readable name is @Override public IChatComponent getDisplayName() { return this.hasCustomName() ? new ChatComponentText(this.getName()) : new ChatComponentTranslation(this.getName()); } // ----------------------------------------------------------------------------------------------------------- // The following methods are not needed for this example but are part of IInventory so they must be implemented /** * This method removes the entire contents of the given slot and returns it. * Used by containers such as crafting tables which return any items in their slots when you close the GUI * @param slotIndex * @return */ @Override public ItemStack getStackInSlotOnClosing(int slotIndex) { ItemStack itemStack = getStackInSlot(slotIndex); if (itemStack != null) setInventorySlotContents(slotIndex, null); return itemStack; } @Override public void openInventory(EntityPlayer player) {} @Override public void closeInventory(EntityPlayer player) {} @Override public int getField(int id) { return 0; } @Override public void setField(int id, int value) { if (id == 9000) this.frequency = value; } @Override public int getFieldCount() { return 0; } /* @Override public String getGuiId() { return CCModpack.MODID + "_" + WirelessChest.name; }*/ } Container: package com.cclloyd.ccmodpack; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; public class WirelessChestContainer extends Container { /** * The container is used to link the client side gui to the server side inventory and it is where * you add the slots to your gui. It can also be used to sync server side data with the client but * that will be covered in a later tutorial */ // Stores a reference to the tile entity instance for later use public WirelessChestEntity wirelessChestEntity; // must assign a slot number to each of the slots used by the GUI. // For this container, we can see both the tile inventory's slots as well as the player inventory slots and the hotbar. // Each time we add a Slot to the container, it automatically increases the slotIndex, which means // 0 - 8 = hotbar slots (which will map to the InventoryPlayer slot numbers 0 - // 9 - 35 = player inventory slots (which map to the InventoryPlayer slot numbers 9 - 35) // 36 - 44 = TileInventory slots, which map to our TileEntity slot numbers 0 - private final int HOTBAR_COUNT = 9; private final int PLAYER_ROWS = 3; private final int PLAYER_COLUMNS = 9; private final int PLAYER_SLOTS = PLAYER_COLUMNS * PLAYER_ROWS; private final int VANILLA_SLOTS = HOTBAR_COUNT + PLAYER_SLOTS; private final int VANILLA_START = 0; private final int TE_START = VANILLA_START + VANILLA_SLOTS; private final int TE_ROWS = 3; private final int TE_COLUMNS = 9; private final int TE_SLOTS = TE_ROWS * TE_COLUMNS; public void setFreq(int frequency) { this.wirelessChestEntity.setFreq(frequency); } public int getFreq() { return this.wirelessChestEntity.getFreq(); } public String freqStr() { return this.wirelessChestEntity.getFreqStr(); } public WirelessChestContainer(InventoryPlayer invPlayer, WirelessChestEntity wirelessChestEntity) { this.wirelessChestEntity = wirelessChestEntity; // Adds all the slots for items final int SLOT_X_SPACING = 18; final int SLOT_Y_SPACING = 18; final int HOTBAR_XPOS = 8; final int HOTBAR_YPOS = 164; final int PLAYER_XPOS = 8; final int PLAYER_YPOS = 106; final int TE_XPOS = 8; final int TE_YPOS = 48; // Add the players hotbar to the gui - the [xpos, ypos] location of each item for (int x = 0; x < HOTBAR_COUNT; x++) { int slotNumber = x; addSlotToContainer(new Slot(invPlayer, slotNumber, HOTBAR_XPOS + SLOT_X_SPACING * x, HOTBAR_YPOS)); } // Add the rest of the players inventory to the gui for (int y = 0; y < PLAYER_ROWS; y++) { for (int x = 0; x < PLAYER_COLUMNS; x++) { int slotNumber = HOTBAR_COUNT + y * PLAYER_COLUMNS + x; int xpos = PLAYER_XPOS + x * SLOT_X_SPACING; int ypos = PLAYER_YPOS + y * SLOT_Y_SPACING; addSlotToContainer(new Slot(invPlayer, slotNumber, xpos, ypos)); } } if (TE_SLOTS != wirelessChestEntity.getSizeInventory()) { System.err.println("Mismatched slot count in ContainerBasic(" + TE_SLOTS + ") and TileInventory (" + wirelessChestEntity.getSizeInventory()+")"); } // Add the tile inventory container to the gui for (int y = 0; y < TE_ROWS; y++) { for (int x = 0; x < TE_COLUMNS; x++) { int slotNumber = (y * HOTBAR_COUNT) + x; int xpos = TE_XPOS + (x * SLOT_X_SPACING); int ypos = TE_YPOS + (y * SLOT_Y_SPACING); addSlotToContainer(new Slot(wirelessChestEntity, slotNumber, xpos, ypos)); } } } // Vanilla calls this method every tick to make sure the player is still able to access the inventory, and if not closes the gui @Override public boolean canInteractWith(EntityPlayer player) { return wirelessChestEntity.isUseableByPlayer(player); } // This is where you specify what happens when a player shift clicks a slot in the gui // (when you shift click a slot in the TileEntity Inventory, it moves it to the first available position in the hotbar and/or // player inventory. When you you shift-click a hotbar or player inventory item, it moves it to the first available // position in the TileEntity inventory) // At the very least you must override this and return null or the game will crash when the player shift clicks a slot // returns null if the source slot is empty, or if none of the the source slot items could be moved // otherwise, returns a copy of the source stack @Override public ItemStack transferStackInSlot(EntityPlayer player, int sourceSlotIndex) { Slot sourceSlot = (Slot)inventorySlots.get(sourceSlotIndex); if (sourceSlot == null || !sourceSlot.getHasStack()) return null; ItemStack sourceStack = sourceSlot.getStack(); ItemStack copyOfSourceStack = sourceStack.copy(); // Check if the slot clicked is one of the vanilla container slots if (sourceSlotIndex >= VANILLA_START && sourceSlotIndex < VANILLA_START + VANILLA_SLOTS) { // This is a vanilla container slot so merge the stack into the tile inventory if (!mergeItemStack(sourceStack, TE_START, TE_START + TE_SLOTS, false)){ return null; } } else if (sourceSlotIndex >= TE_START && sourceSlotIndex < TE_START + TE_SLOTS) { // This is a TE slot so merge the stack into the players inventory if (!mergeItemStack(sourceStack, VANILLA_START, VANILLA_START + VANILLA_SLOTS, false)) { return null; } } else { System.err.print("Invalid slotIndex:" + sourceSlotIndex); return null; } // If stack size == 0 (the entire stack was moved) set slot contents to null if (sourceStack.stackSize == 0) { sourceSlot.putStack(null); } else { sourceSlot.onSlotChanged(); } sourceSlot.onPickupFromSlot(player, sourceStack); return copyOfSourceStack; } // pass the close container message to the tileEntityInventory (not strictly needed for this example) // see ContainerChest and TileEntityChest @Override public void onContainerClosed(EntityPlayer playerIn) { super.onContainerClosed(playerIn); this.wirelessChestEntity.closeInventory(playerIn); } @Override public boolean enchantItem(EntityPlayer player, int action) { this.wirelessChestEntity.setFreq(action); return super.enchantItem(player, action); } } GuiContainer: package com.cclloyd.ccmodpack; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @SideOnly(Side.CLIENT) public class WirelessChestGuiContainer extends GuiContainer { /** * GuiInventoryBasic is a simple gui that does nothing but draw a background image and a line of text on the screen * everything else is handled by the vanilla container code */ private static final ResourceLocation texture = new ResourceLocation("ccmodpack", "textures/gui/container/wirelessChest.png"); private WirelessChestEntity wirelessChestEntity; private WirelessChestContainer container; public WirelessChestGuiContainer(InventoryPlayer invPlayer, WirelessChestEntity tile) { super(new WirelessChestContainer(invPlayer, tile)); wirelessChestEntity = tile; // Set the width and height of the gui. Should match the size of the texture! xSize = 176; ySize = 184; this.xSize = 176; this.ySize = 184; this.container = (WirelessChestContainer)this.inventorySlots; } public Container getContainer() { return null; } // draw the background for the GUI - rendered first @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int x, int y) { // Bind the image texture of our custom container Minecraft.getMinecraft().getTextureManager().bindTexture(texture); // Draw the image GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize); } // draw the foreground for the GUI - rendered after the slots, but before the dragged items and tooltips // renders relative to the top left corner of the background @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { //final int LABEL_XPOS = this.xSize / 2 - 10; //final int LABEL_YPOS = 5; //this.guiLeft = (this.width - this.xSize) / 2; //this.guiTop = (this.height - this.ySize) / 2; //int posX = this.guiLeft; //int posY = this.guiTop; //int center = this.xSize / 2 + this.guiLeft; //fontRendererObj.drawString("0000", this.guiLeft / 2, 4, Color.darkGray.getRGB()); } @SuppressWarnings("unchecked") public void initGui() { super.initGui(); this.mc.thePlayer.openContainer = this.inventorySlots; this.guiLeft = (this.width - this.xSize) / 2; this.guiTop = (this.height - this.ySize) / 2; int posX = this.guiLeft; int posY = this.guiTop; int center = this.xSize / 2 + posX; int width1000 = 40; int width100 = 33; int width10 = 28; int width1 = 20; int posX1000 = 50; int posX100 = 67; int posX10 = 36; int posX1 = 11; int center1000 = center - (width1000 / 2); int center100 = center - (width100 / 2); int center10 = center - (width10 / 2); int center1 = center - (width1 / 2); int posY1000 = posY + 4; int posY100 = posY + 25; int posY10 = posY100; int posY1 = posY100; this.buttonList.add(new GuiButton(1, center1000 - posX1000, posY1000, width1000, 20, "-1000")); this.buttonList.add(new GuiButton(2, center1000 + posX1000, posY1000, width1000, 20, "+1000")); this.buttonList.add(new GuiButton(3, center100 - posX100, posY100, width100, 20, "-100")); this.buttonList.add(new GuiButton(4, center100 + posX100, posY100, width100, 20, "+100")); this.buttonList.add(new GuiButton(5, center10 - posX10, posY10, width10, 20, "-10")); this.buttonList.add(new GuiButton(6, center10 + posX10, posY10, width10, 20, "+10")); this.buttonList.add(new GuiButton(7, center1 - posX1, posY1, width1, 20, "-1")); this.buttonList.add(new GuiButton(8, center1 + posX1, posY1, width1, 20, "+1")); this.buttonList.add(new DisabledButton(0, center - (45 / 2), posY1000, 45, 20, wirelessChestEntity.getFreqStr())); } @SuppressWarnings("unchecked") @Override protected void actionPerformed(GuiButton button) { this.guiLeft = (this.width - this.xSize) / 2; this.guiTop = (this.height - this.ySize) / 2; int posX = this.guiLeft; int posY = this.guiTop; int center = this.xSize / 2 + posX; int posY1000 = posY + 4; if (button.id == 1) { if (container.getFreq() < 1000) container.setFreq(0); else container.setFreq(container.getFreq() - 1000); } if (button.id == 2) { if (container.getFreq() > 8999) container.setFreq(9999); else container.setFreq(container.getFreq() + 1000); } this.buttonList.remove(this.buttonList.size() - 1); this.buttonList.add(new DisabledButton(0, center - (45 / 2), posY1000, 45, 20, container.freqStr())); this.mc.playerController.sendEnchantPacket(this.container.windowId, container.getFreq()); } @Override public void onGuiClosed() { if (this.mc.thePlayer != null) this.inventorySlots.onContainerClosed(this.mc.thePlayer); } } And yet after I close the map it still doesn't save the frequency. Only the items. And just an FYI cause it doesn't seem clear, I am using MC 1.8.
  14. So I add an override enchantItem() into the Container. I assume I ned to put this.mc.playerController.sendEnchantPacket(container.windowId, action); Into the GuiContainer. But how do I access the container to get the windowId from the GuiContainer? Edit: I also tried doing this.wirelessChestEntity.freq(4000); in the onContainerClosed just to force it to do something on the container, and it still only is changed for the duration I'm in the game. If I save and quit, it still resets to 0.
  15. How would I go about that though. Should I access the container that is the superclass of GuiContainer, since that half of it is server side? Would changing that tile entity work? (Assuming I make it accessible by the guicontainer)
×
×
  • Create New...

Important Information

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