Advertisement
Exokem

Untitled

Mar 31st, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 28.14 KB | None | 0 0
  1. //Block
  2. public class MachineArcFurnace extends BlockBase {
  3.  
  4.     public static final PropertyDirection FACING = BlockHorizontal.FACING;
  5.     private static final PropertyBool ACTIVE = PropertyBool.create("burning");
  6.  
  7.     public MachineArcFurnace() {
  8.  
  9.         super("arc_furnace", Material.IRON);
  10.         setSoundType(SoundType.METAL);
  11.         this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(ACTIVE, false));
  12.     }
  13.  
  14.     public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
  15.         return new ItemStack(ExkvaBlocks.arcFurnace);
  16.     }
  17.  
  18.     @Override
  19.     public Item getItemDropped(IBlockState state, Random rand, int fortune) {
  20.         return Item.getItemFromBlock(ExkvaBlocks.arcFurnace);
  21.     }
  22.  
  23.     @Override
  24.     public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  25.         super.breakBlock(worldIn, pos, state);
  26.     }
  27.  
  28.     @Override
  29.     public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
  30.  
  31.         if(!worldIn.isRemote) {
  32.             playerIn.openGui(Exkva.INSTANCE, Exkva.GUI_ARC_FURNACE, worldIn, pos.getX(), pos.getY(), pos.getZ());
  33.         }
  34.  
  35.         return true;
  36.     }
  37.  
  38.     @Override
  39.     public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) {
  40.  
  41.         if(!worldIn.isRemote) {
  42.             IBlockState north, south, east, west;
  43.             north = worldIn.getBlockState(pos.north());
  44.             south = worldIn.getBlockState(pos.south());
  45.             east = worldIn.getBlockState(pos.east());
  46.             west = worldIn.getBlockState(pos.west());
  47.             EnumFacing face = (EnumFacing) state.getValue(FACING);
  48.  
  49.             if (face == EnumFacing.NORTH && north.isFullBlock() && south.isFullBlock()) {
  50.                 face = EnumFacing.SOUTH;
  51.             } else if (face == EnumFacing.SOUTH && south.isFullBlock() && north.isFullBlock()) {
  52.                 face = EnumFacing.NORTH;
  53.             } else if (face == EnumFacing.WEST && west.isFullBlock() && east.isFullBlock()) {
  54.                 face = EnumFacing.EAST;
  55.             } else if (face == EnumFacing.EAST && east.isFullBlock() && west.isFullBlock()) {
  56.                 face = EnumFacing.WEST;
  57.             }
  58.  
  59.             worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
  60.         }
  61.     }
  62.  
  63.     public static void setState(boolean active, World worldIn, BlockPos pos) {
  64.  
  65.         IBlockState state = worldIn.getBlockState(pos);
  66.         TileEntity tileEntity = worldIn.getTileEntity(pos);
  67.  
  68. //        if(active) {
  69. //            worldIn.setBlockState(pos, ExkvaBlocks.arcFurnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(ACTIVE, true), 3);
  70. //        } else worldIn.setBlockState(pos, ExkvaBlocks.arcFurnace.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(ACTIVE, false), 3);
  71.  
  72.         if(tileEntity != null) {
  73.             tileEntity.validate();
  74.             worldIn.setTileEntity(pos, tileEntity);
  75.         }
  76.     }
  77.  
  78.     @Override
  79.     public boolean hasTileEntity(IBlockState state) {
  80.         return true;
  81.     }
  82.  
  83.     @Override
  84.     public TileEntity createTileEntity(World world, IBlockState state) {
  85.         return new TileEntityArcFurnace();
  86.     }
  87.  
  88.     @Override
  89.     public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
  90.         return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
  91.     }
  92.  
  93.     @Override
  94.     public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack) {
  95.         worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
  96.     }
  97.  
  98. //    @Override
  99. //    public void breakBlock(World worldIn, BlockPos pos, IBlockState state) {
  100. //        TileEntityArcFurnace tileEntityArcFurnace = (TileEntityArcFurnace) worldIn.getTileEntity(pos);
  101. //        InventoryHelper.dropInventoryItems(worldIn, pos, tileEntityArcFurnace);
  102. //        super.breakBlock(worldIn, pos, state);
  103. //    }
  104.  
  105.     @Override
  106.     public EnumBlockRenderType getRenderType(IBlockState state) {
  107.         return EnumBlockRenderType.MODEL;
  108.     }
  109.  
  110.     @Override
  111.     public IBlockState withRotation(IBlockState state, Rotation rot) {
  112.         return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING)));
  113.     }
  114.  
  115.     @Override
  116.     public IBlockState withMirror(IBlockState state, Mirror mirrorIn) {
  117.         return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING)));
  118.     }
  119.  
  120.     @Override
  121.     protected BlockStateContainer createBlockState() {
  122.         return new BlockStateContainer(this, new IProperty[] {ACTIVE, FACING});
  123.     }
  124.  
  125.     @Override
  126.     public IBlockState getStateFromMeta(int meta) {
  127.         EnumFacing facing = EnumFacing.getFront(meta);
  128.         if(facing.getAxis() == EnumFacing.Axis.Y) {
  129.             facing = EnumFacing.NORTH;
  130.         }
  131.         return this.getDefaultState().withProperty(FACING, facing);
  132.     }
  133.  
  134.     @Override
  135.     public int getMetaFromState(IBlockState state) {
  136.         return ((EnumFacing) state.getValue(FACING)).getIndex();
  137.     }
  138. }
  139.  
  140. //Container
  141. public class ContainerArcFurnace extends Container {
  142.     private final TileEntityArcFurnace tileentity;
  143.     private int cookTime, totalCookTime, burnTime, currentBurnTime;
  144.  
  145.     public ContainerArcFurnace(InventoryPlayer player, TileEntityArcFurnace tileentity) {
  146.         this.tileentity = tileentity;
  147.         IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
  148.  
  149.         this.addSlotToContainer(new SlotItemHandler(handler, 0, 25, 23)); //input1
  150.         this.addSlotToContainer(new SlotItemHandler(handler, 1, 50, 23)); //input2
  151.         this.addSlotToContainer(new SlotItemHandler(handler, 2, 37, 45)); //input3
  152.         this.addSlotToContainer(new SlotItemHandler(handler, 3, 90, 58)); //fuel
  153.         this.addSlotToContainer(new SlotItemHandler(handler, 4, 133, 33)); //output
  154.  
  155.         for(int y = 0; y < 3; y++) {
  156.             for(int x = 0; x < 9; x++) {
  157.                 this.addSlotToContainer(new Slot(player, x + y*9 + 9, 8 + x*18, 84 + y*18));
  158.             }
  159.         }
  160.  
  161.         for(int x = 0; x < 9; x++) {
  162.             this.addSlotToContainer(new Slot(player, x, 8 + x * 18, 142));
  163.         }
  164.     }
  165.  
  166.     @Override
  167.     public void detectAndSendChanges() {
  168.         super.detectAndSendChanges();
  169.  
  170.         for(int i = 0; i < this.listeners.size(); ++i) {
  171.             IContainerListener listener = (IContainerListener)this.listeners.get(i);
  172.  
  173.             if(this.cookTime != this.tileentity.getField(2)) { listener.sendWindowProperty(this, 2, this.tileentity.getField(2)); }
  174.             if(this.burnTime != this.tileentity.getField(0)) { listener.sendWindowProperty(this, 0, this.tileentity.getField(0)); }
  175.             if(this.currentBurnTime != this.tileentity.getField(1)) { listener.sendWindowProperty(this, 1, this.tileentity.getField(1)); }
  176.             if(this.totalCookTime != this.tileentity.getField(3)) { listener.sendWindowProperty(this, 3, this.tileentity.getField(3)); }
  177.         }
  178.  
  179.         this.cookTime = this.tileentity.getField(2);
  180.         this.burnTime = this.tileentity.getField(0);
  181.         this.currentBurnTime = this.tileentity.getField(1);
  182.         this.totalCookTime = this.tileentity.getField(3);
  183.     }
  184.  
  185.     @Override
  186.     @SideOnly(Side.CLIENT)
  187.     public void updateProgressBar(int id, int data) {
  188.         this.tileentity.setField(id, data);
  189.     }
  190.  
  191.     @Override
  192.     public boolean canInteractWith(EntityPlayer playerIn) {
  193.         return this.tileentity.isUsableByPlayer(playerIn);
  194.     }
  195.  
  196.     @Override
  197.     public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
  198.         ItemStack stack = ItemStack.EMPTY;
  199.         Slot slot = (Slot)this.inventorySlots.get(index);
  200.  
  201.         if(slot != null && slot.getHasStack()) {
  202.             ItemStack stack1 = slot.getStack();
  203.             stack = stack1.copy();
  204.  
  205.             if(index == 3) {
  206.                 if(!this.mergeItemStack(stack1, 4, 40, true)) return ItemStack.EMPTY;
  207.                 slot.onSlotChange(stack1, stack);
  208.             }
  209.             else if(index != 2 && index != 1 && index != 0) {
  210.                 Slot slot1 = (Slot) this.inventorySlots.get(index + 1);
  211.                 Slot slot2 = (Slot) this.inventorySlots.get(index + 2);
  212.  
  213.                 if(!RecipeArcFurnace.getInstance().getResult(stack1, slot1.getStack(), slot2.getStack()).isEmpty()) {
  214.                     if(!this.mergeItemStack(stack1, 0, 2, false)) {
  215.                         return ItemStack.EMPTY;
  216.                     }
  217.                     else if(TileEntityArcFurnace.isItemFuel(stack1)) {
  218.                         if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
  219.                     }
  220.                     else if(TileEntityArcFurnace.isItemFuel(stack1)) {
  221.                         if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
  222.                     }
  223.                     else if(TileEntityArcFurnace.isItemFuel(stack1)) {
  224.                         if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
  225.                     }
  226.                     else if(index >= 4 && index < 31) {
  227.                         if(!this.mergeItemStack(stack1, 31, 40, false)) return ItemStack.EMPTY;
  228.                     }
  229.                     else if(index >= 31 && index < 40 && !this.mergeItemStack(stack1, 4, 31, false)) {
  230.                         return ItemStack.EMPTY;
  231.                     }
  232.                 }
  233.             }
  234.             else if(!this.mergeItemStack(stack1, 4, 40, false)) {
  235.                 return ItemStack.EMPTY;
  236.             }
  237.             if(stack1.isEmpty()) {
  238.                 slot.putStack(ItemStack.EMPTY);
  239.             }
  240.             else {
  241.                 slot.onSlotChanged();
  242.  
  243.             }
  244.             if(stack1.getCount() == stack.getCount()) return ItemStack.EMPTY;
  245.             slot.onTake(playerIn, stack1);
  246.         }
  247.         return stack;
  248.     }
  249.  
  250. //TileEntity
  251. public class TileEntityArcFurnace extends TileEntity implements ITickable, ISidedInventory {
  252.  
  253.     private NonNullList<ItemStack> inventory;
  254.  
  255.     private static final int[] TOP = new int[] { 3 };
  256.     private static final int[] SIDE_RIGHT = new int[] { 0 };
  257.     private static final int[] BACK = new int[] { 2 };
  258.     private static final int[] SIDE_LEFT = new int[] { 1 };
  259.     private static final int[] BOTTOM = new int[] { 4 };
  260.  
  261.     private static final int IN1 = 0;
  262.     private static final int IN2 = 1;
  263.     private static final int IN3 = 2;
  264.     private static final int FUEL = 3;
  265.     private static final int OUT = 4;
  266.  
  267.     private int furnaceBurnTime;
  268.     private int currentItemBurnTime;
  269.     private int cookTime;
  270.     private int totalCookTime;
  271.  
  272.     private String customName;
  273.  
  274.     IItemHandler handlerTop;
  275.     IItemHandler handlerRight;
  276.     IItemHandler handlerBack;
  277.     IItemHandler handlerLeft;
  278.     IItemHandler handlerBottom;
  279.  
  280.     public TileEntityArcFurnace() {
  281.         this.inventory = NonNullList.withSize(5, ItemStack.EMPTY);
  282.         this.handlerTop = new SidedInvWrapper(this, EnumFacing.UP);
  283.         this.handlerRight = new SidedInvWrapper(this, EnumFacing.WEST);
  284.         this.handlerBack = new SidedInvWrapper(this, EnumFacing.SOUTH);
  285.         this.handlerLeft = new SidedInvWrapper(this, EnumFacing.EAST);
  286.         this.handlerBottom = new SidedInvWrapper(this, EnumFacing.DOWN);
  287.     }
  288.  
  289.  
  290.     @Override
  291.     public int getSizeInventory() {
  292.         return this.inventory.size();
  293.     }
  294.  
  295.     @Override
  296.     public boolean isEmpty() {
  297.  
  298.         for(ItemStack stack : this.inventory) {
  299.             if(!stack.isEmpty()) {
  300.                 return false;
  301.             }
  302.         }
  303.  
  304.         return true;
  305.     }
  306.  
  307.     @Override
  308.     public ItemStack getStackInSlot(int index) {
  309.         return (ItemStack) this.inventory.get(index);
  310.     }
  311.  
  312.     @Override
  313.     public ItemStack decrStackSize(int index, int count) {
  314.         return ItemStackHelper.getAndSplit(this.inventory, index, count);
  315.     }
  316.  
  317.     @Override
  318.     public ItemStack removeStackFromSlot(int index) {
  319.         return ItemStackHelper.getAndRemove(this.inventory, index);
  320.     }
  321.  
  322.     @Override
  323.     public void setInventorySlotContents(int index, ItemStack stack) {
  324.  
  325.         ItemStack current = (ItemStack) this.inventory.get(index);
  326.         boolean flag = !stack.isEmpty() && stack.isItemEqual(current) && ItemStack.areItemStackTagsEqual(stack, current);
  327.         this.inventory.set(index, stack);
  328.  
  329.         if(stack.getCount() > this.getInventoryStackLimit()) { stack.setCount(this.getInventoryStackLimit()); }
  330.         if(index == 0 && !flag) {
  331.             ItemStack in2 = this.inventory.get(index + 1);
  332.             ItemStack in3 = this.inventory.get(index + 2);
  333.             this.totalCookTime = this.getCookTime(stack, in2, in3);
  334.             this.cookTime = 0;
  335.             this.markDirty();
  336.         }
  337.     }
  338.  
  339.     @Override
  340.     public String getName() {
  341.         return this.hasCustomName() ? this.customName : "container.arc_furnace";
  342.     }
  343.  
  344.     @Override
  345.     public boolean hasCustomName() {
  346.         return this.customName != null && !this.customName.isEmpty();
  347.     }
  348.  
  349.     public void setCustomName(String name) { this.customName = name; }
  350.  
  351.     public void readFromNBT(NBTTagCompound compound) {
  352.         super.readFromNBT(compound);
  353.         this.inventory = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
  354.         ItemStackHelper.loadAllItems(compound, this.inventory);
  355.         this.furnaceBurnTime = compound.getInteger("BurnTime");
  356.         this.cookTime = compound.getInteger("CookTime");
  357.         this.totalCookTime = compound.getInteger("CookTimeTotal");
  358.         this.currentItemBurnTime = getItemBurnTime((ItemStack)this.inventory.get(1));
  359.         if (compound.hasKey("CustomName", 8)) {
  360.             this.customName = compound.getString("CustomName");
  361.         }
  362.  
  363.     }
  364.  
  365.     public NBTTagCompound writeToNBT(NBTTagCompound compound) {
  366.         super.writeToNBT(compound);
  367.         compound.setInteger("BurnTime", (short)this.furnaceBurnTime);
  368.         compound.setInteger("CookTime", (short)this.cookTime);
  369.         compound.setInteger("CookTimeTotal", (short)this.totalCookTime);
  370.         ItemStackHelper.saveAllItems(compound, this.inventory);
  371.         if (this.hasCustomName()) {
  372.             compound.setString("CustomName", this.customName);
  373.         }
  374.  
  375.         return compound;
  376.     }
  377.  
  378.     @Override
  379.     public int getInventoryStackLimit() {
  380.         return 64;
  381.     }
  382.  
  383.     public boolean isBurning() {
  384.         return this.furnaceBurnTime > 0;
  385.     }
  386.  
  387.     @SideOnly(Side.CLIENT)
  388.     public static boolean isBurning(IInventory inventory) {
  389.         return inventory.getField(0) > 0;
  390.     }
  391.  
  392.     @Override
  393.     public void update() {
  394.         boolean flag = this.isBurning();
  395.         boolean flag1 = false;
  396.         if (this.isBurning()) {
  397.             --this.furnaceBurnTime;
  398.         }
  399.  
  400.         if (!this.world.isRemote) {
  401.             ItemStack fuel = (ItemStack)this.inventory.get(FUEL);
  402.             if (this.isBurning() || !fuel.isEmpty() && !((ItemStack)this.inventory.get(IN1)).isEmpty() || !((ItemStack)this.inventory.get(IN2)).isEmpty() || !((ItemStack)this.inventory.get(IN3)).isEmpty()) {
  403.                 if (!this.isBurning() && this.canSmelt()) {
  404.                     this.furnaceBurnTime = getItemBurnTime(fuel);
  405.                     this.currentItemBurnTime = this.furnaceBurnTime;
  406.                     if (this.isBurning()) {
  407.                         flag1 = true;
  408.                         if (!fuel.isEmpty()) {
  409.                             Item item = fuel.getItem();
  410.                             fuel.shrink(1);
  411.                             if (fuel.isEmpty()) {
  412.                                 ItemStack item1 = item.getContainerItem(fuel);
  413.                                 this.inventory.set(FUEL, item1);
  414.                             }
  415.                         }
  416.                     }
  417.                 }
  418.  
  419.                 if (this.isBurning() && this.canSmelt()) {
  420.                     ++this.cookTime;
  421.                     if (this.cookTime == this.totalCookTime) {
  422.                         this.cookTime = 0;
  423.                         this.totalCookTime = this.getCookTime((ItemStack)this.inventory.get(IN1), (ItemStack)this.inventory.get(IN2), (ItemStack)this.inventory.get(IN3));
  424.                         this.smeltItem();
  425.                         flag1 = true;
  426.                     }
  427.                 } else {
  428.                     this.cookTime = 0;
  429.                 }
  430.             } else if (!this.isBurning() && this.cookTime > 0) {
  431.                 this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.totalCookTime);
  432.             }
  433.  
  434.             if (flag != this.isBurning()) {
  435.                 flag1 = true;
  436.                 BlockFurnace.setState(this.isBurning(), this.world, this.pos);
  437.             }
  438.         }
  439.  
  440.         if (flag1) {
  441.             this.markDirty();
  442.         }
  443.  
  444.     }
  445.  
  446.     public int getCookTime(ItemStack in1, ItemStack in2, ItemStack in3) { return 200; }
  447.  
  448.     private boolean canSmelt() {
  449.  
  450.         ItemStack[] in = { inventory.get(IN1), inventory.get(IN2), inventory.get(IN3)};
  451.         for(ItemStack s : in) {
  452.             if(s.isEmpty()) {
  453.                 return false;
  454.             }
  455.         }
  456.         ItemStack res = RecipeArcFurnace.getInstance().getResult(in[0], in[1], in[2]);
  457.         if(res.isEmpty()) { return false; }
  458.         else {
  459.             ItemStack out = inventory.get(OUT);
  460.             if(out.isEmpty()) { return true; }
  461.             else if(!out.isItemEqual(res)) { return false; }
  462.             else if(out.getCount() + res.getCount() <= this.getInventoryStackLimit() && out.getCount() + res.getCount() <= out.getMaxStackSize()) { return true; }
  463.             else { return out.getCount() + res.getCount() <= res.getMaxStackSize(); }
  464.         }
  465.     }
  466.  
  467.     public void smeltItem() {
  468.         if(this.canSmelt()) {
  469.             ItemStack[] in = { inventory.get(IN1), inventory.get(IN2), inventory.get(IN3)};
  470.             ItemStack res = RecipeArcFurnace.getInstance().getResult(in[0], in[1], in[2]);
  471.             ItemStack out = inventory.get(4);
  472.             if(out.isEmpty()) {
  473.                 this.inventory.set(4, res.copy());
  474.             } else if(out.getItem() == res.getItem()) {
  475.                 out.grow(res.getCount());
  476.             }
  477.  
  478.             for(ItemStack i : in) {
  479.                 i.shrink(1);
  480.             }
  481.         }
  482.     }
  483.  
  484.     public static int getItemBurnTime(ItemStack stack) {
  485.         if (stack.isEmpty()) {
  486.             return 0;
  487.         } else {
  488.             int burnTime = ForgeEventFactory.getItemBurnTime(stack);
  489.             if (burnTime >= 0) {
  490.                 return burnTime;
  491.             } else {
  492.                 Item item = stack.getItem();
  493.                 if (item == Item.getItemFromBlock(Blocks.WOODEN_SLAB)) {
  494.                     return 150;
  495.                 } else if (item == Item.getItemFromBlock(Blocks.WOOL)) {
  496.                     return 100;
  497.                 } else if (item == Item.getItemFromBlock(Blocks.CARPET)) {
  498.                     return 67;
  499.                 } else if (item == Item.getItemFromBlock(Blocks.LADDER)) {
  500.                     return 300;
  501.                 } else if (item == Item.getItemFromBlock(Blocks.WOODEN_BUTTON)) {
  502.                     return 100;
  503.                 } else if (Block.getBlockFromItem(item).getDefaultState().getMaterial() == Material.WOOD) {
  504.                     return 300;
  505.                 } else if (item == Item.getItemFromBlock(Blocks.COAL_BLOCK)) {
  506.                     return 16000;
  507.                 } else if (item instanceof ItemTool && "WOOD".equals(((ItemTool)item).getToolMaterialName())) {
  508.                     return 200;
  509.                 } else if (item instanceof ItemSword && "WOOD".equals(((ItemSword)item).getToolMaterialName())) {
  510.                     return 200;
  511.                 } else if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe)item).getMaterialName())) {
  512.                     return 200;
  513.                 } else if (item == Items.STICK) {
  514.                     return 100;
  515.                 } else if (item != Items.BOW && item != Items.FISHING_ROD) {
  516.                     if (item == Items.SIGN) {
  517.                         return 200;
  518.                     } else if (item == Items.COAL) {
  519.                         return 1600;
  520.                     } else if (item == Items.LAVA_BUCKET) {
  521.                         return 20000;
  522.                     } else if (item != Item.getItemFromBlock(Blocks.SAPLING) && item != Items.BOWL) {
  523.                         if (item == Items.BLAZE_ROD) {
  524.                             return 2400;
  525.                         } else if (item instanceof ItemDoor && item != Items.IRON_DOOR) {
  526.                             return 200;
  527.                         } else {
  528.                             return item instanceof ItemBoat ? 400 : 0;
  529.                         }
  530.                     } else {
  531.                         return 100;
  532.                     }
  533.                 } else {
  534.                     return 300;
  535.                 }
  536.             }
  537.         }
  538.     }
  539.  
  540.     public static boolean isItemFuel(ItemStack stack) {
  541.         return getItemBurnTime(stack) > 0;
  542.     }
  543.  
  544.     @Override
  545.     public boolean isUsableByPlayer(EntityPlayer player) {
  546.         if (this.world.getTileEntity(this.pos) != this) {
  547.             return false;
  548.         } else {
  549.             return player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
  550.         }
  551.     }
  552.  
  553.     @Override
  554.     public void openInventory(EntityPlayer entityPlayer) {
  555.  
  556.     }
  557.  
  558.     @Override
  559.     public void closeInventory(EntityPlayer entityPlayer) {
  560.  
  561.     }
  562.  
  563.     @Override
  564.     public boolean isItemValidForSlot(int index, ItemStack stack) {
  565.         if(index == 4) {
  566.             return false;
  567.         } else if(index != 3) {
  568.             return true;
  569.         } else {
  570.             return isItemFuel(stack);
  571.         }
  572.     }
  573.  
  574.     @Override
  575.     public int[] getSlotsForFace(EnumFacing side) {
  576.         if(side == EnumFacing.UP) {
  577.             return TOP;
  578.         } else if(side == EnumFacing.WEST) {
  579.             return SIDE_RIGHT;
  580.         } else if(side == EnumFacing.SOUTH) {
  581.             return BACK;
  582.         } else if(side == EnumFacing.EAST) {
  583.             return SIDE_LEFT;
  584.         } else if(side != EnumFacing.NORTH) {
  585.             return BOTTOM;
  586.         } else {
  587.             return TOP;
  588.         }
  589.     }
  590.  
  591.     @Override
  592.     public boolean canInsertItem(int index, ItemStack stack, EnumFacing enumFacing) {
  593.         return this.isItemValidForSlot(index, stack);
  594.     }
  595.  
  596.     @Override
  597.     public boolean canExtractItem(int i, ItemStack itemStack, EnumFacing enumFacing) {
  598.  
  599.         return false;
  600.     }
  601.  
  602.     public String getGuiID() {
  603.         return "exkva:arc_furnace";
  604.     }
  605.  
  606.     @Override
  607.     public int getField(int id) {
  608.         switch(id) {
  609.             case 0:
  610.                 return this.furnaceBurnTime;
  611.             case 1:
  612.                 return this.currentItemBurnTime;
  613.             case 2:
  614.                 return this.cookTime;
  615.             case 3:
  616.                 return this.totalCookTime;
  617.             default:
  618.                 return 0;
  619.         }
  620.     }
  621.  
  622.     @Override
  623.     public void setField(int id, int value) {
  624.         switch(id) {
  625.             case 0:
  626.                 this.furnaceBurnTime = value;
  627.                 break;
  628.             case 1:
  629.                 this.currentItemBurnTime = value;
  630.                 break;
  631.             case 2:
  632.                 this.cookTime = value;
  633.                 break;
  634.             case 3:
  635.                 this.totalCookTime = value;
  636.         }
  637.     }
  638.  
  639.     @Override
  640.     public int getFieldCount() {
  641.         return 4;
  642.     }
  643.  
  644.     @Override
  645.     public void clear() {
  646.         this.inventory.clear();
  647.     }
  648. }
  649.  
  650. //Stacktrace, error
  651. [15:39:11] [Server thread/FATAL] [minecraft/MinecraftServer]: Error executing task
  652. java.util.concurrent.ExecutionException: java.lang.NullPointerException
  653.     at java.util.concurrent.FutureTask.report(FutureTask.java:122) ~[?:1.8.0_181]
  654.     at java.util.concurrent.FutureTask.get(FutureTask.java:192) ~[?:1.8.0_181]
  655.     at net.minecraft.util.Util.runTask(Util.java:54) [Util.class:?]
  656.     at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:798) [MinecraftServer.class:?]
  657.     at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) [MinecraftServer.class:?]
  658.     at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) [IntegratedServer.class:?]
  659.     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
  660.     at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
  661. Caused by: java.lang.NullPointerException
  662.     at net.minecraftforge.items.SlotItemHandler.getStack(SlotItemHandler.java:79) ~[SlotItemHandler.class:?]
  663.     at net.minecraft.inventory.Container.getInventory(Container.java:75) ~[Container.class:?]
  664.     at net.minecraft.inventory.Container.addListener(Container.java:61) ~[Container.class:?]
  665.     at net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.openGui(FMLNetworkHandler.java:101) ~[FMLNetworkHandler.class:?]
  666.     at net.minecraft.entity.player.EntityPlayer.openGui(EntityPlayer.java:2809) ~[EntityPlayer.class:?]
  667.     at exokem.exkva.objects.machines.MachineArcFurnace.onBlockActivated(MachineArcFurnace.java:55) ~[MachineArcFurnace.class:?]
  668.     at net.minecraft.server.management.PlayerInteractionManager.processRightClickBlock(PlayerInteractionManager.java:475) ~[PlayerInteractionManager.class:?]
  669.     at net.minecraft.network.NetHandlerPlayServer.processTryUseItemOnBlock(NetHandlerPlayServer.java:769) ~[NetHandlerPlayServer.class:?]
  670.     at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:68) ~[CPacketPlayerTryUseItemOnBlock.class:?]
  671.     at net.minecraft.network.play.client.CPacketPlayerTryUseItemOnBlock.processPacket(CPacketPlayerTryUseItemOnBlock.java:13) ~[CPacketPlayerTryUseItemOnBlock.class:?]
  672.     at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?]
  673.     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) ~[?:1.8.0_181]
  674.     at java.util.concurrent.FutureTask.run(FutureTask.java:266) ~[?:1.8.0_181]
  675.     at net.minecraft.util.Util.runTask(Util.java:53) ~[Util.class:?]
  676.     ... 5 more
  677. [15:39:11] [Server thread/ERROR] [minecraft/MinecraftServer]: Encountered an unexpected exception
  678. net.minecraft.util.ReportedException: Ticking player
  679.     at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:848) ~[MinecraftServer.class:?]
  680.     at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743) ~[MinecraftServer.class:?]
  681.     at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192) ~[IntegratedServer.class:?]
  682.     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592) [MinecraftServer.class:?]
  683.     at java.lang.Thread.run(Thread.java:748) [?:1.8.0_181]
  684. Caused by: java.lang.NullPointerException
  685.     at net.minecraftforge.items.SlotItemHandler.getStack(SlotItemHandler.java:79) ~[SlotItemHandler.class:?]
  686.     at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:97) ~[Container.class:?]
  687.     at exokem.exkva.objects.containers.ContainerArcFurnace.detectAndSendChanges(ContainerArcFurnace.java:44) ~[ContainerArcFurnace.class:?]
  688.     at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:365) ~[EntityPlayerMP.class:?]
  689.     at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2171) ~[World.class:?]
  690.     at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871) ~[WorldServer.class:?]
  691.     at net.minecraft.world.World.updateEntity(World.java:2130) ~[World.class:?]
  692.     at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:672) ~[WorldServer.class:?]
  693.     at net.minecraft.world.World.updateEntities(World.java:1906) ~[World.class:?]
  694.     at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643) ~[WorldServer.class:?]
  695.     at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:842) ~[MinecraftServer.class:?]
  696.     ... 4 more
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement