• 0

    posted a message on creating block variants with different hardness and resistance

    Here is the code for my custom planks:

    package kenneths_mods.kenneths_medieval_mod.objects.bases;
    
    import java.util.List;
    
    import kenneths_mods.kenneths_medieval_mod.utils.IMetaName;
    import net.minecraft.block.Block;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.properties.IProperty;
    import net.minecraft.block.properties.PropertyEnum;
    import net.minecraft.block.state.BlockStateContainer;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.client.util.ITooltipFlag;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.IStringSerializable;
    import net.minecraft.util.NonNullList;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.math.RayTraceResult;
    import net.minecraft.world.World;
    
    public class PlanksBase extends Block implements IMetaName {
    	
    	public static final PropertyEnum<PlanksBase.EnumType> VARIANT = PropertyEnum.<PlanksBase.EnumType>create("variant", PlanksBase.EnumType.class);
    	
    	public PlanksBase(String name, float hardness, float resistance) {
    		super(Material.WOOD);
    		setUnlocalizedName(name);
    		setRegistryName(name);
    		setResistance(resistance);
    		setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
    		this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, PlanksBase.EnumType.ironwood));
    	}
    	
    	@Override
    	public int damageDropped(IBlockState state) {
    		return ((PlanksBase.EnumType)state.getValue(VARIANT)).getMeta();
    	}
    	@Override
    	public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
    		for(PlanksBase.EnumType planksBase$EnumType : PlanksBase.EnumType.values()) {
    			items.add(new ItemStack(this, 1, planksBase$EnumType.getMeta()));
    		}
    	}
    	@Override
    	public IBlockState getStateFromMeta(int meta) {
    		return this.getDefaultState().withProperty(VARIANT, PlanksBase.EnumType.byMetaData(meta));
    	}
    	@Override
    	public int getMetaFromState(IBlockState state) {
    		return ((PlanksBase.EnumType)state.getValue(VARIANT)).getMeta();
    	}
    	@Override
    	public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    		return new ItemStack(Item.getItemFromBlock(this), 1, (int)getMetaFromState(world.getBlockState(pos)));
    	}
    	@Override
    	protected BlockStateContainer createBlockState() {
    		return new BlockStateContainer(this, new IProperty[] {VARIANT});
    	}
    	
    	public static enum EnumType implements IStringSerializable {
    		
    		ironwood(0, "ironwood"),
    		yew(1, "yew");
    		
    		private static final PlanksBase.EnumType[] META_LOOKUP = new PlanksBase.EnumType[values().length];
    		private final int meta;
    		private final String name, unlocalizedName;
    		
    		private EnumType (int meta, String name) {
    			this(meta, name, name);
    		}
    		private EnumType (int meta, String name, String unlocalizedName) {
    			this.meta = meta;
    			this.name = name;
    			this.unlocalizedName = unlocalizedName;
    		}
    		
    		@Override
    		public String getName() {
    			return this.name();
    		}
    		public int getMeta() {
    			return this.meta;
    		}
    		public String getUnlocalizedName() {
    			return this.unlocalizedName;
    		}
    		@Override
    		public String toString() {
    			return this.name;
    		}
    		public static PlanksBase.EnumType byMetaData(int meta){
    			return META_LOOKUP[meta];
    		}
    		static {
    			for(PlanksBase.EnumType planksBase$EnumType : values()) {
    				META_LOOKUP[planksBase$EnumType.getMeta()] = planksBase$EnumType;
    			}
    		}
    	}
    
    	@Override
    	public String getSpecialName(ItemStack stack) {
    		return PlanksBase.EnumType.values()[stack.getItemDamage()].getName();
    	}
    }
    



    I am trying to make it where the Ironwood planks are much harder to break then the yew ones. Any ideas?


    Thanks in advanced.

    Posted in: Modification Development
  • 0

    posted a message on Adding log rotation to an old script:

    I have watched harrys tech reviews tutorials on how to make logs using variants. The problem is he never mentioned how to make the blocks rotateable like regular logs in the game. Anyone know what needs to be added to my scripts to create rotateable logs?:


    package kenneths_mods.kenneths_medieval_mod.objects.bases;
    
    import javax.annotation.Nullable;
    
    import com.google.common.base.Predicate;
    
    import kenneths_mods.kenneths_medieval_mod.utils.IMetaName;
    import net.minecraft.block.BlockLog;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.properties.IProperty;
    import net.minecraft.block.properties.PropertyEnum;
    import net.minecraft.block.state.BlockStateContainer;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.NonNullList;
    
    public class LogsBase extends BlockLog implements IMetaName {
    	public static final PropertyEnum<PlanksBase.EnumType> VARIANT = PropertyEnum.<PlanksBase.EnumType>create("variant", PlanksBase.EnumType.class, new Predicate <PlanksBase.EnumType>(){
    		public boolean apply (@Nullable PlanksBase.EnumType apply) {
    			return apply.getMeta() < 2;
    		}
    	});
    	public LogsBase (String name) {
    		setUnlocalizedName(name);
    		setRegistryName(name);
    		setSoundType(SoundType.WOOD);
    		setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, PlanksBase.EnumType.ironwood).withProperty(LOG_AXIS, EnumAxis.Y));
    	}
    	@Override
    	public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
    		for(PlanksBase.EnumType planksBase$EnumType : PlanksBase.EnumType.values()) {
    			items.add(new ItemStack(this, 1, planksBase$EnumType.getMeta()));
    		}
    	}
    	@Override
    	public IBlockState getStateFromMeta(int meta) {
    		IBlockState state = this.getDefaultState().withProperty(VARIANT, PlanksBase.EnumType.byMetaData((meta & 1) % 2));
    		switch(meta & 6) {
    		case 0:
    			state = state.withProperty(LOG_AXIS, EnumAxis.Y);
    			break;
    		case 2:
    			state = state.withProperty(LOG_AXIS, EnumAxis.X);
    			break;
    		case 4:
    			state = state.withProperty(LOG_AXIS, EnumAxis.Z);
    			break;
    		default:
    			state = state.withProperty(LOG_AXIS, EnumAxis.NONE);
    		}
    		return state;
    	}
    	@SuppressWarnings("incomplete-switch")
    	@Override
    	public int getMetaFromState(IBlockState state) {
    		int i = 0;
    		i = i | ((PlanksBase.EnumType)state.getValue(VARIANT)).getMeta();
    		switch((BlockLog.EnumAxis)state.getValue(LOG_AXIS)) {
    		case X:
    			i |= 2;
    			break;
    		case Y:
    			i |= 4;
    			break;
    		case Z:
    			i |= 6;
    		}
    		return i;
    	}
    	@Override
    	protected BlockStateContainer createBlockState() {
    		return new BlockStateContainer(this, new IProperty[] {VARIANT, LOG_AXIS});
    	}
    	@Override
    	protected ItemStack getSilkTouchDrop(IBlockState state) {
    		return new ItemStack (Item.getItemFromBlock(this), 1, ((PlanksBase.EnumType)state.getValue(VARIANT)).getMeta());
    	}
    	@Override
    	public int damageDropped(IBlockState state) {
    		return ((PlanksBase.EnumType)state.getValue(VARIANT)).getMeta();
    	}
    	@Override
    	public String getSpecialName(ItemStack stack) {
    		return PlanksBase.EnumType.values()[stack.getItemDamage()].getName();
    	}
    }
    



    package kenneths_mods.kenneths_medieval_mod.objects.bases;
    
    import java.util.List;
    
    import kenneths_mods.kenneths_medieval_mod.utils.IMetaName;
    import net.minecraft.block.Block;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.properties.IProperty;
    import net.minecraft.block.properties.PropertyEnum;
    import net.minecraft.block.state.BlockStateContainer;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.client.util.ITooltipFlag;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    import net.minecraft.util.IStringSerializable;
    import net.minecraft.util.NonNullList;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.math.RayTraceResult;
    import net.minecraft.world.World;
    
    public class PlanksBase extends Block implements IMetaName {
    	
    	public static final PropertyEnum<PlanksBase.EnumType> VARIANT = PropertyEnum.<PlanksBase.EnumType>create("variant", PlanksBase.EnumType.class);
    	
    	public PlanksBase(String name, float hardness, float resistance) {
    		super(Material.WOOD);
    		setUnlocalizedName(name);
    		setRegistryName(name);
    		setResistance(resistance);
    		setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
    		this.setDefaultState(this.blockState.getBaseState().withProperty(VARIANT, PlanksBase.EnumType.ironwood));
    	}
    	
    	@Override
    	public int damageDropped(IBlockState state) {
    		return ((PlanksBase.EnumType)state.getValue(VARIANT)).getMeta();
    	}
    	@Override
    	public void getSubBlocks(CreativeTabs itemIn, NonNullList<ItemStack> items) {
    		for(PlanksBase.EnumType planksBase$EnumType : PlanksBase.EnumType.values()) {
    			items.add(new ItemStack(this, 1, planksBase$EnumType.getMeta()));
    		}
    	}
    	@Override
    	public IBlockState getStateFromMeta(int meta) {
    		return this.getDefaultState().withProperty(VARIANT, PlanksBase.EnumType.byMetaData(meta));
    	}
    	@Override
    	public int getMetaFromState(IBlockState state) {
    		return ((PlanksBase.EnumType)state.getValue(VARIANT)).getMeta();
    	}
    	@Override
    	public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player) {
    		return new ItemStack(Item.getItemFromBlock(this), 1, (int)getMetaFromState(world.getBlockState(pos)));
    	}
    	@Override
    	protected BlockStateContainer createBlockState() {
    		return new BlockStateContainer(this, new IProperty[] {VARIANT});
    	}
    	
    	public static enum EnumType implements IStringSerializable {
    		
    		ironwood(0, "ironwood"),
    		yew(1, "yew");
    		
    		private static final PlanksBase.EnumType[] META_LOOKUP = new PlanksBase.EnumType[values().length];
    		private final int meta;
    		private final String name, unlocalizedName;
    		
    		private EnumType (int meta, String name) {
    			this(meta, name, name);
    		}
    		private EnumType (int meta, String name, String unlocalizedName) {
    			this.meta = meta;
    			this.name = name;
    			this.unlocalizedName = unlocalizedName;
    		}
    		
    		@Override
    		public String getName() {
    			return this.name();
    		}
    		public int getMeta() {
    			return this.meta;
    		}
    		public String getUnlocalizedName() {
    			return this.unlocalizedName;
    		}
    		@Override
    		public String toString() {
    			return this.name;
    		}
    		public static PlanksBase.EnumType byMetaData(int meta){
    			return META_LOOKUP[meta];
    		}
    		static {
    			for(PlanksBase.EnumType planksBase$EnumType : values()) {
    				META_LOOKUP[planksBase$EnumType.getMeta()] = planksBase$EnumType;
    			}
    		}
    	}
    
    	@Override
    	public String getSpecialName(ItemStack stack) {
    		return PlanksBase.EnumType.values()[stack.getItemDamage()].getName();
    	}
    }
    

    PS: My mod requires that I use variants because the sawmill block I created will not process logs created using a regular block class.... the logs must come from variants.

    Posted in: Modification Development
  • 0

    posted a message on Strange inventory behaviour with my sawmill.

    Note the items used in the video are placeholder items.

    Posted in: Modification Development
  • 0

    posted a message on Strange inventory behaviour with my sawmill.

    I have managed to fix the recipe system for my sawmill and now I face a new problem:

    When I remove the items from the sawmill they do not enter the first available inventory slots. How do I fix?


    Here is the sawmill's container code:

    package kenneths_mods.kenneths_medieval_mod.objects.machines.sawmill;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IContainerListener;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.IItemHandler;
    import net.minecraftforge.items.SlotItemHandler;
    
    public class SawmillContainer extends Container {
    	private final SawmillTE tileentity;
    	private int sawTime;
    	
    	public SawmillContainer(InventoryPlayer player, SawmillTE tileentity) {
    		this.tileentity = tileentity;
    		IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    		
    		this.addSlotToContainer(new SlotItemHandler(handler, 0, 39, 34));
    		this.addSlotToContainer(new SlotItemHandler(handler, 1, 72, 34) {
    			public boolean isItemValid (ItemStack stack) {
    				return false;
    			}
    		});
    		for(int y = 0; y < 3; y++) {
    			for(int x = 0; x < 9; x++) {
    				this.addSlotToContainer(new Slot(player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
    			}
    		}
    		for(int x = 0; x < 9; x++) {
    			this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
    		}
    	}
    	
    	@Override
    	public boolean canInteractWith(EntityPlayer playerIn) {
    		return true;
    	}
    	
    	@Override
    	public void detectAndSendChanges() {
    		super.detectAndSendChanges();
    		for(int i = 0; i < this.listeners.size(); i++) {
    			IContainerListener listener = (IContainerListener)this.listeners.get(i);
    			if(this.sawTime != this.tileentity.getField(0)) {
    				listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
    			}
    		}
    		this.sawTime = this.tileentity.getField(0);
    	}
    	
    	@Override
    	public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
    		ItemStack itemstack = ItemStack.EMPTY;
    		Slot slot = (Slot) this.inventorySlots.get(index);
    		if (slot != null && slot.getHasStack()) {
    			ItemStack itemstack1 = slot.getStack();
    			itemstack = itemstack1.copy();
    			if (index < 9) {
    				if (!this.mergeItemStack(itemstack1, 9, (45 - 9), true))
    					return ItemStack.EMPTY;
    			} else if (!this.mergeItemStack(itemstack1, 0, 9, false)) {
    				return ItemStack.EMPTY;
    			}
    			if (itemstack1.getCount() == 0) {
    				slot.putStack(ItemStack.EMPTY);
    			} else {
    				slot.onSlotChanged();
    			}
    			if (itemstack1.getCount() == itemstack.getCount()) {
    				return ItemStack.EMPTY;
    			}
    			slot.onTake(playerIn, itemstack1);
    		}
    		return itemstack;
    	}
    	
    	public void onContainerClosed(EntityPlayer playerIn) {
    		super.onContainerClosed(playerIn);
    	}
    }
    
    Posted in: Modification Development
  • 0

    posted a message on Getting the type of log for a custom machine recipe?

    Here is the container code:
    (Also it now only seems to work with birch)


    package kenneths_mod.medieval_mod.objects.machines.sawmill;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IContainerListener;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.IItemHandler;
    import net.minecraftforge.items.SlotItemHandler;
    public class SawmillContainer extends Container {
    private final SawmillTE tileentity;
    private int sawTime;

    public SawmillContainer(InventoryPlayer player, SawmillTE tileentity) {
    this.tileentity = tileentity;
    IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

    this.addSlotToContainer(new SlotItemHandler(handler, 0, 39, 34));
    this.addSlotToContainer(new SlotItemHandler(handler, 1, 72, 34) {
    public boolean isItemValid (ItemStack stack) {
    return false;
    }
    });
    for(int y = 0; y < 3; y++) {
    for(int x = 0; x < 9; x++) {
    this.addSlotToContainer(new Slot(player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
    }
    }
    for(int x = 0; x < 9; x++) {
    this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
    }
    }

    @Override
    public boolean canInteractWith(EntityPlayer playerIn) {
    return true;
    }

    @Override
    public void detectAndSendChanges() {
    super.detectAndSendChanges();
    for(int i = 0; i < this.listeners.size(); i++) {
    IContainerListener listener = (IContainerListener)this.listeners.get(i);
    if(this.sawTime != this.tileentity.getField(0)) {
    listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
    }
    }
    this.sawTime = this.tileentity.getField(0);
    }

    @Override
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
    ItemStack itemstack = ItemStack.EMPTY;
    Slot slot = (Slot) this.inventorySlots.get(index);
    if(slot != null && slot.getHasStack()) {
    ItemStack itemstack1 = slot.getStack();
    itemstack = itemstack1.copy();
    if(index >= 0 && index < 27) {
    if(!this.mergeItemStack(itemstack1, 27, 36, false)) {
    return ItemStack.EMPTY;
    }
    } else if (index >= 27 && index < 36) {
    if(!this.mergeItemStack(itemstack1, 0, 27, false)) {
    return ItemStack.EMPTY;
    }
    } else if (!this.mergeItemStack(itemstack1, 0, 36, false)) {
    return ItemStack.EMPTY;
    }
    if(itemstack1.isEmpty()) {
    slot.putStack(ItemStack.EMPTY);
    } else {
    slot.onSlotChanged();
    }
    if(itemstack1.getCount() == itemstack.getCount()) {
    return ItemStack.EMPTY;
    }
    slot.onTake(playerIn, itemstack1);
    }
    return itemstack;
    }

    public void onContainerClosed(EntityPlayer playerIn) {
    super.onContainerClosed(playerIn);
    }
    }
    Posted in: Modification Development
  • 0

    posted a message on Getting the type of log for a custom machine recipe?

    made more changes:

    package kenneths_mod.medieval_mod.objects.machines.sawmill;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import net.minecraft.block.BlockPlanks;
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.item.Item;
    import net.minecraft.item.ItemStack;
    
    public class SawmillRecipes {
    	
    	private static final SawmillRecipes INSTANCE = new SawmillRecipes();
    	
    	public static List<SawmillRecipe> recipes = new ArrayList<SawmillRecipe>();
    	public static List<Item> acceptedInputs = new ArrayList<Item>();
    	
    	public static SawmillRecipe refined_oak_plank;
    	public static SawmillRecipe refined_spruce_plank;
    	public static SawmillRecipe refined_birch_plank;
    	
    	public static void init () {
    		refined_oak_plank = new SawmillRecipe(new ItemStack(Blocks.PLANKS, 1, BlockPlanks.EnumType.OAK.getMetadata()), new ItemStack(Items.LEATHER, 1));
    		recipes.add(refined_oak_plank);
    		acceptedInputs.add(refined_oak_plank.input.getItem());
    		
    		refined_spruce_plank = new SawmillRecipe(new ItemStack(Blocks.PLANKS, 1, BlockPlanks.EnumType.SPRUCE.getMetadata()), new ItemStack(Items.BONE, 1));
    		recipes.add(refined_spruce_plank);
    		acceptedInputs.add(refined_spruce_plank.input.getItem());
    		
    		refined_birch_plank = new SawmillRecipe(new ItemStack(Blocks.PLANKS, 1, BlockPlanks.EnumType.BIRCH.getMetadata()), new ItemStack(Items.APPLE, 1));
    		recipes.add(refined_birch_plank);
    		acceptedInputs.add(refined_birch_plank.input.getItem());
    	}
    	
    	public static SawmillRecipes getInstance () {
    		return INSTANCE;
    	}
    	
    	public boolean compareInputOutput (ItemStack slot1, ItemStack slot2) {
    		for(SawmillRecipe recipe : recipes) {
    			if(recipe.input.getItem() == slot1.getItem() && recipe.output.getItem() == slot2.getItem()) {
    				if(recipe.input.getMetadata() == slot1.getMetadata()) {
    					return true;
    				}
    			}
    		}
    		return false;
    	}
    	public ItemStack getOutput (ItemStack input) {
    		for(SawmillRecipe recipe : recipes) {
    			if(recipe.input.getMetadata() == input.getMetadata()) {
    				return recipe.output.copy();
    			}
    		}
    		return ItemStack.EMPTY;
    	}
    }



    package kenneths_mod.medieval_mod.objects.machines.sawmill;
    
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.ITickable;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.util.text.TextComponentTranslation;
    import net.minecraftforge.common.capabilities.Capability;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.ItemStackHandler;
    
    public class SawmillTE extends TileEntity implements ITickable {
    	
    	private ItemStackHandler handler = new  ItemStackHandler(2);
    	private String customName;
    	private int sawTime;
    	
    	@Override
    	public void update() {
    		if(!this.world.isRemote) {
    			
    			if(this.handler.getStackInSlot(0) != ItemStack.EMPTY && this.handler.getStackInSlot(1) != ItemStack.EMPTY) {
    				if(!SawmillRecipes.getInstance().compareInputOutput(this.handler.getStackInSlot(0), this.handler.getStackInSlot(1))) {
    					sawTime = 100;
    				}
    			}
    			
    			if(this.handler.getStackInSlot(1).getCount() < 64) {
    				if(SawmillRecipes.acceptedInputs.contains(this.handler.getStackInSlot(0).getItem())) {
    					this.sawTime--;
    					if(this.handler.getStackInSlot(1) == ItemStack.EMPTY || this.handler.getStackInSlot(1).getCount() == 0) {
    						if(sawTime <= 0) {
    							this.handler.setStackInSlot(1, SawmillRecipes.getInstance().getOutput(this.handler.getStackInSlot(0)).copy());
    							if(this.handler.getStackInSlot(0).getCount() > 1) {
    								this.handler.getStackInSlot(0).shrink(1);
    							} else {
    								this.handler.setStackInSlot(0, ItemStack.EMPTY);
    							}
    							this.sawTime = 100;
    						}
    					} else {
    						if(SawmillRecipes.getInstance().compareInputOutput(this.handler.getStackInSlot(0).copy(), this.handler.getStackInSlot(1).copy())) {
    							if(this.sawTime <= 0) {
    								this.handler.getStackInSlot(1).grow(1);
    								if(this.handler.getStackInSlot(0).getCount() > 1) {
    									this.handler.getStackInSlot(0).shrink(1);
    								} else {
    									this.handler.setStackInSlot(0, ItemStack.EMPTY);
    								}
    								this.sawTime = 100;
    							}
    						}
    					}
    				} else {
    					this.sawTime = 100;
    				}
    			}
    		}
    	}
    	@Override
    	public void readFromNBT(NBTTagCompound compound) {
    		super.readFromNBT(compound);
    		this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
    		this.sawTime = compound.getInteger("ST");
    		if(compound.hasKey("CustomName", 8)) {
    			this.setCustomName(compound.getString("CustomName"));
    		}
    	}
    	@Override
    	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    		super.writeToNBT(compound);
    		compound.setTag("Inventory", this.handler.serializeNBT());
    		compound.setInteger("ST", (short)this.sawTime);
    		if(this.hasCustomName()) {
    			compound.setString("CustomName", this.customName);
    		}
    		return compound;
    	}
    	public boolean hasCustomName () {
    		return this.customName != null && !this.customName.isEmpty();
    	}
    	public void setCustomName(String customName) {
    		this.customName = customName;
    	}
    	@Override
    	public ITextComponent getDisplayName() {
    		return this.hasCustomName() ? new TextComponentString(this.customName) : new TextComponentTranslation("Sawmill");
    	}
    	
    	public int getField (int id) {
    		switch (id) {
    		case 0:
    			return this.sawTime;
    		default:
    			return 0;
    		}
    	}
    	@Override
    	public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
    		if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
    			return true;
    		} else {
    			return false;
    		}
    	}
    	@Override
    	public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
    		if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
    			return (T) this.handler;
    		}
    		return super.getCapability(capability, facing);
    	}
    }



    But it does not seem to work for oak planks. plz help.

    Posted in: Modification Development
  • 0

    posted a message on Getting the type of log for a custom machine recipe?

    Ok I now tried:


    refined_oak_plank = new SawmillRecipe(new ItemStack(Blocks.PLANKS, 1, BlockPlanks.EnumType.OAK.getMetadata()), new ItemStack(Items.ARROW, 1));



    and it seems to work thanks.


    Edit: actually now when I put the planks in it does nothing.... not working

    Posted in: Modification Development
  • 0

    posted a message on Getting the type of log for a custom machine recipe?

    Okay I tried:

    refined_oak_plank = new SawmillRecipe (new ItemStack(BlockPlanks.EnumType.OAK, 1), new ItemStack(Items.ARROW, 1));


    but it gives me an error saying:

    Description Resource Path Location Type
    The constructor ItemStack(BlockPlanks.EnumType, int) is undefined SawmillRecipes.java /Kenneths Mod/src/main/java/kenneths_mod/medieval_mod/objects/machines/sawmill line 27 Java Problem

    Posted in: Modification Development
  • 0

    posted a message on Strange Behaviour from my Sawmill.

    Here is the code for the sawill's block and tile entity:


    package kenneth.kenneths_medieval_mod.init.machines.basic_sawmill;
    
    import kenneth.kenneths_medieval_mod.Main;
    import kenneth.kenneths_medieval_mod.Reference;
    import net.minecraft.block.Block;
    import net.minecraft.block.BlockHorizontal;
    import net.minecraft.block.SoundType;
    import net.minecraft.block.material.Material;
    import net.minecraft.block.properties.IProperty;
    import net.minecraft.block.properties.PropertyBool;
    import net.minecraft.block.properties.PropertyDirection;
    import net.minecraft.block.state.BlockStateContainer;
    import net.minecraft.block.state.IBlockState;
    import net.minecraft.creativetab.CreativeTabs;
    import net.minecraft.entity.EntityLivingBase;
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.init.Items;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.EnumBlockRenderType;
    import net.minecraft.util.EnumFacing;
    import net.minecraft.util.EnumHand;
    import net.minecraft.util.ITickable;
    import net.minecraft.util.Mirror;
    import net.minecraft.util.Rotation;
    import net.minecraft.util.math.BlockPos;
    import net.minecraft.util.text.ITextComponent;
    import net.minecraft.util.text.TextComponentString;
    import net.minecraft.util.text.TextComponentTranslation;
    import net.minecraft.world.World;
    import net.minecraftforge.common.capabilities.Capability;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.ItemStackHandler;
    
    public class BasicSawmill extends Block {
    	public static final PropertyDirection FACING = BlockHorizontal.FACING;
    	
    	public BasicSawmill () {
    		super(Material.WOOD);
    		setUnlocalizedName("basic_sawmill");
    		setRegistryName("basic_sawmill");
    		setHardness(3);
    		setResistance(20);
    		setSoundType(SoundType.WOOD);
    		setCreativeTab(CreativeTabs.DECORATIONS);
    	}
    	
    	@Override
    	public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    		if(!worldIn.isRemote) {
    			playerIn.openGui(Main.instance, Reference.GUI_BASIC_SAWMILL_GUIID, worldIn, pos.getX(), pos.getY(), pos.getZ());
    		}
    		return super.onBlockActivated(worldIn, pos, state, playerIn, hand, facing, hitX, hitY, hitZ);
    	}
    	@Override
    	public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
    		if(!worldIn.isRemote) {
    			IBlockState north = worldIn.getBlockState(pos.north());
                IBlockState south = worldIn.getBlockState(pos.south());
                IBlockState west = worldIn.getBlockState(pos.west());
                IBlockState east = worldIn.getBlockState(pos.east());
                EnumFacing face = (EnumFacing)state.getValue(FACING);
                
                if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH;
                else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH;
                else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST;
                else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST;
                worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
    		}
    	}
    	@Override
    	public boolean hasTileEntity(IBlockState state) {
    		return true;
    	}
    	@Override
    	public TileEntity createTileEntity(World world, IBlockState state) {
    		return new BasicSawmillTE();
    	}
    	
    	//Tile Entity:
    	public static class BasicSawmillTE extends TileEntity implements ITickable {
    		private ItemStackHandler handler = new ItemStackHandler (2);
    		private String customName;
    		
    		private int sawTime;
    		
    		@Override
    		public void update() {
    			if(!this.world.isRemote) {
    				if(this.handler.getStackInSlot(0) != ItemStack.EMPTY) {
    					if(this.handler.getStackInSlot(1) != ItemStack.EMPTY) {
    						if(BasicSawmillRecipes.getInstance().compareInputOutput(this.handler.getStackInSlot(0), this.handler.getStackInSlot(1))) {
    							if(this.sawTime > 0) {
    								this.sawTime--;
    							} else {
    								sawReset();
    							}
    						}
    					} else {
    						if(this.sawTime > 0) {
    							this.sawTime--;
    						} else  {
    							sawReset2();
    						}
    					}
    				} else {
    					this.sawTime = 100;
    				}
    			}
    		}
    		public void sawReset () {
    			this.handler.getStackInSlot(1).grow(1);
    			if(this.handler.getStackInSlot(0).getCount() > 1) {
    				this.handler.getStackInSlot(0).shrink(1);
    			} else {
    				this.handler.setStackInSlot(0, ItemStack.EMPTY);
    			}
    			this.sawTime = 100;
    		}
    		public void sawReset2 () {
    			this.handler.setStackInSlot(1, BasicSawmillRecipes.getInstance().getOutput(this.handler.getStackInSlot(0)));
    			if(this.handler.getStackInSlot(0).getCount() > 1) {
    				this.handler.getStackInSlot(0).shrink(1);
    			} else {
    				this.handler.setStackInSlot(0, ItemStack.EMPTY);
    			}
    			this.sawTime = 100;
    		}
    		
    		@Override
    		public void readFromNBT(NBTTagCompound compound) {
    			super.readFromNBT(compound);
    			this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
    			this.sawTime = compound.getInteger("ST");
    			if(compound.hasKey("CustomName", 8)) {
    				this.setCustomName(compound.getString("CustomName"));
    			}
    		}
    		@Override
    		public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    			super.writeToNBT(compound);
    			compound.setInteger("ST", (short)this.sawTime);
    			compound.setTag("Inventory", this.handler.serializeNBT());
    			if(this.hasCustomName()) compound.setString("CustomName", this.customName);
    			return compound;
    		}
    		
    		public int getField (int id) {
    			switch (id) {
    			case 0:
    				return this.sawTime;
    			default:
    				return 0;
    			}
    		}
    		
    		
    		@Override
    		public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
    			if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
    				return true;
    			} else {
    				return false;
    			}
    		}
    		@Override
    		public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
    			if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) {
    				return (T) this.handler;
    			}
    			return super.getCapability(capability, facing);
    		}
    		
    		public boolean hasCustomName () {
    			return this.customName != null && !this.customName.isEmpty();
    		}
    		public void setCustomName(String customName) {
    			this.customName = customName;
    		}
    		@Override
    		public ITextComponent getDisplayName() {
    			return this.hasCustomName() ? new TextComponentString(this.customName) : new TextComponentTranslation("Basic Sawmill");
    		}
    	}
    	@Override
    	public boolean isOpaqueCube(IBlockState state){
    		return false;
    	}
    	@Override
    	public boolean isFullCube(IBlockState state) {
    		return false;
    	}
    	@Override
    	public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) {
    		return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    	}
    	@Override
    	public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
    		worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
    	}
    	@Override
    	public IBlockState withRotation(IBlockState state, Rotation rot){
    		return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    	}
    	@Override
    	public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
    		return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    	}
    	@Override
    	protected BlockStateContainer createBlockState() {
    		return new BlockStateContainer(this, new IProperty[] {FACING});
    	}
    	@Override
    	public IBlockState getStateFromMeta(int meta) {
    		EnumFacing facing = EnumFacing.getFront(meta);
    		if(facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH;
    		return this.getDefaultState().withProperty(FACING, facing);
    	}
    	@Override
    	public int getMetaFromState(IBlockState state) {
    		return ((EnumFacing)state.getValue(FACING)).getIndex();
    	}
    }
    



    And here is the sawmill's container:


    package kenneth.kenneths_medieval_mod.init.machines.basic_sawmill;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IContainerListener;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.IItemHandler;
    import net.minecraftforge.items.SlotItemHandler;
    
    public class BasicSawmillContainer extends Container {
    	private final BasicSawmill.BasicSawmillTE tileentity;
    	private int sawTime;
    	
    	public BasicSawmillContainer(InventoryPlayer player, BasicSawmill.BasicSawmillTE tileentity) {
    		this.tileentity = tileentity;
    		IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    		
    		this.addSlotToContainer(new SlotItemHandler(handler, 0, 39, 34));
    		this.addSlotToContainer(new SlotItemHandler(handler, 1, 72, 34) {
    			public boolean isItemValid (ItemStack stack) {
    				return false;
    			}
    		});
    		for(int y = 0; y < 3; y++) {
    			for(int x = 0; x < 9; x++) {
    				this.addSlotToContainer(new Slot(player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
    			}
    		}
    		for(int x = 0; x < 9; x++) {
    			this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
    		}
    	}
    	
    	@Override
    	public void detectAndSendChanges() {
    		super.detectAndSendChanges();
    		for(int i = 0; i < this.listeners.size(); i++) {
    			IContainerListener listener = (IContainerListener)this.listeners.get(i);
    			if(this.sawTime != this.tileentity.getField(0)) {
    				listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
    			}
    		}
    		this.sawTime = this.tileentity.getField(2);
    	}
    	
    	@Override
    	public boolean canInteractWith(EntityPlayer playerIn) {
    		return true;
    	}
    	
    	@Override
    	public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
    		ItemStack itemstack = null;
    		Slot slot = (Slot) this.inventorySlots.get(index);
    		if(slot != null && slot.getHasStack()) {
    			ItemStack itemstack1 = slot.getStack();
    			itemstack = itemstack1.copy();
    			if(index < 9) {
    				if(!this.mergeItemStack(itemstack1, 9, (45 - 9), true)) {
    					return ItemStack.EMPTY;
    				}
    			} else if (!this.mergeItemStack(itemstack1, 0, 9, false)) {
    				return ItemStack.EMPTY;
    			}
    			if(itemstack1.getCount() == 0) {
    				slot.putStack(ItemStack.EMPTY);
    			} else {
    				slot.onSlotChanged();
    			}
    			if(itemstack1.getCount() == itemstack.getCount()) {
    				return ItemStack.EMPTY;
    			}
    			slot.onTake(playerIn, itemstack1);
    		}
    		return itemstack;
    	}
    	
    	public void onContainerClosed(EntityPlayer playerIn) {
    		super.onContainerClosed(playerIn);
    	}
    }
    


    And here is the sawmill recipes class:

    package kenneth.kenneths_medieval_mod.init.machines.basic_sawmill;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import net.minecraft.init.Blocks;
    import net.minecraft.init.Items;
    import net.minecraft.item.ItemStack;
    
    public class BasicSawmillRecipes {
    	
    	private static final BasicSawmillRecipes INSTANCE = new BasicSawmillRecipes();
    	public static List<BasicSawmillRecipe> recipes = new ArrayList<BasicSawmillRecipe>();
    	
    	public static BasicSawmillRecipe basic_planks;
    	
    	public static BasicSawmillRecipes getInstance () {
    		return INSTANCE;
    	}
    	
    	public static void init () {
    		basic_planks = new BasicSawmillRecipe(new ItemStack(Items.LEATHER, 1), new ItemStack(Items.ARROW, 1));
    	}
    	public static void register () {
    		recipes.add(basic_planks);
    	}
    	public boolean compareInputOutput (ItemStack slot1, ItemStack slot2) {
    		for(BasicSawmillRecipe recipe : recipes) {
    			if(recipe.input.getItem() == slot1.getItem() && recipe.output.getItem() == slot2.getItem()) {
    				return true;
    			}
    		}
    		return false;
    	}
    	public ItemStack getOutput (ItemStack input) {
    		for(BasicSawmillRecipe recipe : recipes) {
    			if(recipe.input.getItem() == input.getItem()) {
    				return recipe.output;
    			}
    		}
    		return ItemStack.EMPTY;
    	}
    }
    



    And lastly the recipe class:

    package kenneth.kenneths_medieval_mod.init.machines.basic_sawmill;
    
    import net.minecraft.item.ItemStack;
    
    public class BasicSawmillRecipe {
    	public static ItemStack input;
    	public static ItemStack output;
    	
    	public BasicSawmillRecipe (ItemStack input, ItemStack output) {
    		this.input = input;
    		this.output = output;
    	}
    }
    


    The video could probably explain it better than I could:


    note that the input and output items are just placeholders and will be replaced with other items later.

    Also if you spot anything else that can go wrong with my code please tell me. thanks

    Posted in: Modification Development
  • 0

    posted a message on Getting the type of log for a custom machine recipe?

    I am trying to make a sawmill that when people place logs in the sawmill's GUI, it saws the log into its corresponding plank.

    package kenneth.kenneths_medieval_mod.init.machines.basic_sawmill;
    
    import net.minecraft.item.ItemStack;
    
    public class BasicSawmillRecipe {
    	public static ItemStack input;
    	public static ItemStack output;
    	
    	public BasicSawmillRecipe (ItemStack input, ItemStack output) {
    		this.input = input;
    		this.output = output;
    	}
    }
    



    package kenneth.kenneths_medieval_mod.init.machines.basic_sawmill;
    
    import java.util.ArrayList;
    import java.util.List;
    
    import net.minecraft.init.Blocks;
    import net.minecraft.item.ItemStack;
    
    public class BasicSawmillRecipes {
    	public static List<BasicSawmillRecipe> recipes = new ArrayList<BasicSawmillRecipe>();
    	
    	public static BasicSawmillRecipe basic_planks;
    	
    	public static void init () {
    		basic_planks = new BasicSawmillRecipe(new ItemStack(Blocks.LOG, 1), new ItemStack(Blocks.PLANKS, 1));
    	}
    	public static void register () {
    		recipes.add(basic_planks);
    	}
    }
    



    Is there any way to specify what log creates what planks?

    Posted in: Modification Development
  • 0

    posted a message on My block does not save nbt data....

    I am trying to add a custom furnace without a GUI. Start smelting is called when the player right clicks on the furnace while holding an iron ore.

    package kenneths_mod.medieval_mod.init.machines.smelting_furnace;
    
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.tileentity.TileEntity;
    import net.minecraft.util.ITickable;
    import net.minecraftforge.items.ItemStackHandler;
    
    public class SmeltingFurnaceTileEntity extends TileEntity implements ITickable {
    	
    	public ItemStackHandler smelting_furnace_inventory = new ItemStackHandler (3);
    	//Slot 0 is input, while slot 1 is the output item, and 2 is the stored output item.
    	
    	public boolean smelting;
    	public float maxFuel = 2000f;
    	public float burnTime = 0f;
    	public float fuelLeft = 200f;
    	
    	@Override
    	public void update() {
    		if (fuelLeft > 0) {
    			if (smelting == true) {
    				if (burnTime > 0) {
    					burnTime--;
    					fuelLeft--;
    				} else if (burnTime <= 0){
    					StopSmelting ();
    				}
    			}
    		}
    		markDirty();
    	}
    	public void StartSmelting (ItemStack input) {
    		if (fuelLeft > 0) {
    			for(int i = 0; i < SmeltingFurnaceRecipes.recipes.size(); i++) {
    				if(SmeltingFurnaceRecipes.recipes.get(i).input == input.getItem()) {
    					smelting_furnace_inventory.setStackInSlot(0, input);
    					burnTime = 100f;
    					smelting_furnace_inventory.setStackInSlot(1, new ItemStack (SmeltingFurnaceRecipes.recipes.get(i).output, 1));
    					smelting = true;
    				}
    			}
    		}
    	}
    	public void StopSmelting () {
    		smelting_furnace_inventory.setStackInSlot(2, new ItemStack(smelting_furnace_inventory.getStackInSlot(1).getItem(), 1));
    		smelting = false;
    	}
    	
    	@Override
    	public void readFromNBT(NBTTagCompound compound) {
    		super.readFromNBT(compound);
    		this.smelting_furnace_inventory.deserializeNBT(compound.getCompoundTag("SFI"));
    		this.burnTime = compound.getFloat("BT");
    		this.fuelLeft = compound.getFloat("FL");
    	}
    	@Override
    	public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    		compound.setTag("SFI", this.smelting_furnace_inventory.serializeNBT());
    		compound.setFloat("BT", burnTime);
    		compound.setFloat("FL", fuelLeft);
    		return compound;
    	}
    	
    	public void addFuel (float toAdd) {
    		if ((fuelLeft + toAdd) < maxFuel) {
    			fuelLeft += toAdd;
    		}
    	}
    }



    What is happening is that it does not save the value "fuelLeft"

    I do not know if it saves anything else....

    Posted in: Modification Development
  • 0

    posted a message on Add item to player's inventory or drop item if there is no more room.

    I am making a mod that adds a special smelting furnace for the purpose of making it more difficult to smelt metals.


    The furnace has no GUI, so in order to retrieve the metal ingot from the furnace, the player must use a set of tongs (an item I am adding in my mod).


    What I need help with is getting the ingot to be added to the player's inventory if there is room for it, or dropping it on the floor if there is no more room in the player's inventory. Can I get some help please?

    Posted in: Modification Development
  • 0

    posted a message on Getting an index out of bounds exception... need help.

    Says something about line 76:


    package kenneths_mods.kenneths_medieval_mod.init.objects.machines.smeltingfurnace;
    
    import net.minecraft.entity.player.EntityPlayer;
    import net.minecraft.entity.player.InventoryPlayer;
    import net.minecraft.inventory.Container;
    import net.minecraft.inventory.IContainerListener;
    import net.minecraft.inventory.Slot;
    import net.minecraft.item.ItemStack;
    import net.minecraftforge.fml.relauncher.Side;
    import net.minecraftforge.fml.relauncher.SideOnly;
    import net.minecraftforge.items.CapabilityItemHandler;
    import net.minecraftforge.items.IItemHandler;
    import net.minecraftforge.items.SlotItemHandler;
    
    public class SmeltingFurnaceContainer extends Container {
    	private final SmeltingFurnaceTileEntity tileentity;
    	private int cookTime, totalCookTime, burnTime, currentBurnTime;
    	public SmeltingFurnaceContainer (InventoryPlayer player, SmeltingFurnaceTileEntity tileentity) {
    		this.tileentity = tileentity;
    		IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
    		this.addSlotToContainer(new SlotItemHandler(handler, 0, 26, 11));
    		this.addSlotToContainer(new SlotItemHandler(handler, 1, 26, 59));
    		this.addSlotToContainer(new SlotItemHandler(handler, 2, 7, 35));
    		this.addSlotToContainer(new SlotItemHandler(handler, 3, 81, 36));
    		
    		for(int y = 0; y < 3; y++) {
    			for(int x = 0; x < 9; x++) {
    				this.addSlotToContainer(new Slot(player, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
    			}
    		}
    		
    		for(int x = 0; x < 9; x++) {
    			this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
    		}
    	}
    	
    	@Override
    	public void detectAndSendChanges() {
    		super.detectAndSendChanges();
    		for(int i = 0; i < this.listeners.size(); ++i) {
    			IContainerListener listener = (IContainerListener)this.listeners.get(i);
    			if(this.cookTime != this.tileentity.getField(2)) listener.sendWindowProperty(this, 2, this.tileentity.getField(2));
    			if(this.burnTime != this.tileentity.getField(0)) listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
    			if(this.currentBurnTime != this.tileentity.getField(1)) listener.sendWindowProperty(this, 1, this.tileentity.getField(1));
    			if(this.totalCookTime != this.tileentity.getField(3)) listener.sendWindowProperty(this, 3, this.tileentity.getField(3));
    		}
    		this.cookTime = this.tileentity.getField(2);
    		this.burnTime = this.tileentity.getField(0);
    		this.currentBurnTime = this.tileentity.getField(1);
    		this.totalCookTime = this.tileentity.getField(3);
    	}
    	
    	@Override
    	@SideOnly(Side.CLIENT)
    	public void updateProgressBar(int id, int data) {
    		this.tileentity.setField(id, data);
    	}
    	
    	@Override
    	public boolean canInteractWith(EntityPlayer playerIn) {
    		return this.tileentity.isUsableByPlayer(playerIn);
    	}
    	
    	@Override
    	public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
    		ItemStack stack = ItemStack.EMPTY;
    		Slot slot = (Slot)this.inventorySlots.get(index);
    		
    		if(slot != null && slot.getHasStack()) {
    			ItemStack stack1 = slot.getStack();
    			stack = stack1.copy();
    			if(index == 3) {
    				if(!this.mergeItemStack(stack1, 4, 40, true)) return ItemStack.EMPTY;
    				slot.onSlotChange(stack1, stack);
    			} else if (index != 2 && index != 1 && index != 0) {
    //Line 76				Slot slot1 = (Slot)this.inventorySlots.get(index + 1);
    				if(!SmeltingFurnaceRecipes.getInstance().getSmeltingResult(stack1, slot1.getStack()).isEmpty()) {
    					if(!this.mergeItemStack(stack1, 0, 2, false)) {
    						return ItemStack.EMPTY;
    					} else if (SmeltingFurnaceTileEntity.isItemFuel(stack1)) {
    						if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
    					} else if (SmeltingFurnaceTileEntity.isItemFuel(stack1)) {
    						if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
    					} else if (SmeltingFurnaceTileEntity.isItemFuel(stack1)) {
    						if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
    					} else if (index >= 4 && index < 31) {
    						if(!this.mergeItemStack(stack1, 31, 40, false)) return ItemStack.EMPTY;
    					} else if (index >= 31 && index < 40 && !this.mergeItemStack(stack1, 4, 31, false)) {
    						return ItemStack.EMPTY;
    					}
    				}
    			} else if (!this.mergeItemStack(stack1, 4, 40, false)) {
    				return ItemStack.EMPTY;
    			}
    			if(stack1.isEmpty()) {
    				slot.putStack(ItemStack.EMPTY);
    			}
    			if(stack1.isEmpty()) {
    				slot.onSlotChanged();
    			}
    			if(stack1.getCount() == stack.getCount()) return ItemStack.EMPTY;
    			slot.onTake(playerIn, stack1);
    		}
    		return stack;
    	}
    }



    what is wrong?

    For those who need to know I am using the scripts from harrys tech reviews tutorial:
    https://github.com/HarryTechRevs/Minecraft-Modding-1.12/blob/master/main/java/harry/mods/tutorial/blocks/containers/ContainerSinteringFurnace.java

    Posted in: Modification Development
  • To post a comment, please .