Posted October 18, 201410 yr I just finished working thorough a tutorial and trying a few things out for my self on making a dual-input machine. It works just fine but it has a problem I seem to be unable to fix. I can put items into it, and after combining one set of items it changes the block face back to its inactive state even if it has more to process(it continues to process) Here is the, blockclass: package robo51.newt.blocks; import java.util.Random; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.util.MathHelper; import net.minecraft.world.World; import robo51.newt.Newt; import robo51.newt.lib.Constants; import robo51.newt.tileentities.TileEntityFurnaceBlock; import robo51.newt.tileentities.TileEntityPresserBlock; import cpw.mods.fml.common.network.internal.FMLNetworkHandler; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class PresserBlock extends BlockContainer { @SideOnly(Side.CLIENT) private IIcon iconFace; @SideOnly(Side.CLIENT) private IIcon iconTop; private static boolean keepInventory = false; private Random rand; private final boolean isActive; public PresserBlock(boolean blockState) { super(Material.iron); setStepSound(soundTypeMetal); setHardness(4.0F); setResistance(5.0F); rand = new Random(); isActive = blockState; } @Override public TileEntity createNewTileEntity(World world, int meta) { return new TileEntityPresserBlock(); } @Override public boolean hasTileEntity(int metadata) { return true; } @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister IconRegistry) { this.blockIcon = IconRegistry.registerIcon(Constants.MODID + ":" + "chassisBlock"); this.iconFace = IconRegistry.registerIcon(Constants.MODID + ":" + (this.isActive ? "presserBlock_face_active" : "presserBlock_face_idle")); this.iconTop = IconRegistry.registerIcon(Constants.MODID + ":" + "chassisBlock_top"); } @SideOnly(Side.CLIENT) public IIcon getIcon(int side, int meta) { if (meta == 0 && side == 3) { return this.iconFace; } else if (side == 1) { return this.iconTop; } else if (side == 0) { return this.iconTop; } else if (side != meta) { return this.blockIcon; } return this.iconFace; } @SideOnly(Side.CLIENT) public void onBlockAdded(World world, int x, int y, int z) { super.onBlockAdded(world, x, y, z); this.setDefaultDirection(world, x, y, z); } private void setDefaultDirection(World world, int x, int y, int z) { if(!world.isRemote) { Block dir = world.getBlock(x, y, z -1); Block dir1 = world.getBlock(x, y, z +1); Block dir2 = world.getBlock(x -1, y, z); Block dir3 = world.getBlock(x +1, y, z); byte byte0 = 3; if(dir.func_149730_j() && !dir1.func_149730_j()) { byte0 = 3; } if(dir1.func_149730_j() && !dir.func_149730_j()) { byte0 = 2; } if(dir2.func_149730_j() && !dir3.func_149730_j()) { byte0 = 5; } if(dir3.func_149730_j() && !dir2.func_149730_j()) { byte0 = 4; } world.setBlockMetadataWithNotify(x, y, z, byte0, 2); } } public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemstack) { int dir = MathHelper.floor_double((double)(entity.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; if(dir == 0) world.setBlockMetadataWithNotify(x, y, z, 2, 2); if(dir == 1) world.setBlockMetadataWithNotify(x, y, z, 5, 2); if(dir == 2) world.setBlockMetadataWithNotify(x, y, z, 3, 2); if(dir == 3) world.setBlockMetadataWithNotify(x, y, z, 4, 2); if(itemstack.hasDisplayName()) { ((TileEntityFurnaceBlock)world.getTileEntity(x, y, z)).setGuiDisplayName(itemstack.getDisplayName()); } } public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { if (world.isRemote) { return true; }else if (!player.isSneaking()) { TileEntityPresserBlock entity = (TileEntityPresserBlock) world.getTileEntity(x, y, z); if (entity != null) { FMLNetworkHandler.openGui(player, Newt.instance, ModBlocks.guiIdPresserBlock, world, x, y, z); } return true; }else { return false; } } public void breakBlock(World world, int x, int y, int z, Block oldblock, int oldMetadata) { if(!keepInventory) { TileEntityPresserBlock tileentity = (TileEntityPresserBlock) world.getTileEntity(x, y, z); if(tileentity != null) { for(int i = 0; i < tileentity.getSizeInventory(); i++) { ItemStack itemstack = tileentity.getStackInSlot(i); if(itemstack != null) { float f = this.rand.nextFloat() * 0.8F + 0.1F; float f1 = this.rand.nextFloat() * 0.8F + 0.1F; float f2 = this.rand.nextFloat() * 0.8F + 0.1F; while(itemstack.stackSize > 0) { int j = this.rand.nextInt(21) + 10; if(j > itemstack.stackSize) { j = itemstack.stackSize; } itemstack.stackSize -= j; EntityItem item = new EntityItem(world, (double)((float)x + f), (double)((float)y + f1), (double)((float)z + f2), new ItemStack(itemstack.getItem(), j, itemstack.getItemDamage())); if(itemstack.hasTagCompound()) { item.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy()); } world.spawnEntityInWorld(item); } } } world.func_147453_f(x, y, z, oldblock); } } super.breakBlock(world, x, y, z, oldblock, oldMetadata); } public Item getItem(World world, int x, int y, int z) { return Item.getItemFromBlock(ModBlocks.presserBlock_Idle); } public static void updatePresserBlockState(boolean active, World worldObj, int xCoord, int yCoord, int zCoord) { int i = worldObj.getBlockMetadata(xCoord, yCoord, zCoord); TileEntity tilentity = worldObj.getTileEntity(xCoord, yCoord, zCoord); keepInventory = true; if(active) { worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.presserBlock_Active); } else { worldObj.setBlock(xCoord, yCoord, zCoord, ModBlocks.presserBlock_Idle); } keepInventory = false; worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, i, 2); if(tilentity != null) { tilentity.validate(); worldObj.setTileEntity(xCoord, yCoord, zCoord, tilentity); } } } tileentityclass: package robo51.newt.tileentities; import robo51.newt.blocks.PresserBlock; import robo51.newt.crafting.PresserBlockRecipes; import robo51.newt.items.ModItems; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Items; import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; public class TileEntityPresserBlock extends TileEntity implements ISidedInventory { public static final String publicName = "tileEntityPresserBlock"; private String name = "tileEntityPresserBlock"; private ItemStack slots[]; public int dualPower; public int dualCookTime; public static final int maxPower = 1001; public static final int pressingSpeed = 100; private static final int[] slots_top = new int[] {0, 1}; private static final int[] slots_bottom = new int[] {3}; private static final int[] slots_side = new int[] {2}; public String getName() { return name; } public TileEntityPresserBlock() { slots = new ItemStack[4]; } @Override public int getSizeInventory() { return slots.length; } @Override public ItemStack getStackInSlot(int i) { return slots; } @Override public ItemStack decrStackSize(int i, int j) { if (slots != null) { if (slots.stackSize <= j) { ItemStack itemstack = slots; slots = null; return itemstack; } ItemStack itemstack1 = slots.splitStack(j); if (slots.stackSize == 0) { slots = null; } return itemstack1; } else { return null; } } @Override public ItemStack getStackInSlotOnClosing(int i) { if (slots != null) { ItemStack itemstack = slots; slots = null; return itemstack; } else { return null; } } @Override public void setInventorySlotContents(int i, ItemStack itemstack) { slots = itemstack; if(itemstack != null && itemstack.stackSize > getInventoryStackLimit()) { itemstack.stackSize = getInventoryStackLimit(); } } @Override public String getInventoryName() { return this.hasCustomInventoryName() ? this.name : "container.presserBlock"; } @Override public boolean hasCustomInventoryName() { return this.name != null && this.name.length() > 0; } @Override public int getInventoryStackLimit() { return 64; } @Override public boolean isUseableByPlayer(EntityPlayer player) { if (worldObj.getTileEntity(xCoord, yCoord, zCoord) != this) { return false; } else { return player.getDistanceSq((double)xCoord + 0.5D, (double)yCoord + 0.5D, (double)zCoord + 0.5D) <= 64; } } public void openInventory() {} public void closeInventory() {} @Override public boolean isItemValidForSlot(int i, ItemStack itemstack) { return i == 3 ? false : (i == 2 ? hasItemPower(itemstack) : true); } public boolean hasItemPower(ItemStack itemstack) { return getItemPower(itemstack) > 0; } private static int getItemPower (ItemStack itemstack) { if (itemstack == null) { return 0; } else { Item item = itemstack.getItem(); if (item == ModItems.redcoalItem) return 100; return 0; } } public void readFromNBT (NBTTagCompound nbt) { super.readFromNBT(nbt); NBTTagList list = nbt.getTagList("Items", 10); slots = new ItemStack[getSizeInventory()]; for (int i = 0; i < list.tagCount(); i++) { NBTTagCompound nbt1 = (NBTTagCompound)list.getCompoundTagAt(i); byte b0 = nbt1.getByte("Slot"); if (b0 >= 0 && b0 < slots.length) { slots[b0] = ItemStack.loadItemStackFromNBT(nbt1); } } dualPower = nbt.getShort("PowerTime"); dualCookTime = nbt.getShort("CookTime"); } public void writeToNBT(NBTTagCompound nbt) { super.writeToNBT(nbt); nbt.setShort("PowerTime", (short)dualPower); nbt.setShort("CookTime", (short)dualCookTime); NBTTagList list = new NBTTagList(); for (int i = 0; i < slots.length; i++) { if (slots != null) { NBTTagCompound nbt1 = new NBTTagCompound(); nbt1.setByte("Slot", (byte)i); slots.writeToNBT(nbt1); list.appendTag(nbt1); } } nbt.setTag("Items", list); } @Override public int[] getAccessibleSlotsFromSide(int i) { return i == 0 ? slots_bottom : (i == 1 ? slots_top : slots_side); } @Override public boolean canInsertItem(int var1, ItemStack itemstack, int var3) { return this.isItemValidForSlot(var1, itemstack); } @Override public boolean canExtractItem(int i, ItemStack itemstack, int j) { return j != 0 || i != 1 || itemstack.getItem() == Items.bucket; } public int getPresserProgressScaled(int i) { return (dualCookTime * i) / this.pressingSpeed; } public int getPowerRemainingScaled(int i) { return (dualPower * i) / maxPower; } private boolean canPress() { if (slots[0] == null || slots[1] == null) { return false; } ItemStack itemstack = PresserBlockRecipes.getPressingResult(slots[0].getItem(), slots[1].getItem()); if (itemstack == null) { return false; } if (slots[3] == null) { return true; } if (!slots[3].isItemEqual(itemstack)) { return false; } if (slots[3].stackSize < getInventoryStackLimit() && slots[3].stackSize < slots[3].getMaxStackSize()) { return true; } else { return slots[3].stackSize < itemstack.getMaxStackSize(); } } private void pressItem() { if (canPress()) { ItemStack itemstack = PresserBlockRecipes.getPressingResult(slots[0].getItem(), slots[1].getItem()); if (slots[3] == null) { slots[3] = itemstack.copy(); } else if (slots[3].isItemEqual(itemstack)) { slots[3].stackSize += itemstack.stackSize; } for (int i = 0; i < 2; i++) { if (slots.stackSize <= 0) { slots = new ItemStack(slots.getItem().setFull3D()); }else{ slots.stackSize--; } if (slots.stackSize <= 0){ slots = null; } } } } public boolean hasPower() { return dualPower > 0; } public boolean isPressing() { return this.dualCookTime > 0; } public void updateEntity() { boolean flag = this.hasPower(); boolean flag1= false; if(hasPower() && this.isPressing()) { this.dualPower--; } if(!worldObj.isRemote) { if (this.hasItemPower(this.slots[2]) && this.dualPower < (this.maxPower - this.getItemPower(this.slots[2]))) { this.dualPower += getItemPower(this.slots[2]); if(this.slots[2] != null) { flag1 = true; this.slots[2].stackSize--; if(this.slots[2].stackSize == 0) { this.slots[2] = this.slots[2].getItem().getContainerItem(this.slots[2]); } } } if (this.hasPower() && this.canPress()) { this.dualCookTime++; if (this.dualCookTime == this.pressingSpeed) { this.dualCookTime = 0; this.pressItem(); flag1 = true; } } else { this.dualCookTime = 0; } if (flag != this.isPressing()) { flag1 = true; PresserBlock.updatePresserBlockState(this.isPressing(), this.worldObj, this.xCoord, this.yCoord, this.zCoord); } } if (flag1) { this.markDirty(); } } } i'm pretty sure the slots thing is related to isItemValidForSlot but I can't wrap my head around how I would fix it. I'm not trying to be rude it just comes out that way sometimes. I'm here to try and learn as much as I can, won't you join me?
October 18, 201410 yr Author I managed to fix my slot problem. But I'm still having trouble with the block states changes. I've tried a few different things but nothing has worked as of yet. Does anyone have any ideas? I'm not trying to be rude it just comes out that way sometimes. I'm here to try and learn as much as I can, won't you join me?
October 20, 201410 yr Author Any help on this would be appreciated. I'm not trying to be rude it just comes out that way sometimes. I'm here to try and learn as much as I can, won't you join me?
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.