2016-03-15 05:53:05 +01:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import reborncore.api.power.EnumPowerTier;
|
2016-04-11 18:43:54 +02:00
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
2016-10-08 21:46:16 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
2016-03-15 05:53:05 +01:00
|
|
|
import reborncore.common.blocks.BlockMachineBase;
|
2016-08-10 01:45:07 +02:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2016-03-15 05:53:05 +01:00
|
|
|
import reborncore.common.util.Inventory;
|
|
|
|
import techreborn.api.ScrapboxList;
|
|
|
|
import techreborn.init.ModBlocks;
|
|
|
|
import techreborn.init.ModItems;
|
2016-04-11 18:50:00 +02:00
|
|
|
|
|
|
|
import java.util.Random;
|
2016-03-15 09:13:05 +01:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public class TileScrapboxinator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory {
|
2016-03-15 05:53:05 +01:00
|
|
|
|
|
|
|
public Inventory inventory = new Inventory(6, "TileScrapboxinator", 64, this);
|
2016-08-10 01:45:07 +02:00
|
|
|
public int capacity = 1000;
|
2016-03-15 05:53:05 +01:00
|
|
|
public int cost = 20;
|
|
|
|
public int progress;
|
|
|
|
public int time = 200;
|
|
|
|
public int chance = 4;
|
|
|
|
public int random;
|
|
|
|
public int input1 = 0;
|
|
|
|
public int output = 1;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileScrapboxinator() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super(1);
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public int gaugeProgressScaled(int scale) {
|
2016-03-15 05:53:05 +01:00
|
|
|
return (progress * scale) / time;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void updateEntity() {
|
2016-03-15 05:53:05 +01:00
|
|
|
boolean burning = isBurning();
|
|
|
|
boolean updateInventory = false;
|
2016-10-08 21:46:16 +02:00
|
|
|
if (getEnergy() <= cost && canOpen()) {
|
|
|
|
if (getEnergy() > cost) {
|
2016-03-15 05:53:05 +01:00
|
|
|
updateInventory = true;
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (isBurning() && canOpen()) {
|
2016-03-15 05:53:05 +01:00
|
|
|
updateState();
|
|
|
|
|
|
|
|
progress++;
|
2016-10-08 21:46:16 +02:00
|
|
|
if (progress >= time) {
|
2016-03-15 05:53:05 +01:00
|
|
|
progress = 0;
|
|
|
|
recycleItems();
|
|
|
|
updateInventory = true;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-15 05:53:05 +01:00
|
|
|
progress = 0;
|
|
|
|
updateState();
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (burning != isBurning()) {
|
2016-03-15 05:53:05 +01:00
|
|
|
updateInventory = true;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (updateInventory) {
|
2016-03-15 05:53:05 +01:00
|
|
|
markDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public void recycleItems() {
|
2016-11-19 13:50:08 +01:00
|
|
|
if (this.canOpen() && !world.isRemote) {
|
2016-03-15 05:53:05 +01:00
|
|
|
int random = new Random().nextInt(ScrapboxList.stacks.size());
|
|
|
|
ItemStack out = ScrapboxList.stacks.get(random).copy();
|
2016-10-08 21:46:16 +02:00
|
|
|
if (getStackInSlot(output) == null) {
|
2016-03-15 05:53:05 +01:00
|
|
|
useEnergy(cost);
|
|
|
|
setInventorySlotContents(output, out);
|
|
|
|
}
|
|
|
|
|
2016-11-19 13:50:08 +01:00
|
|
|
if (getStackInSlot(input1).getCount() > 1) {
|
2016-03-15 05:53:05 +01:00
|
|
|
useEnergy(cost);
|
|
|
|
this.decrStackSize(input1, 1);
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-15 05:53:05 +01:00
|
|
|
useEnergy(cost);
|
2016-11-19 17:36:13 +01:00
|
|
|
setInventorySlotContents(input1, ItemStack.EMPTY);
|
2016-03-15 05:53:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canOpen() {
|
2016-11-19 17:36:13 +01:00
|
|
|
return getStackInSlot(input1) != ItemStack.EMPTY && getStackInSlot(output) == ItemStack.EMPTY;
|
2016-03-15 05:53:05 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean isBurning() {
|
2016-03-15 05:53:05 +01:00
|
|
|
return getEnergy() > cost;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public void updateState() {
|
2016-11-19 13:50:08 +01:00
|
|
|
IBlockState blockState = world.getBlockState(pos);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (blockState.getBlock() instanceof BlockMachineBase) {
|
2016-03-15 05:53:05 +01:00
|
|
|
BlockMachineBase blockMachineBase = (BlockMachineBase) blockState.getBlock();
|
|
|
|
if (blockState.getValue(BlockMachineBase.ACTIVE) != progress > 0)
|
2016-11-19 13:50:08 +01:00
|
|
|
blockMachineBase.setActive(progress > 0, world, pos);
|
2016-03-15 05:53:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
2016-03-15 05:53:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumFacing getFacing() {
|
2016-03-15 05:53:05 +01:00
|
|
|
return getFacingEnum();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
2016-04-03 15:34:39 +02:00
|
|
|
return entityPlayer.isSneaking();
|
2016-03-15 05:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public float getWrenchDropRate() {
|
2016-03-15 05:53:05 +01:00
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return new ItemStack(ModBlocks.SCRAPBOXINATOR, 1);
|
2016-03-15 05:53:05 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean isComplete() {
|
2016-03-15 05:53:05 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ISidedInventory
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public int[] getSlotsForFace(EnumFacing side) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2 } : new int[] { 0, 1, 2 };
|
2016-03-15 05:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
|
2016-03-15 05:53:05 +01:00
|
|
|
if (slotIndex == 2)
|
|
|
|
return false;
|
2016-10-08 21:46:16 +02:00
|
|
|
if (slotIndex == 1) {
|
2017-01-01 08:29:32 +01:00
|
|
|
if (itemStack.getItem() == ModItems.SCRAP_BOX) {
|
2016-03-15 05:53:05 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return isItemValidForSlot(slotIndex, itemStack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
|
2016-03-15 05:53:05 +01:00
|
|
|
return slotIndex == 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxPower() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return capacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canAcceptEnergy(EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canProvideEnergy(EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxOutput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 0;
|
2016-03-15 05:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxInput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumPowerTier getTier() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return EnumPowerTier.MEDIUM;
|
2016-03-15 05:53:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-04-11 18:43:54 +02:00
|
|
|
public Inventory getInventory() {
|
|
|
|
return inventory;
|
2016-03-15 05:53:05 +01:00
|
|
|
}
|
|
|
|
}
|