Plusieurs liquides dans un Chaudron ? | Des "fuels" pour certains objets uniquement ?
-
Bonjour, ayant commencé à coder sur Minecraft depuis peu, j’ai rencontré différents problèmes que j’ai sût régler par ma propre initiative. Malheureusement, il s’avère que je ne parviens pas à régler certains d’entre eux.
Alors pour commencer, après avoir créé un block chaudron, j’ai cherché à y ajouter différents liquides (comme l’eau qui y est de base), mais après plusieurs tentatives pour modifier le code, je tente de rajouter manuellement un autre second liquide qui refuse de s’y mettre de s’y mettre, empêchant par la même occasion le premier liquide (que j’avais rajouté auparavant en modifiant les données de l’eau) qui à la base fonctionnait très bien d’être contenu dans le chaudron.
Du coup, j’en viens à demander de l’aide quant à l’ajout d’un second liquide pouvant être contenu par le Block Chaudron.Voici le code de la class principal du block (ici nommé BarrilAsCauldron) :
package be.istiile.weapon.block.divers; import java.util.List; import java.util.Random; import javax.annotation.Nullable; import be.istiile.weapon.Global; import be.istiile.weapon.block.WBlocks; import be.istiile.weapon.item.WItems; import net.minecraft.block.Block; import net.minecraft.block.BlockCauldron; import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.Items; import net.minecraft.init.PotionTypes; import net.minecraft.item.Item; import net.minecraft.item.ItemArmor; import net.minecraft.item.ItemBanner; import net.minecraft.item.ItemStack; import net.minecraft.potion.PotionUtils; import net.minecraft.stats.StatList; import net.minecraft.tileentity.TileEntityBanner; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BarrilAsCauldron extends Block { public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 9); protected static final AxisAlignedBB AABB_LEGS = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.3125D, 1.0D); protected static final AxisAlignedBB AABB_WALL_NORTH = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 1.0D, 0.125D); protected static final AxisAlignedBB AABB_WALL_SOUTH = new AxisAlignedBB(0.0D, 0.0D, 0.875D, 1.0D, 1.0D, 1.0D); protected static final AxisAlignedBB AABB_WALL_EAST = new AxisAlignedBB(0.875D, 0.0D, 0.0D, 1.0D, 1.0D, 1.0D); protected static final AxisAlignedBB AABB_WALL_WEST = new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.125D, 1.0D, 1.0D); public BarrilAsCauldron(String unlocalizedName) { super(Material.WOOD); this.setDefaultState(this.blockState.getBaseState().withProperty(LEVEL, Integer.valueOf(0))); this.setUnlocalizedName("barril_As_Cauldron"); this.setRegistryName(new ResourceLocation(Global.MOD_ID, unlocalizedName)); } public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List <axisalignedbb>collidingBoxes, @Nullable Entity entityIn) { addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_LEGS); addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_WEST); addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_NORTH); addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_EAST); addCollisionBoxToList(pos, entityBox, collidingBoxes, AABB_WALL_SOUTH); } public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) { return FULL_BLOCK_AABB; } /** * Used to determine ambient occlusion and culling when rebuilding chunks for render */ public boolean isOpaqueCube(IBlockState state) { return false; } public boolean isFullCube(IBlockState state) { return false; } /** * Called When an Entity Collided with the Block */ public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { int i = ((Integer)state.getValue(LEVEL)).intValue(); float f = (float)pos.getY() + (6.0F + (float)(9 * i)) / 16.0F; if (!worldIn.isRemote && entityIn.isBurning() && i > 0 && entityIn.getEntityBoundingBox().minY <= (double)f) { entityIn.extinguish(); this.setWaterLevel(worldIn, pos, state, i - 1); } } public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (heldItem == null) { return true; } else { int i = ((Integer)state.getValue(LEVEL)).intValue(); Item item = heldItem.getItem(); if (item == WItems.seauBeer) { if (i < 9 && !worldIn.isRemote) { if (!playerIn.capabilities.isCreativeMode) { playerIn.setHeldItem(hand, new ItemStack(Items.BUCKET)); } playerIn.addStat(StatList.CAULDRON_FILLED); this.setWaterLevel(worldIn, pos, state, 9); } return true; } if (item == Items.BUCKET) { if (i == 9 && !worldIn.isRemote) { if (!playerIn.capabilities.isCreativeMode) { –heldItem.stackSize; if (heldItem.stackSize == 0) { playerIn.setHeldItem(hand, new ItemStack(WItems.seauBeer)); } else if (!playerIn.inventory.addItemStackToInventory(new ItemStack(WItems.seauBeer))) { playerIn.dropItem(new ItemStack(WItems.seauBeer), false); } else if (!playerIn.inventory.addItemStackToInventory(new ItemStack(WItems.seauRaisinRouge))) { playerIn.dropItem(new ItemStack(WItems.seauRaisinBlanc), false); } else if (!playerIn.inventory.addItemStackToInventory(new ItemStack(WItems.seauRaisinBlanc))) { playerIn.dropItem(new ItemStack(WItems.seauRaisinBlanc), false); } } playerIn.addStat(StatList.CAULDRON_USED); this.setWaterLevel(worldIn, pos, state, 0); } return true; } else if (item == Items.GLASS_BOTTLE) { if (i > 0 && !worldIn.isRemote) { if (!playerIn.capabilities.isCreativeMode) { ItemStack itemstack = PotionUtils.addPotionToItemStack(new ItemStack(Items.POTIONITEM), PotionTypes.WATER); playerIn.addStat(StatList.CAULDRON_USED); if (--heldItem.stackSize == 0) { playerIn.setHeldItem(hand, itemstack); } else if (!playerIn.inventory.addItemStackToInventory(itemstack)) { playerIn.dropItem(itemstack, false); } else if (playerIn instanceof EntityPlayerMP) { ((EntityPlayerMP)playerIn).sendContainerToPlayer(playerIn.inventoryContainer); } } this.setWaterLevel(worldIn, pos, state, i - 1); } return true; } else { if (i > 0 && item instanceof ItemArmor) { ItemArmor itemarmor = (ItemArmor)item; if (itemarmor.getArmorMaterial() == ItemArmor.ArmorMaterial.LEATHER && itemarmor.hasColor(heldItem) && !worldIn.isRemote) { itemarmor.removeColor(heldItem); this.setWaterLevel(worldIn, pos, state, i - 1); playerIn.addStat(StatList.ARMOR_CLEANED); return true; } } if (i > 0 && item instanceof ItemBanner) { if (TileEntityBanner.getPatterns(heldItem) > 0 && !worldIn.isRemote) { ItemStack itemstack = heldItem.copy(); itemstack.stackSize = 1; TileEntityBanner.removeBannerData(itemstack); playerIn.addStat(StatList.BANNER_CLEANED); if (!playerIn.capabilities.isCreativeMode) { --heldItem.stackSize; } if (heldItem.stackSize == 0) { playerIn.setHeldItem(hand, itemstack); } else if (!playerIn.inventory.addItemStackToInventory(itemstack)) { playerIn.dropItem(itemstack, false); } else if (playerIn instanceof EntityPlayerMP) { ((EntityPlayerMP)playerIn).sendContainerToPlayer(playerIn.inventoryContainer); } if (!playerIn.capabilities.isCreativeMode) { this.setWaterLevel(worldIn, pos, state, i - 1); } } return true; } else { return false; } } } } public void setWaterLevel(World worldIn, BlockPos pos, IBlockState state, int level) { worldIn.setBlockState(pos, state.withProperty(LEVEL, Integer.valueOf(MathHelper.clamp(level, 0, 9))), 2); worldIn.updateComparatorOutputLevel(pos, this); } /** * Called similar to random ticks, but only when it is raining. */ public void fillWithRain(World worldIn, BlockPos pos) { if (worldIn.rand.nextInt(20) == 1) { float f = worldIn.getBiome(pos).getFloatTemperature(pos); if (worldIn.getBiomeProvider().getTemperatureAtHeight(f, pos.getY()) >= 0.15F) { IBlockState iblockstate = worldIn.getBlockState(pos); if (((Integer)iblockstate.getValue(LEVEL)).intValue() < 9) { worldIn.setBlockState(pos, iblockstate.cycleProperty(LEVEL), 2); } } } } /** * Get the Item that this Block should drop when harvested. */ @Nullable public Item getItemDropped(IBlockState state, Random rand, int fortune) { return Item.getItemFromBlock(WBlocks.barrilAsCauldron); } public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) { return new ItemStack(WBlocks.barrilAsCauldron); } public boolean hasComparatorInputOverride(IBlockState state) { return true; } public int getComparatorInputOverride(IBlockState blockState, World worldIn, BlockPos pos) { return ((Integer)blockState.getValue(LEVEL)).intValue(); } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(LEVEL, Integer.valueOf(meta)); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return ((Integer)state.getValue(LEVEL)).intValue(); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] {LEVEL}); } public boolean isPassable(IBlockAccess worldIn, BlockPos pos) { return true; } }
Ensuite, j’avais une autre demande.
Pour que dans un block codé comme un four, on puisse mettre une condition pour que le block « cuit » ne puisse l’être que par un unique « fuel ».
Je m’explique. En gros, j’ai créé un baril qui fonctionne comme un four et qui a pour but de cuir des seaux d’un certains liquide (de malt, de raisin, etc…) afin de donner en résultat des seaux d’alcool (bière, vin …). Le problème est que du coup, j’ai dû mettre les items qui devaient servir de fuels pour “cuir” le seau du liquide, mais de ce fait, je cherche à ce que certains items ne puissent pas “cuir” certains seaux (comme ici présent le houblon qui ne doit pas “cuir” les seaux de raisin).Voici le code du TileEntity du four (ici nommé TEntityBarril
package be.istiile.weapon.block.tileentityblock; import java.util.Random; import javax.annotation.Nullable; import be.istiile.weapon.Main; import be.istiile.weapon.block.furnace.BarrilBlock; import be.istiile.weapon.item.WItems; import net.minecraft.block.Block; import net.minecraft.block.BlockFurnace; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.init.SoundEvents; import net.minecraft.inventory.Container; import net.minecraft.inventory.ContainerFurnace; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.InventoryHelper; import net.minecraft.inventory.ItemStackHelper; import net.minecraft.inventory.SlotFurnaceFuel; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemHoe; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemTool; import net.minecraft.item.crafting.FurnaceRecipes; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.stats.StatList; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityLockable; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.ITickable; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.SoundCategory; import net.minecraft.util.datafix.DataFixer; import net.minecraft.util.datafix.FixTypes; import net.minecraft.util.datafix.walkers.ItemStackDataLists; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class TEntityBarril extends TileEntityLockable implements ITickable, ISidedInventory { private static final int[] SLOTS_TOP = new int[] {0}; private static final int[] SLOTS_BOTTOM = new int[] {2, 1}; private static final int[] SLOTS_SIDES = new int[] {1}; /** The ItemStacks that hold the items currently being used in the furnace */ private ItemStack[] barrilItemStack = new ItemStack[3]; /** The number of ticks that the furnace will keep burning */ private int furnaceBurnTime; /** The number of ticks that a fresh copy of the currently-burning item would keep the furnace burning for */ private int currentItemBurnTime; private int cookTime; private int totalCookTime; private String furnaceCustomName; /** * Returns the number of slots in the inventory. */ public int getSizeInventory() { return this.barrilItemStack.length; } /** * Returns the stack in the given slot. */ @Nullable public ItemStack getStackInSlot(int index) { return this.barrilItemStack[index]; } /** * Removes up to a specified number of items from an inventory slot and returns them in a new stack. */ @Nullable public ItemStack decrStackSize(int index, int count) { return ItemStackHelper.getAndSplit(this.barrilItemStack, index, count); } /** * Removes a stack from the given slot and returns it. */ @Nullable public ItemStack removeStackFromSlot(int index) { return ItemStackHelper.getAndRemove(this.barrilItemStack, index); } /** * Sets the given item stack to the specified slot in the inventory (can be crafting or armor sections). */ public void setInventorySlotContents(int index, @Nullable ItemStack stack) { boolean flag = stack != null && stack.isItemEqual(this.barrilItemStack[index]) && ItemStack.areItemStackTagsEqual(stack, this.barrilItemStack[index]); this.barrilItemStack[index] = stack; if (stack != null && stack.stackSize > this.getInventoryStackLimit()) { stack.stackSize = this.getInventoryStackLimit(); } if (index == 0 && !flag) { this.totalCookTime = this.getCookTime(stack); this.cookTime = 0; this.markDirty(); } } /** * Get the name of this object. For players this returns their username */ public String getName() { return this.hasCustomName() ? this.furnaceCustomName : "Baril"; } /** * Returns true if this thing is named */ public boolean hasCustomName() { return this.furnaceCustomName != null && !this.furnaceCustomName.isEmpty(); } public void setCustomInventoryName(String p_145951_1_) { this.furnaceCustomName = p_145951_1_; } public static void registerFixesFurnace(DataFixer fixer) { fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists("Furnace", new String[] {"Items"})); } public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); NBTTagList nbttaglist = compound.getTagList("Items", 10); this.barrilItemStack = new ItemStack[this.getSizeInventory()]; for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound.getByte("Slot"); if (j >= 0 && j < this.barrilItemStack.length) { this.barrilItemStack[j] = ItemStack.loadItemStackFromNBT(nbttagcompound); } } this.furnaceBurnTime = compound.getInteger("BurnTime"); this.cookTime = compound.getInteger("CookTime"); this.totalCookTime = compound.getInteger("CookTimeTotal"); this.currentItemBurnTime = getItemBurnTime(this.barrilItemStack[1]); if (compound.hasKey("CustomName", 8)) { this.furnaceCustomName = compound.getString("CustomName"); } } public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); compound.setInteger("BurnTime", this.furnaceBurnTime); compound.setInteger("CookTime", this.cookTime); compound.setInteger("CookTimeTotal", this.totalCookTime); NBTTagList nbttaglist = new NBTTagList(); for (int i = 0; i < this.barrilItemStack.length; ++i) { if (this.barrilItemStack != null) * * { NBTTagCompound nbttagcompound = new NBTTagCompound(); nbttagcompound.setByte("Slot", (byte)i); this.barrilItemStack.writeToNBT(nbttagcompound); nbttaglist.appendTag(nbttagcompound); } } compound.setTag("Items", nbttaglist); if (this.hasCustomName()) { compound.setString("CustomName", this.furnaceCustomName); } return compound; } /** * Returns the maximum stack size for a inventory slot. Seems to always be 64, possibly will be extended. */ public int getInventoryStackLimit() { return 64; } /** * Furnace isBurning */ public boolean isBurning() { return this.furnaceBurnTime > 0; } @SideOnly(Side.CLIENT) public static boolean isBurning(IInventory inventory) { return inventory.getField(0) > 0; } /** * Like the old updateEntity(), except more generic. */ public void update() { boolean flag = this.isBurning(); boolean flag1 = false; if (this.isBurning()) { –this.furnaceBurnTime; } if (!this.world.isRemote) { if (this.isBurning() || this.barrilItemStack[1] != null && this.barrilItemStack[0] != null) { if (!this.isBurning() && this.canSmelt()) { this.furnaceBurnTime = getItemBurnTime(this.barrilItemStack[1]); this.currentItemBurnTime = this.furnaceBurnTime; if (this.isBurning()) { flag1 = true; if (this.barrilItemStack[1] != null) { –this.barrilItemStack[1].stackSize; if (this.barrilItemStack[1].stackSize == 0) { this.barrilItemStack[1] = barrilItemStack[1].getItem().getContainerItem(barrilItemStack[1]); } } } } if (this.isBurning() && this.canSmelt()) { ++this.cookTime; if (this.cookTime == this.totalCookTime) { this.cookTime = 0; this.totalCookTime = this.getCookTime(this.barrilItemStack[0]); this.smeltItem(); flag1 = true; } } else { this.cookTime = 0; } } else if (!this.isBurning() && this.cookTime > 0) { this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.totalCookTime); } if (flag != this.isBurning()) { flag1 = true; BarrilBlock.setState(this.isBurning(), this.world, this.pos); } } if (flag1) { this.markDirty(); } } /** * Time to cook something Lower = Faster (100 = plus rapide que 300) */ public int getCookTime(@Nullable ItemStack stack) { return 200; } /** * Returns true if the furnace can smelt an item, i.e. has a source item, destination stack isn't full, etc. */ private boolean canSmelt() { if (this.barrilItemStack[0] == null) { return false; } else { ItemStack itemstack = RecipesCustom.instance().getSmeltingResult(this.barrilItemStack[0]); if (itemstack == null) return false; if (this.barrilItemStack[2] == null) return true; if (!this.barrilItemStack[2].isItemEqual(itemstack)) return false; int result = barrilItemStack[2].stackSize + itemstack.stackSize; return result <= getInventoryStackLimit() && result <= this.barrilItemStack[2].getMaxStackSize(); //Forge BugFix: Make it respect stack sizes properly. } } /** * Turn one item from the fonderie source stack into the appropriate smelted item in the fonderie result stack */ public void smeltItem() { if (this.canSmelt()) { ItemStack itemstack = RecipesCustom.instance().getSmeltingResult(this.barrilItemStack[0]); if (this.barrilItemStack[2] == null) { this.barrilItemStack[2] = itemstack.copy(); } else if (this.barrilItemStack[2].getItem() == itemstack.getItem()) { this.barrilItemStack[2].stackSize += itemstack.stackSize; // Forge BugFix: Results may have multiple items } if (this.barrilItemStack[0].getItem() == Item.getItemFromBlock(Blocks.SPONGE) && this.barrilItemStack[0].getMetadata() == 1 && this.barrilItemStack[1] != null && this.barrilItemStack[1].getItem() == Items.BUCKET) { this.barrilItemStack[1] = new ItemStack(Items.WATER_BUCKET); } –this.barrilItemStack[0].stackSize; if (this.barrilItemStack[0].stackSize <= 0) { this.barrilItemStack[0] = null; } } } /** * Returns the number of ticks that the supplied fuel item will keep the furnace burning, or 0 if the item isn't * fuel */ public static int getItemBurnTime(ItemStack stack) { if (stack == null) { return 0; } else { Item item = stack.getItem(); if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR) { Block block = Block.getBlockFromItem(item); } if (item == WItems.houblon) return 23; if (item == WItems.redGrapes) return 23; if (item == WItems.whiteGrapes) return 23; return net.minecraftforge.fml.common.registry.GameRegistry.getFuelValue(stack); } } public static boolean isItemFuel(ItemStack stack) { return getItemBurnTime(stack) > 0; } /** * Don't rename this method to canInteractWith due to conflicts with Container */ public boolean isUsableByPlayer(EntityPlayer player) { return this.world.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; } public void openInventory(EntityPlayer player) { } public void closeInventory(EntityPlayer player) { } /** * Returns true if automation is allowed to insert the given stack (ignoring stack size) into the given slot. For * guis use Slot.isItemValid */ public boolean isItemValidForSlot(int index, ItemStack stack) { if (index == 2) { return false; } else if (index != 1) { return true; } else { ItemStack itemstack = this.barrilItemStack[1]; return isItemFuel(stack) || SlotFurnaceFuel.isBucket(stack) && (itemstack == null || itemstack.getItem() != Items.BUCKET); } } public int[] getSlotsForFace(EnumFacing side) { return side == EnumFacing.DOWN ? SLOTS_BOTTOM : (side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES); } /** * Returns true if automation can insert the given item in the given slot from the given side. */ public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) { return this.isItemValidForSlot(index, itemStackIn); } /** * Returns true if automation can extract the given item in the given slot from the given side. */ public boolean canExtractItem(int index, 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 String getGuiID() { return "MOD_TILE_ENTITY_GUI"; } public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn) { return new ContainerBarril(playerInventory, this); } public int getField(int id) { switch (id) { case 0: return this.furnaceBurnTime; case 1: return this.currentItemBurnTime; case 2: return this.cookTime; case 3: return this.totalCookTime; default: return 0; } } public void setField(int id, int value) { switch (id) { case 0: this.furnaceBurnTime = value; break; case 1: this.currentItemBurnTime = value; break; case 2: this.cookTime = value; break; case 3: this.totalCookTime = value; } } public int getFieldCount() { return 4; } public void clear() { for (int i = 0; i < this.barrilItemStack.length; ++i) { this.barrilItemStack = null; } } net.minecraftforge.items.IItemHandler handlerTop = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.UP); net.minecraftforge.items.IItemHandler handlerBottom = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.DOWN); net.minecraftforge.items.IItemHandler handlerSide = new net.minecraftforge.items.wrapper.SidedInvWrapper(this, net.minecraft.util.EnumFacing.WEST); @SuppressWarnings("unchecked") @Override public <t>T getCapability(net.minecraftforge.common.capabilities.Capability <t>capability, net.minecraft.util.EnumFacing facing) { if (facing != null && capability == net.minecraftforge.items.CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) if (facing == EnumFacing.DOWN) return (T) handlerBottom; else if (facing == EnumFacing.UP) return (T) handlerTop; else return (T) handlerSide; return super.getCapability(capability, facing); } }
Le code de ma class pour les recipes du baril (nommé RecipesCustom
package be.istiile.weapon.block.tileentityblock; import java.util.Map; import java.util.Map.Entry; import com.google.common.collect.Maps; import be.istiile.weapon.item.WItems; import net.minecraft.block.Block; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; public class RecipesCustom { private static final RecipesCustom smeltingBase = new RecipesCustom(); private Map <itemstack, itemstack="">smeltingList = Maps.<itemstack, itemstack="">newHashMap(); private Map <itemstack, float="">experienceList = Maps.<itemstack, float="">newHashMap(); /** * Returns an instance of FurnaceRecipes. */ public static RecipesCustom instance() { return smeltingBase; } private RecipesCustom() { this.addSmelting(WItems.seauMalt, new ItemStack(WItems.seauBeer), 0F); this.addSmelting(Items.BUCKET, new ItemStack(WItems.seauRaisinRouge), 0F); this.addSmelting(Items.BUCKET, new ItemStack(WItems.seauRaisinBlanc), 0F); } /** * Adds a smelting recipe, where the input item is an instance of Block. */ public void addSmeltingRecipeForBlock(Block input, ItemStack stack, float experience) { this.addSmelting(Item.getItemFromBlock(input), stack, experience); } /** * Adds a smelting recipe using an Item as the input item. */ public void addSmelting(Item input, ItemStack stack, float experience) { this.addSmeltingRecipe(new ItemStack(input, 1, 32767), stack, experience); } /** * Adds a smelting recipe using an ItemStack as the input for the recipe. */ public void addSmeltingRecipe(ItemStack input, ItemStack stack, float experience) { if (getSmeltingResult(input) != null) { net.minecraftforge.fml.common.FMLLog.info("Ignored smelting recipe with conflicting input: " + input + " = " + stack); return; } this.smeltingList.put(input, stack); this.experienceList.put(stack, Float.valueOf(experience)); } /** * Returns the smelting result of an item. */ public ItemStack getSmeltingResult(ItemStack stack) { for (Entry <itemstack, itemstack="">entry : this.smeltingList.entrySet()) { if (this.compareItemStacks(stack, (ItemStack)entry.getKey())) { return (ItemStack)entry.getValue(); } } return null; } /** * Compares two itemstacks to ensure that they are the same. This checks both the item and the metadata of the item. */ private boolean compareItemStacks(ItemStack stack1, ItemStack stack2) { return stack2.getItem() == stack1.getItem() && (stack2.getMetadata() == 32767 || stack2.getMetadata() == stack1.getMetadata()); } public Map <itemstack, itemstack="">getSmeltingList() { return this.smeltingList; } public float getSmeltingExperience(ItemStack stack) { float ret = stack.getItem().getSmeltingExperience(stack); if (ret != -1) return ret; for (Entry <itemstack, float="">entry : this.experienceList.entrySet()) { if (this.compareItemStacks(stack, (ItemStack)entry.getKey())) { return ((Float)entry.getValue()).floatValue(); } } return 0.0F; } }
Le code de la class des blocks(nommé WBlocks
package be.istiile.weapon.block; import be.istiile.weapon.Global; import be.istiile.weapon.Main; import be.istiile.weapon.block.divers.BarrilAsCauldron; import be.istiile.weapon.block.divers.Corde; import be.istiile.weapon.block.divers.HoublonPlante; import be.istiile.weapon.block.divers.MaltPlant; import be.istiile.weapon.block.divers.WhiteGrapesPlant; import be.istiile.weapon.block.divers.GrapesLikeCrops; import be.istiile.weapon.block.furnace.BarrilBlock; import be.istiile.weapon.item.Utils; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.block.model.ModelResourceLocation; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.ModelLoader; import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fml.common.registry.GameRegistry; public class WBlocks { public static Block corde; public static Block houblonPlant; public static Block maltPlant; public static Block barril; public static Block lit_barril; public static Block barrilAsCauldron; public static Block redWineAsReed; public static Block whiteGrapesPlant; public static void init() { corde = new Corde("corde"); houblonPlant = new HoublonPlante("houblonPlant"); maltPlant = new MaltPlant("maltPlant"); barril = new BarrilBlock(false, "barril"); lit_barril = new BarrilBlock(true, "lit_barril"); barrilAsCauldron = new BarrilAsCauldron("barril_As_Cauldron"); redWineAsReed = new GrapesLikeCrops("redWineAsReed"); whiteGrapesPlant = new WhiteGrapesPlant("whiteGrapesPlant"); } public static void register() { registerBlock(corde); registerBlock(houblonPlant); registerBlock(maltPlant); registerBlock(barril); registerBlock(lit_barril); registerBlock(barrilAsCauldron); registerBlock(redWineAsReed); registerBlock(whiteGrapesPlant); } public static void registerRenders() { registerRender(corde); registerRender(houblonPlant, 0, "houblonPlant"); registerRender(maltPlant, 0, "maltPlant"); registerRender(barril); registerRender(lit_barril); registerRender(barrilAsCauldron); registerRender(redWineAsReed); registerRender(whiteGrapesPlant); } public static void registerBlock(Block block) { block.setCreativeTab(Main.blocks); GameRegistry.register(block); GameRegistry.register(new ItemBlock(block).setRegistryName(block.getRegistryName())); Utils.getLogger().info("Registered Block: " + block.getUnlocalizedName().substring(5)); } public static void registerBlock(Block block, ItemBlock itemBlock) { block.setCreativeTab(Main.blocks); GameRegistry.register(block); GameRegistry.register(itemBlock.setRegistryName(block.getRegistryName())); Utils.getLogger().info("Registered Block: " + block.getUnlocalizedName().substring(5)); } public static void registerRender(Block block) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0, new ModelResourceLocation(new ResourceLocation(Global.MOD_ID, block.getUnlocalizedName().substring(5)), "inventory")); Utils.getLogger().info("Registered render for " + block.getUnlocalizedName().substring(5)); } public static void registerRender(Block block, int meta, String fileName) { ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), meta, new ModelResourceLocation(new ResourceLocation(Global.MOD_ID, fileName), "inventory")); Utils.getLogger().info("Registered render for " + block.getUnlocalizedName().substring(5)); } }
Voilà si il y’a besoin de plus de class faites-moi signe je la rajouterai en edit. Aussi ma version de forge est la forge-1.10.2-12.18.3.2185. Merci d’avance de votre aide et bonne journée/ bonne soirée !</itemstack,></itemstack,></itemstack,></itemstack,></itemstack,></itemstack,></itemstack,></t></t></axisalignedbb>