2016-07-24 01:10:37 +07:00
|
|
|
package techreborn.tiles.multiblock;
|
|
|
|
|
|
|
|
import net.minecraft.block.state.IBlockState;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.init.Blocks;
|
|
|
|
import net.minecraft.init.Items;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
2016-11-19 14:41:00 +00:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
|
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
2016-07-24 01:10:37 +07:00
|
|
|
import net.minecraftforge.oredict.OreDictionary;
|
2017-01-08 20:34:46 +01:00
|
|
|
|
2016-07-24 01:10:37 +07:00
|
|
|
import reborncore.api.power.EnumPowerTier;
|
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
|
|
|
import reborncore.common.IWrenchable;
|
2016-08-10 00:51:44 +01:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2016-07-24 01:10:37 +07:00
|
|
|
import reborncore.common.util.FluidUtils;
|
|
|
|
import reborncore.common.util.Inventory;
|
|
|
|
import reborncore.common.util.Tank;
|
2017-01-08 20:34:46 +01:00
|
|
|
|
|
|
|
import techreborn.client.container.IContainerProvider;
|
|
|
|
import techreborn.client.container.builder.BuiltContainer;
|
|
|
|
import techreborn.client.container.builder.ContainerBuilder;
|
2016-07-24 01:10:37 +07:00
|
|
|
import techreborn.init.ModBlocks;
|
|
|
|
import techreborn.items.ItemDusts;
|
|
|
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public class TileIndustrialSawmill extends TilePowerAcceptor
|
|
|
|
implements IWrenchable, IInventoryProvider, IContainerProvider {
|
2016-07-24 01:10:37 +07:00
|
|
|
|
2016-10-08 20:46:16 +01:00
|
|
|
public Inventory inventory = new Inventory(5, "Sawmill", 64, this);
|
|
|
|
public Tank tank = new Tank("Sawmill", 16000, this);
|
2016-07-24 01:10:37 +07:00
|
|
|
|
|
|
|
public int tickTime;
|
|
|
|
public MultiblockChecker multiblockChecker;
|
|
|
|
|
2016-08-10 00:51:44 +01:00
|
|
|
public TileIndustrialSawmill() {
|
|
|
|
super(2);
|
|
|
|
}
|
|
|
|
|
2016-07-24 01:10:37 +07:00
|
|
|
@Override
|
|
|
|
public void update() {
|
|
|
|
super.update();
|
2017-01-08 20:34:46 +01:00
|
|
|
|
|
|
|
if (this.getMutliBlock()) {
|
|
|
|
final ItemStack wood = this.inventory.getStackInSlot(0);
|
|
|
|
if (this.tickTime == 0) {
|
|
|
|
if (!wood.isEmpty()) {
|
|
|
|
for (final int id : OreDictionary.getOreIDs(wood)) {
|
|
|
|
final String name = OreDictionary.getOreName(id);
|
|
|
|
if (name.equals("logWood") && this.canAddOutput(2, 10) && this.canAddOutput(3, 5)
|
|
|
|
&& this.canAddOutput(4, 3) && this.canUseEnergy(128.0F) && !this.tank.isEmpty()
|
|
|
|
&& this.tank.getFluid().amount >= 1000) {
|
2016-11-19 14:41:00 +00:00
|
|
|
wood.shrink(1);
|
|
|
|
if (wood.getCount() == 0)
|
2017-01-08 20:34:46 +01:00
|
|
|
this.setInventorySlotContents(0, ItemStack.EMPTY);
|
|
|
|
this.tank.drain(1000, true);
|
|
|
|
this.useEnergy(128.0F);
|
|
|
|
this.syncWithAll();
|
|
|
|
this.tickTime = 1;
|
2016-10-08 20:46:16 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-01-08 20:34:46 +01:00
|
|
|
} else if (++this.tickTime > 100) {
|
|
|
|
final Random rnd = this.world.rand;
|
|
|
|
this.addOutput(2, new ItemStack(Blocks.PLANKS, 6 + rnd.nextInt(4)));
|
2016-10-08 20:46:16 +01:00
|
|
|
if (rnd.nextInt(4) != 0) {
|
2017-01-08 20:34:46 +01:00
|
|
|
final ItemStack pulp = ItemDusts.getDustByName("sawDust", 2 + rnd.nextInt(3));
|
|
|
|
this.addOutput(3, pulp);
|
2016-10-08 20:46:16 +01:00
|
|
|
}
|
|
|
|
if (rnd.nextInt(3) == 0) {
|
2017-01-08 20:34:46 +01:00
|
|
|
final ItemStack paper = new ItemStack(Items.PAPER, 1 + rnd.nextInt(2));
|
|
|
|
this.addOutput(4, paper);
|
2016-10-08 20:46:16 +01:00
|
|
|
}
|
2017-01-08 20:34:46 +01:00
|
|
|
this.tickTime = 0;
|
2016-10-08 20:46:16 +01:00
|
|
|
}
|
|
|
|
}
|
2017-01-08 20:34:46 +01:00
|
|
|
FluidUtils.drainContainers(this.tank, this.inventory, 1, 4);
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public void addOutput(final int slot, final ItemStack stack) {
|
|
|
|
if (this.getStackInSlot(slot) == ItemStack.EMPTY)
|
|
|
|
this.setInventorySlotContents(slot, stack);
|
|
|
|
this.getStackInSlot(slot).grow(stack.getCount());
|
2016-10-08 20:46:16 +01:00
|
|
|
}
|
2016-07-24 01:10:37 +07:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canAddOutput(final int slot, final int amount) {
|
|
|
|
final ItemStack stack = this.getStackInSlot(slot);
|
|
|
|
return stack == ItemStack.EMPTY || this.getInventoryStackLimit() - stack.getCount() >= amount;
|
2016-10-08 20:46:16 +01:00
|
|
|
}
|
2016-07-24 01:10:37 +07:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void validate() {
|
|
|
|
super.validate();
|
2017-01-08 20:34:46 +01:00
|
|
|
this.multiblockChecker = new MultiblockChecker(this.world, this.getPos().down(3));
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean getMutliBlock() {
|
2017-01-08 20:34:46 +01:00
|
|
|
final boolean down = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_NORMAL,
|
|
|
|
MultiblockChecker.ZERO_OFFSET);
|
|
|
|
final boolean up = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_NORMAL,
|
|
|
|
new BlockPos(0, 2, 0));
|
|
|
|
final boolean blade = this.multiblockChecker.checkRingY(1, 1, MultiblockChecker.CASING_REINFORCED,
|
|
|
|
new BlockPos(0, 1, 0));
|
|
|
|
final IBlockState centerBlock = this.multiblockChecker.getBlock(0, 1, 0);
|
|
|
|
final boolean center = centerBlock.getBlock() == Blocks.WATER;
|
2016-10-08 20:46:16 +01:00
|
|
|
return down && center && blade && up;
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
|
2016-07-24 01:10:37 +07:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumFacing getFacing() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.getFacingEnum();
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
|
2016-07-24 01:10:37 +07:00
|
|
|
return entityPlayer.isSneaking();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getWrenchDropRate() {
|
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
|
2016-12-31 23:29:32 -08:00
|
|
|
return new ItemStack(ModBlocks.INDUSTRIAL_SAWMILL, 1);
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public void readFromNBT(final NBTTagCompound tagCompound) {
|
2016-07-24 01:10:37 +07:00
|
|
|
super.readFromNBT(tagCompound);
|
2017-01-08 20:34:46 +01:00
|
|
|
this.tank.readFromNBT(tagCompound);
|
|
|
|
this.tickTime = tagCompound.getInteger("tickTime");
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
|
2016-07-24 01:10:37 +07:00
|
|
|
super.writeToNBT(tagCompound);
|
2017-01-08 20:34:46 +01:00
|
|
|
this.tank.writeToNBT(tagCompound);
|
|
|
|
tagCompound.setInteger("tickTime", this.tickTime);
|
2016-07-24 01:10:37 +07:00
|
|
|
return tagCompound;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean hasCapability(final Capability<?> capability, final EnumFacing facing) {
|
2016-11-25 13:25:51 +00:00
|
|
|
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
2016-11-19 14:41:00 +00:00
|
|
|
return true;
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
2016-11-19 14:41:00 +00:00
|
|
|
return super.hasCapability(capability, facing);
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public <T> T getCapability(final Capability<T> capability, final EnumFacing facing) {
|
2016-11-25 13:25:51 +00:00
|
|
|
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
2017-01-08 20:34:46 +01:00
|
|
|
return (T) this.tank;
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
2016-11-19 14:41:00 +00:00
|
|
|
return super.getCapability(capability, facing);
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
|
2016-10-08 20:46:16 +01:00
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public int[] getSlotsForFace(final EnumFacing side) {
|
2016-10-08 20:46:16 +01:00
|
|
|
return new int[] { 0, 2, 3, 4, 5 };
|
|
|
|
}
|
2016-07-24 01:10:37 +07:00
|
|
|
|
2016-10-08 20:46:16 +01:00
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canInsertItem(final int index, final ItemStack itemStackIn, final EnumFacing direction) {
|
2016-10-08 20:46:16 +01:00
|
|
|
return index == 0;
|
|
|
|
}
|
2016-07-24 01:10:37 +07:00
|
|
|
|
2016-10-08 20:46:16 +01:00
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canExtractItem(final int index, final ItemStack stack, final EnumFacing direction) {
|
2016-10-08 20:46:16 +01:00
|
|
|
return index >= 2;
|
|
|
|
}
|
2016-07-24 01:10:37 +07:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public int getProgressScaled(final int scale) {
|
|
|
|
if (this.tickTime != 0) {
|
|
|
|
return this.tickTime * scale / 100;
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxPower() {
|
|
|
|
return 64000;
|
|
|
|
}
|
|
|
|
|
2016-08-10 00:51:44 +01:00
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canAcceptEnergy(final EnumFacing direction) {
|
2016-08-10 00:51:44 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canProvideEnergy(final EnumFacing direction) {
|
2016-08-10 00:51:44 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxOutput() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxInput() {
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
2016-07-24 01:10:37 +07:00
|
|
|
@Override
|
|
|
|
public EnumPowerTier getTier() {
|
|
|
|
return EnumPowerTier.MEDIUM;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Inventory getInventory() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.inventory;
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
@Override
|
|
|
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
|
|
|
return new ContainerBuilder("industrialsawmill").player(player.inventory).inventory(8, 84).hotbar(8, 142)
|
|
|
|
.addInventory().tile(this).slot(0, 32, 26).slot(1, 32, 44).outputSlot(2, 84, 35).outputSlot(3, 102, 35)
|
|
|
|
.outputSlot(4, 120, 35).syncEnergyValue().addInventory().create();
|
|
|
|
}
|
2016-07-24 01:10:37 +07:00
|
|
|
}
|