Merge branch 'feature/containers-builder' of https://github.com/TechReborn/TechReborn into feature/containers-builder

# Conflicts:
#	src/main/java/techreborn/client/gui/GuiBatbox.java
#	src/main/java/techreborn/client/gui/GuiQuantumChest.java
This commit is contained in:
ProfessorProspector 2017-01-07 20:22:34 -08:00
commit 0cccb0a91b
47 changed files with 915 additions and 1452 deletions

View file

@ -8,6 +8,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumFacing;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.tile.TileLegacyMachineBase;
@ -30,100 +31,98 @@ public class TileIronFurnace extends TileLegacyMachineBase implements IInventory
int fuelslot = 2;
boolean active = false;
public int gaugeProgressScaled(int scale) {
return (progress * scale) / fuelScale;
public int gaugeProgressScaled(final int scale) {
return this.progress * scale / this.fuelScale;
}
public int gaugeFuelScaled(int scale) {
if (fuelGague == 0) {
fuelGague = fuel;
if (fuelGague == 0) {
fuelGague = fuelScale;
public int gaugeFuelScaled(final int scale) {
if (this.fuelGague == 0) {
this.fuelGague = this.fuel;
if (this.fuelGague == 0) {
this.fuelGague = this.fuelScale;
}
}
return (fuel * scale) / fuelGague;
return this.fuel * scale / this.fuelGague;
}
@Override
public void updateEntity() {
boolean burning = isBurning();
final boolean burning = this.isBurning();
boolean updateInventory = false;
if (fuel > 0) {
fuel--;
updateState();
if (this.fuel > 0) {
this.fuel--;
this.updateState();
}
if (fuel <= 0 && canSmelt()) {
fuel = fuelGague = (int) (TileEntityFurnace.getItemBurnTime(getStackInSlot(fuelslot)) * 1.25);
if (fuel > 0) {
if (getStackInSlot(fuelslot).getItem().hasContainerItem()) // Fuel
// slot
if (this.fuel <= 0 && this.canSmelt()) {
this.fuel = this.fuelGague = (int) (TileEntityFurnace.getItemBurnTime(this.getStackInSlot(this.fuelslot)) * 1.25);
if (this.fuel > 0) {
if (this.getStackInSlot(this.fuelslot).getItem().hasContainerItem()) // Fuel
// slot
{
setInventorySlotContents(fuelslot, new ItemStack(getStackInSlot(fuelslot).getItem().getContainerItem()));
} else if (getStackInSlot(fuelslot).getCount() > 1) {
decrStackSize(fuelslot, 1);
} else if (getStackInSlot(fuelslot).getCount() == 1) {
setInventorySlotContents(fuelslot, ItemStack.EMPTY);
this.setInventorySlotContents(this.fuelslot, new ItemStack(this.getStackInSlot(this.fuelslot).getItem().getContainerItem()));
} else if (this.getStackInSlot(this.fuelslot).getCount() > 1) {
this.decrStackSize(this.fuelslot, 1);
} else if (this.getStackInSlot(this.fuelslot).getCount() == 1) {
this.setInventorySlotContents(this.fuelslot, ItemStack.EMPTY);
}
updateInventory = true;
}
}
if (isBurning() && canSmelt()) {
progress++;
if (progress >= fuelScale) {
progress = 0;
cookItems();
if (this.isBurning() && this.canSmelt()) {
this.progress++;
if (this.progress >= this.fuelScale) {
this.progress = 0;
this.cookItems();
updateInventory = true;
}
} else {
progress = 0;
this.progress = 0;
}
if (burning != isBurning()) {
if (burning != this.isBurning()) {
updateInventory = true;
}
if (updateInventory) {
markDirty();
this.markDirty();
}
}
public void cookItems() {
if (this.canSmelt()) {
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
if (getStackInSlot(output) == ItemStack.EMPTY) {
setInventorySlotContents(output, itemstack.copy());
} else if (getStackInSlot(output).isItemEqual(itemstack)) {
getStackInSlot(output).grow(itemstack.getCount());
if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
this.setInventorySlotContents(this.output, itemstack.copy());
} else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) {
this.getStackInSlot(this.output).grow(itemstack.getCount());
}
if (getStackInSlot(input1).getCount() > 1) {
this.decrStackSize(input1, 1);
if (this.getStackInSlot(this.input1).getCount() > 1) {
this.decrStackSize(this.input1, 1);
} else {
setInventorySlotContents(input1, ItemStack.EMPTY);
this.setInventorySlotContents(this.input1, ItemStack.EMPTY);
}
}
}
public boolean canSmelt() {
if (getStackInSlot(input1) == ItemStack.EMPTY) {
if (this.getStackInSlot(this.input1) == ItemStack.EMPTY)
return false;
} else {
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
if (itemstack == ItemStack.EMPTY)
return false;
if (getStackInSlot(output) == ItemStack.EMPTY)
return true;
if (!getStackInSlot(output).isItemEqual(itemstack))
return false;
int result = getStackInSlot(output).getCount() + itemstack.getCount();
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
}
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
if (itemstack == ItemStack.EMPTY)
return false;
if (this.getStackInSlot(this.output) == ItemStack.EMPTY)
return true;
if (!this.getStackInSlot(this.output).isItemEqual(itemstack))
return false;
final int result = this.getStackInSlot(this.output).getCount() + itemstack.getCount();
return result <= this.getInventoryStackLimit() && result <= itemstack.getMaxStackSize();
}
public boolean isBurning() {
return fuel > 0;
return this.fuel > 0;
}
public ItemStack getResultFor(ItemStack stack) {
ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
public ItemStack getResultFor(final ItemStack stack) {
final ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
if (result != ItemStack.EMPTY) {
return result.copy();
}
@ -131,30 +130,33 @@ public class TileIronFurnace extends TileLegacyMachineBase implements IInventory
}
public void updateState() {
IBlockState BlockStateContainer = world.getBlockState(pos);
final IBlockState BlockStateContainer = this.world.getBlockState(this.pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != fuel > 0)
blockMachineBase.setActive(fuel > 0, world, pos);
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.fuel > 0)
blockMachineBase.setActive(this.fuel > 0, this.world, this.pos);
}
}
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int[] getSlotsForFace(EnumFacing side) {
return side == EnumFacing.DOWN ? SLOTS_BOTTOM : (side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES);
@Override
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? TileIronFurnace.SLOTS_BOTTOM : side == EnumFacing.UP ? TileIronFurnace.SLOTS_TOP : TileIronFurnace.SLOTS_SIDES;
}
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
@Override
public boolean canInsertItem(final int index, final ItemStack itemStackIn, final EnumFacing direction) {
return this.isItemValidForSlot(index, itemStackIn);
}
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
@Override
public boolean canExtractItem(final int index, final ItemStack stack, final EnumFacing direction) {
if (direction == EnumFacing.DOWN && index == 1) {
Item item = stack.getItem();
final Item item = stack.getItem();
if (item != Items.WATER_BUCKET && item != Items.BUCKET) {
return false;
@ -163,4 +165,20 @@ public class TileIronFurnace extends TileLegacyMachineBase implements IInventory
return true;
}
public int getBurnTime() {
return this.fuel;
}
public void setBurnTime(final int burnTime) {
this.fuel = burnTime;
}
public int getTotalBurnTime() {
return this.fuelGague;
}
public void setTotalBurnTime(final int totalBurnTime) {
this.fuelGague = totalBurnTime;
}
}

View file

@ -7,12 +7,14 @@ import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.ForgeModContainer;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.init.ModBlocks;
public class TileGenerator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
@ -31,69 +33,69 @@ public class TileGenerator extends TilePowerAcceptor implements IWrenchable, IIn
super(1);
}
public static int getItemBurnTime(ItemStack stack) {
public static int getItemBurnTime(final ItemStack stack) {
return TileEntityFurnace.getItemBurnTime(stack) / 4;
}
@Override
public void updateEntity() {
super.updateEntity();
if (world.isRemote) {
if (this.world.isRemote) {
return;
}
if (getEnergy() < getMaxPower()) {
if (burnTime > 0) {
burnTime--;
addEnergy(outputAmount);
isBurning = true;
if (this.getEnergy() < this.getMaxPower()) {
if (this.burnTime > 0) {
this.burnTime--;
this.addEnergy(TileGenerator.outputAmount);
this.isBurning = true;
}
} else {
isBurning = false;
this.isBurning = false;
}
if (burnTime == 0) {
updateState();
burnTime = totalBurnTime = getItemBurnTime(getStackInSlot(fuelSlot));
if (burnTime > 0) {
updateState();
burnItem = getStackInSlot(fuelSlot);
if (getStackInSlot(fuelSlot).getCount() == 1) {
if (getStackInSlot(fuelSlot).getItem() == Items.LAVA_BUCKET || getStackInSlot(fuelSlot).getItem() == ForgeModContainer.getInstance().universalBucket) {
setInventorySlotContents(fuelSlot, new ItemStack(Items.BUCKET));
if (this.burnTime == 0) {
this.updateState();
this.burnTime = this.totalBurnTime = TileGenerator.getItemBurnTime(this.getStackInSlot(this.fuelSlot));
if (this.burnTime > 0) {
this.updateState();
this.burnItem = this.getStackInSlot(this.fuelSlot);
if (this.getStackInSlot(this.fuelSlot).getCount() == 1) {
if (this.getStackInSlot(this.fuelSlot).getItem() == Items.LAVA_BUCKET || this.getStackInSlot(this.fuelSlot).getItem() == ForgeModContainer.getInstance().universalBucket) {
this.setInventorySlotContents(this.fuelSlot, new ItemStack(Items.BUCKET));
} else {
setInventorySlotContents(fuelSlot, ItemStack.EMPTY);
this.setInventorySlotContents(this.fuelSlot, ItemStack.EMPTY);
}
} else {
decrStackSize(fuelSlot, 1);
this.decrStackSize(this.fuelSlot, 1);
}
}
}
lastTickBurning = isBurning;
this.lastTickBurning = this.isBurning;
}
public void updateState() {
IBlockState BlockStateContainer = world.getBlockState(pos);
final IBlockState BlockStateContainer = this.world.getBlockState(this.pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != burnTime > 0)
blockMachineBase.setActive(burnTime > 0, world, pos);
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.burnTime > 0)
blockMachineBase.setActive(this.burnTime > 0, this.world, this.pos);
}
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
return false;
}
@Override
public EnumFacing getFacing() {
return getFacingEnum();
return this.getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
}
@ -108,12 +110,12 @@ public class TileGenerator extends TilePowerAcceptor implements IWrenchable, IIn
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
public boolean canAcceptEnergy(final EnumFacing direction) {
return false;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
public boolean canProvideEnergy(final EnumFacing direction) {
return true;
}
@ -133,12 +135,32 @@ public class TileGenerator extends TilePowerAcceptor implements IWrenchable, IIn
}
@Override
public ItemStack getWrenchDrop(EntityPlayer p0) {
public ItemStack getWrenchDrop(final EntityPlayer p0) {
return new ItemStack(ModBlocks.SOLID_FUEL_GENEREATOR);
}
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int getBurnTime() {
return this.burnTime;
}
public void setBurnTime(final int burnTime) {
this.burnTime = burnTime;
}
public int getTotalBurnTime() {
return this.totalBurnTime;
}
public void setTotalBurnTime(final int totalBurnTime) {
this.totalBurnTime = totalBurnTime;
}
public int getScaledBurnTime(final int i) {
return (int) ((float) this.burnTime / (float) this.totalBurnTime * i);
}
}

View file

@ -6,12 +6,14 @@ import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.init.ModBlocks;
public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory {
@ -31,78 +33,78 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
super(1);
}
public int gaugeProgressScaled(int scale) {
return (progress * scale) / fuelScale;
public int gaugeProgressScaled(final int scale) {
return this.progress * scale / this.fuelScale;
}
@Override
public void update() {
super.update();
boolean burning = isBurning();
final boolean burning = this.isBurning();
boolean updateInventory = false;
if (isBurning() && canSmelt()) {
updateState();
if (this.isBurning() && this.canSmelt()) {
this.updateState();
progress++;
if (progress % 10 == 0) {
useEnergy(cost);
this.progress++;
if (this.progress % 10 == 0) {
this.useEnergy(this.cost);
}
if (progress >= fuelScale) {
progress = 0;
cookItems();
if (this.progress >= this.fuelScale) {
this.progress = 0;
this.cookItems();
updateInventory = true;
}
} else {
progress = 0;
updateState();
this.progress = 0;
this.updateState();
}
if (burning != isBurning()) {
if (burning != this.isBurning()) {
updateInventory = true;
}
if (updateInventory) {
markDirty();
this.markDirty();
}
}
public void cookItems() {
if (this.canSmelt()) {
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
if (getStackInSlot(output) == ItemStack.EMPTY) {
setInventorySlotContents(output, itemstack.copy());
} else if (getStackInSlot(output).isItemEqual(itemstack)) {
getStackInSlot(output).grow(itemstack.getCount());
if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
this.setInventorySlotContents(this.output, itemstack.copy());
} else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) {
this.getStackInSlot(this.output).grow(itemstack.getCount());
}
if (getStackInSlot(input1).getCount() > 1) {
this.decrStackSize(input1, 1);
if (this.getStackInSlot(this.input1).getCount() > 1) {
this.decrStackSize(this.input1, 1);
} else {
setInventorySlotContents(input1, ItemStack.EMPTY);
this.setInventorySlotContents(this.input1, ItemStack.EMPTY);
}
}
}
public boolean canSmelt() {
if (getStackInSlot(input1) == ItemStack.EMPTY) {
if (this.getStackInSlot(this.input1) == ItemStack.EMPTY) {
return false;
} else {
ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(getStackInSlot(input1));
final ItemStack itemstack = FurnaceRecipes.instance().getSmeltingResult(this.getStackInSlot(this.input1));
if (itemstack == ItemStack.EMPTY)
return false;
if (getStackInSlot(output) == ItemStack.EMPTY)
if (this.getStackInSlot(this.output) == ItemStack.EMPTY)
return true;
if (!getStackInSlot(output).isItemEqual(itemstack))
if (!this.getStackInSlot(this.output).isItemEqual(itemstack))
return false;
int result = getStackInSlot(output).getCount() + itemstack.getCount();
return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
final int result = this.getStackInSlot(this.output).getCount() + itemstack.getCount();
return result <= this.getInventoryStackLimit() && result <= itemstack.getMaxStackSize();
}
}
public boolean isBurning() {
return getEnergy() > cost;
return this.getEnergy() > this.cost;
}
public ItemStack getResultFor(ItemStack stack) {
ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
public ItemStack getResultFor(final ItemStack stack) {
final ItemStack result = FurnaceRecipes.instance().getSmeltingResult(stack);
if (result != ItemStack.EMPTY) {
return result.copy();
}
@ -110,26 +112,26 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
}
public void updateState() {
IBlockState BlockStateContainer = world.getBlockState(pos);
final IBlockState BlockStateContainer = this.world.getBlockState(this.pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != progress > 0)
blockMachineBase.setActive(progress > 0, world, pos);
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.progress > 0)
blockMachineBase.setActive(this.progress > 0, this.world, this.pos);
}
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
return false;
}
@Override
public EnumFacing getFacing() {
return getFacingEnum();
return this.getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
}
@ -139,7 +141,7 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.ELECTRIC_FURNACE, 1);
}
@ -149,34 +151,34 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
return side == EnumFacing.DOWN ? SLOTS_BOTTOM : (side == EnumFacing.UP ? SLOTS_TOP : SLOTS_SIDES);
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? TileElectricFurnace.SLOTS_BOTTOM : side == EnumFacing.UP ? TileElectricFurnace.SLOTS_TOP : TileElectricFurnace.SLOTS_SIDES;
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
public boolean canInsertItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
if (slotIndex == 2)
return false;
return isItemValidForSlot(slotIndex, itemStack);
return this.isItemValidForSlot(slotIndex, itemStack);
}
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
return slotIndex == 1;
}
@Override
public double getMaxPower() {
return capacity;
return this.capacity;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
@ -197,6 +199,14 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int getBurnTime() {
return this.progress;
}
public void setBurnTime(final int burnTime) {
this.progress = burnTime;
}
}

View file

@ -4,21 +4,21 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IContainerProvider;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.container.RebornContainer;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.ContainerExtractor;
import techreborn.init.ModBlocks;
import techreborn.utils.upgrade.UpgradeHandler;
public class TileExtractor extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public class TileExtractor extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider {
public Inventory inventory = new Inventory(6, "TileExtractor", 64, this);
@ -29,34 +29,34 @@ public class TileExtractor extends TilePowerAcceptor implements IWrenchable, IIn
public TileExtractor() {
super(1);
int[] inputs = new int[1];
final int[] inputs = new int[1];
inputs[0] = 0;
int[] outputs = new int[1];
final int[] outputs = new int[1];
outputs[0] = 1;
crafter = new RecipeCrafter(Reference.extractorRecipe, this, 2, 1, inventory, inputs, outputs);
upgradeHandler = new UpgradeHandler(crafter, inventory, 2, 3, 4, 5);
this.crafter = new RecipeCrafter(Reference.extractorRecipe, this, 2, 1, this.inventory, inputs, outputs);
this.upgradeHandler = new UpgradeHandler(this.crafter, this.inventory, 2, 3, 4, 5);
}
@Override
public void update() {
super.update();
crafter.updateEntity();
upgradeHandler.tick();
charge(3);
this.crafter.updateEntity();
this.upgradeHandler.tick();
this.charge(3);
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
return false;
}
@Override
public EnumFacing getFacing() {
return getFacingEnum();
return this.getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
}
@ -66,7 +66,7 @@ public class TileExtractor extends TilePowerAcceptor implements IWrenchable, IIn
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.EXTRACTOR, 1);
}
@ -75,37 +75,37 @@ public class TileExtractor extends TilePowerAcceptor implements IWrenchable, IIn
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
crafter.readFromNBT(tagCompound);
this.crafter.readFromNBT(tagCompound);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
this.crafter.writeToNBT(tagCompound);
return tagCompound;
}
public int getProgressScaled(int scale) {
if (crafter.currentTickTime != 0) {
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
public int getProgressScaled(final int scale) {
if (this.crafter.currentTickTime != 0) {
return this.crafter.currentTickTime * scale / this.crafter.currentNeededTicks;
}
return 0;
}
@Override
public double getMaxPower() {
return capacity;
return this.capacity;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
@ -126,31 +126,26 @@ public class TileExtractor extends TilePowerAcceptor implements IWrenchable, IIn
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public RebornContainer getContainer() {
return RebornContainer.getContainerFromClass(ContainerExtractor.class, this);
}
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return new int[] { 0, 1 };
}
@Override
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
public boolean canInsertItem(final int index, final ItemStack itemStackIn, final EnumFacing direction) {
return index == 0;
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
public boolean canExtractItem(final int index, final ItemStack stack, final EnumFacing direction) {
return index == 1;
}

View file

@ -5,25 +5,24 @@ import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import reborncore.api.IListInfoProvider;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IContainerProvider;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.container.RebornContainer;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.ContainerGrinder;
import techreborn.init.ModBlocks;
import techreborn.utils.upgrade.UpgradeHandler;
import java.util.List;
public class TileGrinder extends TilePowerAcceptor implements IWrenchable, IInventoryProvider,
IListInfoProvider, IRecipeCrafterProvider, IContainerProvider, ISidedInventory {
IListInfoProvider, IRecipeCrafterProvider, ISidedInventory {
public Inventory inventory = new Inventory(6, "TileGrinder", 64, this);
@ -34,34 +33,34 @@ public class TileGrinder extends TilePowerAcceptor implements IWrenchable, IInve
public TileGrinder() {
super(1);
int[] inputs = new int[1];
final int[] inputs = new int[1];
inputs[0] = 0;
int[] outputs = new int[1];
final int[] outputs = new int[1];
outputs[0] = 1;
crafter = new RecipeCrafter(Reference.grinderRecipe, this, 2, 1, inventory, inputs, outputs);
upgradeHandler = new UpgradeHandler(crafter, inventory, 2, 3, 4, 5);
this.crafter = new RecipeCrafter(Reference.grinderRecipe, this, 2, 1, this.inventory, inputs, outputs);
this.upgradeHandler = new UpgradeHandler(this.crafter, this.inventory, 2, 3, 4, 5);
}
@Override
public void updateEntity() {
super.updateEntity();
upgradeHandler.tick();
this.upgradeHandler.tick();
//charge(3); TODO
charge(3);
this.charge(3);
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
return false;
}
@Override
public EnumFacing getFacing() {
return getFacingEnum();
return this.getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
}
@ -71,7 +70,7 @@ public class TileGrinder extends TilePowerAcceptor implements IWrenchable, IInve
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.GRINDER, 1);
}
@ -80,38 +79,38 @@ public class TileGrinder extends TilePowerAcceptor implements IWrenchable, IInve
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound);
crafter.readFromNBT(tagCompound);
this.inventory.readFromNBT(tagCompound);
this.crafter.readFromNBT(tagCompound);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
this.crafter.writeToNBT(tagCompound);
return tagCompound;
}
public int getProgressScaled(int scale) {
if (crafter.currentTickTime != 0 && crafter.currentNeededTicks != 0) {
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
public int getProgressScaled(final int scale) {
if (this.crafter.currentTickTime != 0 && this.crafter.currentNeededTicks != 0) {
return this.crafter.currentTickTime * scale / this.crafter.currentNeededTicks;
}
return 0;
}
@Override
public double getMaxPower() {
return capacity;
return this.capacity;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
@ -131,37 +130,32 @@ public class TileGrinder extends TilePowerAcceptor implements IWrenchable, IInve
}
@Override
public void addInfo(List<String> info, boolean isRealTile) {
public void addInfo(final List<String> info, final boolean isRealTile) {
info.add("Macerator");
}
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public RebornContainer getContainer() {
return RebornContainer.getContainerFromClass(ContainerGrinder.class, this);
}
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return new int[] { 0, 1 };
}
@Override
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
public boolean canInsertItem(final int index, final ItemStack itemStackIn, final EnumFacing direction) {
return index == 0;
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
public boolean canExtractItem(final int index, final ItemStack stack, final EnumFacing direction) {
return index == 1;
}
}

View file

@ -5,12 +5,14 @@ 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;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.init.ModBlocks;
import techreborn.items.ItemParts;
@ -30,107 +32,107 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
super(1);
}
public int gaugeProgressScaled(int scale) {
return (progress * scale) / time;
public int gaugeProgressScaled(final int scale) {
return this.progress * scale / this.time;
}
@Override
public void updateEntity() {
if (world.isRemote) {
if (this.world.isRemote) {
return;
}
boolean burning = isBurning();
final boolean burning = this.isBurning();
boolean updateInventory = false;
if (getEnergy() <= cost && canRecycle()) {
if (getEnergy() > cost) {
if (this.getEnergy() <= this.cost && this.canRecycle()) {
if (this.getEnergy() > this.cost) {
updateInventory = true;
}
}
if (isBurning() && canRecycle()) {
updateState();
if (this.isBurning() && this.canRecycle()) {
this.updateState();
progress++;
if (progress >= time) {
progress = 0;
recycleItems();
this.progress++;
if (this.progress >= this.time) {
this.progress = 0;
this.recycleItems();
updateInventory = true;
}
} else {
progress = 0;
updateState();
this.progress = 0;
this.updateState();
}
if (burning != isBurning()) {
if (burning != this.isBurning()) {
updateInventory = true;
}
if (updateInventory) {
markDirty();
this.markDirty();
}
}
public void recycleItems() {
if (this.canRecycle()) {
ItemStack itemstack = ItemParts.getPartByName("scrap");
int randomchance = world.rand.nextInt(chance);
final ItemStack itemstack = ItemParts.getPartByName("scrap");
final int randomchance = this.world.rand.nextInt(this.chance);
if (getStackInSlot(output) == ItemStack.EMPTY) {
useEnergy(cost);
if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
this.useEnergy(this.cost);
if (randomchance == 1) {
setInventorySlotContents(output, itemstack.copy());
this.setInventorySlotContents(this.output, itemstack.copy());
}
} else if (getStackInSlot(output).isItemEqual(itemstack)) {
useEnergy(cost);
} else if (this.getStackInSlot(this.output).isItemEqual(itemstack)) {
this.useEnergy(this.cost);
if (randomchance == 1) {
getStackInSlot(output).setCount(itemstack.getCount());
this.getStackInSlot(this.output).setCount(itemstack.getCount());
}
}
if (getStackInSlot(input1).getCount() > 1) {
useEnergy(cost);
this.decrStackSize(input1, 1);
if (this.getStackInSlot(this.input1).getCount() > 1) {
this.useEnergy(this.cost);
this.decrStackSize(this.input1, 1);
} else {
useEnergy(cost);
setInventorySlotContents(input1, ItemStack.EMPTY);
this.useEnergy(this.cost);
this.setInventorySlotContents(this.input1, ItemStack.EMPTY);
}
}
}
public boolean canRecycle() {
return getStackInSlot(input1) != null && hasSlotGotSpace(output);
return this.getStackInSlot(this.input1) != null && this.hasSlotGotSpace(this.output);
}
public boolean hasSlotGotSpace(int slot) {
if (getStackInSlot(slot) == ItemStack.EMPTY) {
public boolean hasSlotGotSpace(final int slot) {
if (this.getStackInSlot(slot) == ItemStack.EMPTY) {
return true;
} else if (getStackInSlot(slot).getCount() < getStackInSlot(slot).getMaxStackSize()) {
} else if (this.getStackInSlot(slot).getCount() < this.getStackInSlot(slot).getMaxStackSize()) {
return true;
}
return true;
}
public boolean isBurning() {
return getEnergy() > cost;
return this.getEnergy() > this.cost;
}
public void updateState() {
IBlockState BlockStateContainer = world.getBlockState(pos);
final IBlockState BlockStateContainer = this.world.getBlockState(this.pos);
if (BlockStateContainer.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != progress > 0)
blockMachineBase.setActive(progress > 0, world, pos);
final BlockMachineBase blockMachineBase = (BlockMachineBase) BlockStateContainer.getBlock();
if (BlockStateContainer.getValue(BlockMachineBase.ACTIVE) != this.progress > 0)
blockMachineBase.setActive(this.progress > 0, this.world, this.pos);
}
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
return false;
}
@Override
public EnumFacing getFacing() {
return getFacingEnum();
return this.getFacingEnum();
}
@Override
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
}
@ -140,7 +142,7 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.RECYCLER, 1);
}
@ -150,34 +152,34 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { output } : new int[] { input1 };
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { this.output } : new int[] { this.input1 };
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
if (slotIndex == output)
public boolean canInsertItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
if (slotIndex == this.output)
return false;
return isItemValidForSlot(slotIndex, itemStack);
return this.isItemValidForSlot(slotIndex, itemStack);
}
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
return slotIndex == output;
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
return slotIndex == this.output;
}
@Override
public double getMaxPower() {
return capacity;
return this.capacity;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
public boolean canAcceptEnergy(final EnumFacing direction) {
return true;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
public boolean canProvideEnergy(final EnumFacing direction) {
return false;
}
@ -198,6 +200,14 @@ public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInv
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int getProgress() {
return this.progress;
}
public void setProgress(final int progress) {
this.progress = progress;
}
}