Merge remote-tracking branch 'remotes/origin/feature/containers-builder' into 1.11.2

# Conflicts:
#	src/main/java/techreborn/client/container/ContainerAlloyFurnace.java
#	src/main/java/techreborn/tiles/TileAlloyFurnace.java
This commit is contained in:
modmuss50 2017-01-10 19:34:17 +00:00
commit 8b24fdf765
No known key found for this signature in database
GPG key ID: 203A5ED4D3E48BEA
195 changed files with 4701 additions and 5523 deletions

View file

@ -8,6 +8,7 @@ import net.minecraft.init.Items;
import net.minecraft.item.*;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.fml.common.registry.GameRegistry;
import reborncore.api.recipe.IBaseRecipeType;
import reborncore.api.recipe.RecipeHandler;
import reborncore.api.tile.IInventoryProvider;
@ -16,10 +17,16 @@ import reborncore.common.recipes.RecipeTranslator;
import reborncore.common.tile.TileLegacyMachineBase;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.api.Reference;
import techreborn.api.recipe.machines.AlloySmelterRecipe;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchable, IInventoryProvider {
public class TileAlloyFurnace extends TileLegacyMachineBase
implements IWrenchable, IInventoryProvider, IContainerProvider {
public int tickTime;
public Inventory inventory = new Inventory(4, "TileAlloyFurnace", 64, this);
@ -39,14 +46,14 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
* Returns the number of ticks that the supplied fuel item will keep the
* furnace burning, or 0 if the item isn't fuel
*/
public static int getItemBurnTime(ItemStack stack) {
public static int getItemBurnTime(final ItemStack stack) {
if (stack == null) {
return 0;
} else {
Item item = stack.getItem();
final Item item = stack.getItem();
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR) {
Block block = Block.getBlockFromItem(item);
final Block block = Block.getBlockFromItem(item);
if (block == Blocks.WOODEN_SLAB) {
return 150;
@ -84,19 +91,19 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
@Override
public void updateEntity() {
super.updateEntity();
boolean flag = this.burnTime > 0;
final boolean flag = this.burnTime > 0;
boolean flag1 = false;
if (this.burnTime > 0) {
--this.burnTime;
}
if (!this.world.isRemote) {
if (this.burnTime != 0 || getStackInSlot(input1) != ItemStack.EMPTY && getStackInSlot(fuel) != ItemStack.EMPTY) {
if (this.burnTime != 0 || this.getStackInSlot(this.input1) != ItemStack.EMPTY && this.getStackInSlot(this.fuel) != ItemStack.EMPTY) {
if (this.burnTime == 0 && this.canSmelt()) {
this.currentItemBurnTime = this.burnTime = getItemBurnTime(getStackInSlot(fuel));
this.currentItemBurnTime = this.burnTime = TileAlloyFurnace.getItemBurnTime(this.getStackInSlot(this.fuel));
if (this.burnTime > 0) {
flag1 = true;
if (this.getStackInSlot(fuel) != ItemStack.EMPTY) {
decrStackSize(fuel, 1);
if (this.getStackInSlot(this.fuel) != ItemStack.EMPTY) {
this.decrStackSize(this.fuel, 1);
}
}
}
@ -121,11 +128,11 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
}
}
public boolean hasAllInputs(IBaseRecipeType recipeType) {
public boolean hasAllInputs(final IBaseRecipeType recipeType) {
if (recipeType == null) {
return false;
}
for (Object input : recipeType.getInputs()) {
for (final Object input : recipeType.getInputs()) {
boolean hasItem = false;
boolean useOreDict = input instanceof String || recipeType.useOreDic();
boolean checkSize = input instanceof ItemStack;
@ -138,7 +145,6 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
}
}
}
if (!hasItem)
return false;
}
@ -146,12 +152,12 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
}
private boolean canSmelt() {
if (this.getStackInSlot(input1) == ItemStack.EMPTY || this.getStackInSlot(input2) == ItemStack.EMPTY) {
if (this.getStackInSlot(this.input1) == ItemStack.EMPTY || this.getStackInSlot(this.input2) == ItemStack.EMPTY) {
return false;
} else {
ItemStack itemstack = null;
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
if (hasAllInputs(recipeType)) {
for (final IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
if (this.hasAllInputs(recipeType)) {
itemstack = recipeType.getOutput(0);
break;
}
@ -159,12 +165,12 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
if (itemstack == null)
return false;
if (this.getStackInSlot(output) == ItemStack.EMPTY)
if (this.getStackInSlot(this.output) == ItemStack.EMPTY)
return true;
if (!this.getStackInSlot(output).isItemEqual(itemstack))
if (!this.getStackInSlot(this.output).isItemEqual(itemstack))
return false;
int result = getStackInSlot(output).getCount() + itemstack.getCount();
return result <= getInventoryStackLimit() && result <= this.getStackInSlot(output).getMaxStackSize(); // Forge
final int result = this.getStackInSlot(this.output).getCount() + itemstack.getCount();
return result <= this.getInventoryStackLimit() && result <= this.getStackInSlot(this.output).getMaxStackSize(); // Forge
// BugFix:
// Make
// it
@ -182,8 +188,8 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
public void smeltItem() {
if (this.canSmelt()) {
ItemStack itemstack = null;
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
if (hasAllInputs(recipeType)) {
for (final IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
if (this.hasAllInputs(recipeType)) {
itemstack = recipeType.getOutput(0);
break;
}
@ -192,15 +198,15 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
}
}
if (this.getStackInSlot(output) == ItemStack.EMPTY) {
setInventorySlotContents(output, itemstack.copy());
} else if (this.getStackInSlot(output).getItem() == itemstack.getItem()) {
decrStackSize(output, -itemstack.getCount());
if (this.getStackInSlot(this.output) == ItemStack.EMPTY) {
this.setInventorySlotContents(this.output, itemstack.copy());
} else if (this.getStackInSlot(this.output).getItem() == itemstack.getItem()) {
this.decrStackSize(this.output, -itemstack.getCount());
}
for (IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
for (final IBaseRecipeType recipeType : RecipeHandler.getRecipeClassFromName(Reference.alloySmelteRecipe)) {
boolean hasAllRecipes = true;
if (hasAllInputs(recipeType)) {
if (this.hasAllInputs(recipeType)) {
} else {
hasAllRecipes = false;
@ -209,8 +215,8 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
for (Object input : recipeType.getInputs()) {
boolean useOreDict = input instanceof String || recipeType.useOreDic();
for (int inputSlot = 0; inputSlot < 2; inputSlot++) {
if (ItemUtils.isInputEqual(input, inventory.getStackInSlot(inputSlot), true, true,
useOreDict)) {
if (ItemUtils.isInputEqual(input, this.inventory.getStackInSlot(inputSlot), true, true,
recipeType.useOreDic())) {
int count = 1;
if(input instanceof ItemStack){
count = RecipeTranslator.getStackFromObject(input).getCount();
@ -233,7 +239,7 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
return this.burnTime > 0;
}
public int getBurnTimeRemainingScaled(int scale) {
public int getBurnTimeRemainingScaled(final int scale) {
if (this.currentItemBurnTime == 0) {
this.currentItemBurnTime = 200;
}
@ -241,22 +247,22 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
return this.burnTime * scale / this.currentItemBurnTime;
}
public int getCookProgressScaled(int scale) {
public int getCookProgressScaled(final int scale) {
return this.cookTime * scale / 200;
}
@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();
}
@ -266,7 +272,7 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.IRON_ALLOY_FURNACE, 1);
}
@ -276,22 +282,68 @@ public class TileAlloyFurnace extends TileLegacyMachineBase implements IWrenchab
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return new int[] { 0, 1, 2 };
}
@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 || index == 1;
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
public boolean canExtractItem(final int index, final ItemStack stack, final EnumFacing direction) {
return index == 2;
}
public int getBurnTime()
{
return this.burnTime;
}
public void setBurnTime(final int burnTime)
{
this.burnTime = burnTime;
}
public int getCurrentItemBurnTime()
{
return this.currentItemBurnTime;
}
public void setCurrentItemBurnTime(final int currentItemBurnTime)
{
this.currentItemBurnTime = currentItemBurnTime;
}
public int getCookTime()
{
return this.cookTime;
}
public void setCookTime(final int cookTime)
{
this.cookTime = cookTime;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("alloyfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this)
.filterSlot(0, 47, 17,
stack -> RecipeHandler.recipeList.stream()
.anyMatch(recipe -> recipe instanceof AlloySmelterRecipe
&& ItemUtils.isInputEqual(recipe.getInputs().get(0), stack, true, true, true)))
.filterSlot(1, 65, 17,
stack -> RecipeHandler.recipeList.stream()
.anyMatch(recipe -> recipe instanceof AlloySmelterRecipe
&& ItemUtils.isInputEqual(recipe.getInputs().get(1), stack, true, true, true)))
.outputSlot(2, 116, 35).fuelSlot(3, 56, 53).syncIntegerValue(this::getBurnTime, this::setBurnTime)
.syncIntegerValue(this::getCookTime, this::setCookTime)
.syncIntegerValue(this::getCurrentItemBurnTime, this::setCurrentItemBurnTime).addInventory().create();
}
}

View file

@ -5,18 +5,27 @@ import net.minecraft.inventory.ISidedInventory;
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.recipe.RecipeHandler;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.api.Reference;
import techreborn.api.recipe.machines.AlloySmelterRecipe;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.utils.upgrade.UpgradeHandler;
public class TileAlloySmelter extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory, IRecipeCrafterProvider {
public class TileAlloySmelter extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, ISidedInventory, IRecipeCrafterProvider, IContainerProvider {
public int tickTime;
public Inventory inventory = new Inventory(8, "TileAlloySmelter", 64, this);
@ -27,35 +36,35 @@ public class TileAlloySmelter extends TilePowerAcceptor implements IWrenchable,
public TileAlloySmelter() {
super(1);
// Input slots
int[] inputs = new int[2];
final int[] inputs = new int[2];
inputs[0] = 0;
inputs[1] = 1;
int[] outputs = new int[1];
final int[] outputs = new int[1];
outputs[0] = 2;
crafter = new RecipeCrafter(Reference.alloySmelteRecipe, this, 2, 1, inventory, inputs, outputs);
upgrades = new UpgradeHandler(crafter, inventory, 4, 5, 6, 7);
this.crafter = new RecipeCrafter(Reference.alloySmelteRecipe, this, 2, 1, this.inventory, inputs, outputs);
this.upgrades = new UpgradeHandler(this.crafter, this.inventory, 4, 5, 6, 7);
}
@Override
public void update() {
super.update();
crafter.updateEntity();
upgrades.tick();
charge(3);
this.crafter.updateEntity();
this.upgrades.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();
}
@ -65,7 +74,7 @@ public class TileAlloySmelter extends TilePowerAcceptor implements IWrenchable,
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.ALLOY_SMELTER, 1);
}
@ -74,16 +83,16 @@ public class TileAlloySmelter extends TilePowerAcceptor implements IWrenchable,
}
@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;
}
@ -99,41 +108,41 @@ public class TileAlloySmelter extends TilePowerAcceptor implements IWrenchable,
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2 } : new int[] { 0, 1, 2 };
}
@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 == 2;
}
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;
}
@ -154,11 +163,28 @@ public class TileAlloySmelter extends TilePowerAcceptor implements IWrenchable,
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("alloysmelter").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this)
.filterSlot(0, 47, 17,
stack -> RecipeHandler.recipeList.stream()
.anyMatch(recipe -> recipe instanceof AlloySmelterRecipe
&& ItemUtils.isInputEqual(recipe.getInputs().get(0), stack, true, true, true)))
.filterSlot(1, 65, 17,
stack -> RecipeHandler.recipeList.stream()
.anyMatch(recipe -> recipe instanceof AlloySmelterRecipe
&& ItemUtils.isInputEqual(recipe.getInputs().get(1), stack, true, true, true)))
.outputSlot(2, 116, 35).energySlot(3, 56, 53).upgradeSlot(4, 152, 8).upgradeSlot(5, 152, 26)
.upgradeSlot(6, 152, 44).upgradeSlot(7, 152, 62).syncEnergyValue().syncCrafterValue().addInventory()
.create();
}
}

View file

@ -4,6 +4,7 @@ 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.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
@ -11,10 +12,15 @@ import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
public class TileAssemblingMachine extends TilePowerAcceptor implements IWrenchable, ISidedInventory, IInventoryProvider, IRecipeCrafterProvider {
public class TileAssemblingMachine extends TilePowerAcceptor
implements IWrenchable, ISidedInventory, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public int tickTime;
public Inventory inventory = new Inventory(8, "TileAssemblingMachine", 64, this);
@ -23,32 +29,32 @@ public class TileAssemblingMachine extends TilePowerAcceptor implements IWrencha
public TileAssemblingMachine() {
super(2);
// Input slots
int[] inputs = new int[2];
final int[] inputs = new int[2];
inputs[0] = 0;
inputs[1] = 1;
int[] outputs = new int[1];
final int[] outputs = new int[1];
outputs[0] = 2;
crafter = new RecipeCrafter(Reference.assemblingMachineRecipe, this, 2, 2, inventory, inputs, outputs);
this.crafter = new RecipeCrafter(Reference.assemblingMachineRecipe, this, 2, 2, this.inventory, inputs, outputs);
}
@Override
public void updateEntity() {
super.updateEntity();
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();
}
@ -58,7 +64,7 @@ public class TileAssemblingMachine extends TilePowerAcceptor implements IWrencha
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.ASSEMBLY_MACHINE, 1);
}
@ -76,9 +82,9 @@ public class TileAssemblingMachine extends TilePowerAcceptor implements IWrencha
// }
// }
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;
}
@ -89,12 +95,12 @@ public class TileAssemblingMachine extends TilePowerAcceptor implements IWrencha
}
@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;
}
@ -115,27 +121,34 @@ public class TileAssemblingMachine extends TilePowerAcceptor implements IWrencha
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return new int[] { 0, 1, 2 };
}
@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 || index == 1;
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
public boolean canExtractItem(final int index, final ItemStack stack, final EnumFacing direction) {
return index == 2;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("assemblingmachine").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 47, 17).slot(1, 65, 17).outputSlot(2, 116, 35).energySlot(3, 56, 53)
.upgradeSlot(4, 152, 8).upgradeSlot(5, 152, 26).upgradeSlot(6, 152, 44).upgradeSlot(7, 152, 62)
.syncEnergyValue().syncCrafterValue().addInventory().create();
}
}

View file

@ -15,6 +15,9 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.items.DynamicCell;
@ -23,7 +26,7 @@ import techreborn.utils.upgrade.UpgradeHandler;
import java.util.List;
public class TileCentrifuge extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IListInfoProvider, IRecipeCrafterProvider {
implements IWrenchable, IInventoryProvider, IListInfoProvider, IRecipeCrafterProvider, IContainerProvider {
public int tickTime;
public Inventory inventory = new Inventory(11, "TileCentrifuge", 64, this);
@ -35,30 +38,30 @@ public class TileCentrifuge extends TilePowerAcceptor
public TileCentrifuge() {
super(2);
// Input slots
int[] inputs = new int[] { 0, 1 };
int[] outputs = new int[4];
final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[4];
outputs[0] = 2;
outputs[1] = 3;
outputs[2] = 4;
outputs[3] = 5;
crafter = new RecipeCrafter(Reference.centrifugeRecipe, this, 2, 4, inventory, inputs, outputs);
upgradeHandler = new UpgradeHandler(crafter, inventory, 7, 8, 9, 10);
this.crafter = new RecipeCrafter(Reference.centrifugeRecipe, this, 2, 4, this.inventory, inputs, outputs);
this.upgradeHandler = new UpgradeHandler(this.crafter, this.inventory, 7, 8, 9, 10);
}
@Override
public void updateEntity() {
super.updateEntity();
crafter.updateEntity();
upgradeHandler.tick();
charge(6);
if (inventory.getStackInSlot(6) != ItemStack.EMPTY) {
ItemStack stack = inventory.getStackInSlot(6);
this.crafter.updateEntity();
this.upgradeHandler.tick();
this.charge(6);
if (this.inventory.getStackInSlot(6) != ItemStack.EMPTY) {
final ItemStack stack = this.inventory.getStackInSlot(6);
if (stack.getItem() instanceof IEnergyItemInfo) {
IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem();
final IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem();
if (item.canProvideEnergy(stack)) {
if (getEnergy() != getMaxPower()) {
addEnergy(item.getMaxTransfer(stack));
if (this.getEnergy() != this.getMaxPower()) {
this.addEnergy(item.getMaxTransfer(stack));
PoweredItem.setEnergy(PoweredItem.getEnergy(stack) - item.getMaxTransfer(stack), stack);
}
}
@ -67,17 +70,17 @@ public class TileCentrifuge extends TilePowerAcceptor
}
@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();
}
@ -87,7 +90,7 @@ public class TileCentrifuge extends TilePowerAcceptor
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.INDUSTRIAL_CENTRIFUGE, 1);
}
@ -96,44 +99,44 @@ public class TileCentrifuge extends TilePowerAcceptor
}
@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;
}
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3, 4, 5 } : new int[] { 0, 1, 2, 3, 4, 5 };
}
@Override
public boolean canInsertItem(int index, ItemStack itemStackIn, EnumFacing direction) {
public boolean canInsertItem(final int index, final ItemStack itemStackIn, final EnumFacing direction) {
return itemStackIn.isItemEqual(DynamicCell.getEmptyCell(1).copy()) ? index == 1 : index == 0;
}
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
return slotIndex >= 2 && slotIndex <= 5;
}
@Override
public void addInfo(List<String> info, boolean isRealTile) {
public void addInfo(final List<String> info, final boolean isRealTile) {
super.addInfo(info, isRealTile);
info.add("Round and round it goes");
}
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;
}
@ -144,12 +147,12 @@ public class TileCentrifuge extends TilePowerAcceptor
}
@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;
}
@ -170,12 +173,20 @@ public class TileCentrifuge extends TilePowerAcceptor
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("centrifuge").player(player.inventory).inventory().hotbar()
.addInventory().tile(this).slot(0, 40, 34).slot(1, 40, 54).outputSlot(2, 82, 44).outputSlot(3, 101, 25)
.outputSlot(4, 120, 44).outputSlot(5, 101, 63).energySlot(6, 8, 72).syncEnergyValue()
.syncCrafterValue().addInventory().create();
}
}

View file

@ -4,15 +4,21 @@ 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.power.IEnergyInterfaceItem;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
public class TileChargeBench extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory {
public class TileChargeBench extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, ISidedInventory, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileChargeBench", 64, this);
public int capacity = 100000;
@ -26,15 +32,15 @@ public class TileChargeBench extends TilePowerAcceptor implements IWrenchable, I
super.updateEntity();
for (int i = 0; i < 6; i++) {
if (inventory.getStackInSlot(i) != ItemStack.EMPTY) {
if (getEnergy() > 0) {
ItemStack stack = inventory.getStackInSlot(i);
if (this.inventory.getStackInSlot(i) != ItemStack.EMPTY) {
if (this.getEnergy() > 0) {
final ItemStack stack = this.inventory.getStackInSlot(i);
if (stack.getItem() instanceof IEnergyInterfaceItem) {
IEnergyInterfaceItem interfaceItem = (IEnergyInterfaceItem) stack.getItem();
double trans = Math.min(interfaceItem.getMaxPower(stack) - interfaceItem.getEnergy(stack),
Math.min(interfaceItem.getMaxTransfer(stack), getEnergy()));
final IEnergyInterfaceItem interfaceItem = (IEnergyInterfaceItem) stack.getItem();
final double trans = Math.min(interfaceItem.getMaxPower(stack) - interfaceItem.getEnergy(stack),
Math.min(interfaceItem.getMaxTransfer(stack), this.getEnergy()));
interfaceItem.setEnergy(trans + interfaceItem.getEnergy(stack), stack);
useEnergy(trans);
this.useEnergy(trans);
}
}
}
@ -42,17 +48,17 @@ public class TileChargeBench extends TilePowerAcceptor implements IWrenchable, I
}
@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();
}
@ -62,7 +68,7 @@ public class TileChargeBench extends TilePowerAcceptor implements IWrenchable, I
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.CHARGE_O_MAT, 1);
}
@ -72,17 +78,17 @@ public class TileChargeBench extends TilePowerAcceptor implements IWrenchable, I
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3, 4, 5 } : new int[] { 0, 1, 2, 3, 4, 5 };
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
return isItemValidForSlot(slotIndex, itemStack);
public boolean canInsertItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
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) {
// if (itemStack.getItem() instanceof IElectricItem) {
// double CurrentCharge = ElectricItem.manager.getCharge(itemStack);
// double MaxCharge = ((IElectricItem)
@ -95,16 +101,16 @@ public class TileChargeBench extends TilePowerAcceptor implements IWrenchable, I
@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;
}
@ -125,6 +131,13 @@ public class TileChargeBench extends TilePowerAcceptor implements IWrenchable, I
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("chargebench").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).energySlot(0, 62, 25).energySlot(1, 98, 25).energySlot(2, 62, 45).energySlot(3, 98, 45)
.energySlot(4, 62, 65).energySlot(5, 98, 65).syncEnergyValue().addInventory().create();
}
}

View file

@ -13,9 +13,13 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
public class TileChemicalReactor extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory, IRecipeCrafterProvider {
public class TileChemicalReactor extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, ISidedInventory, IRecipeCrafterProvider, IContainerProvider {
public int tickTime;
public Inventory inventory = new Inventory(8, "TileChemicalReactor", 64, this);
@ -24,33 +28,33 @@ public class TileChemicalReactor extends TilePowerAcceptor implements IWrenchabl
public TileChemicalReactor() {
super(2);
// Input slots
int[] inputs = new int[2];
final int[] inputs = new int[2];
inputs[0] = 0;
inputs[1] = 1;
int[] outputs = new int[1];
final int[] outputs = new int[1];
outputs[0] = 2;
crafter = new RecipeCrafter(Reference.chemicalReactorRecipe, this, 2, 2, inventory, inputs, outputs);
this.crafter = new RecipeCrafter(Reference.chemicalReactorRecipe, this, 2, 2, this.inventory, inputs, outputs);
}
@Override
public void updateEntity() {
super.updateEntity();
crafter.updateEntity();
charge(3);
this.crafter.updateEntity();
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();
}
@ -60,7 +64,7 @@ public class TileChemicalReactor extends TilePowerAcceptor implements IWrenchabl
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.CHEMICAL_REACTOR, 1);
}
@ -69,33 +73,33 @@ public class TileChemicalReactor extends TilePowerAcceptor implements IWrenchabl
}
@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;
}
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2 } : new int[] { 0, 1, 2 };
}
@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 == 2;
}
@ -109,9 +113,9 @@ public class TileChemicalReactor extends TilePowerAcceptor implements IWrenchabl
// }
// }
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;
}
@ -122,12 +126,12 @@ public class TileChemicalReactor extends TilePowerAcceptor implements IWrenchabl
}
@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;
}
@ -148,11 +152,18 @@ public class TileChemicalReactor extends TilePowerAcceptor implements IWrenchabl
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("chemicalreactor").player(player.inventory).inventory().hotbar()
.addInventory().tile(this).slot(0, 34, 47).slot(1, 126, 47).outputSlot(2, 80, 47).energySlot(3, 8, 72)
.syncEnergyValue().syncCrafterValue().addInventory().create();
}
}

View file

@ -3,14 +3,19 @@ package techreborn.tiles;
import net.minecraft.entity.player.EntityPlayer;
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.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
public class TileChunkLoader extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
public class TileChunkLoader extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, IContainerProvider {
public Inventory inventory = new Inventory(1, "TileChunkLoader", 64, this);
@ -24,17 +29,17 @@ public class TileChunkLoader extends TilePowerAcceptor implements IWrenchable, I
}
@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();
}
@ -44,7 +49,7 @@ public class TileChunkLoader extends TilePowerAcceptor implements IWrenchable, I
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.CHUNK_LOADER, 1);
}
@ -58,12 +63,12 @@ public class TileChunkLoader extends TilePowerAcceptor implements IWrenchable, I
}
@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;
}
@ -84,6 +89,12 @@ public class TileChunkLoader extends TilePowerAcceptor implements IWrenchable, I
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("chunkloader").player(player.inventory).inventory().hotbar().addInventory()
.create();
}
}

View file

@ -1,8 +1,19 @@
package techreborn.tiles;
public class TileDigitalChest extends TileTechStorageBase {
import net.minecraft.entity.player.EntityPlayer;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
public class TileDigitalChest extends TileTechStorageBase implements IContainerProvider {
public TileDigitalChest() {
super("TileDigitalChest", Short.MAX_VALUE);
super("TileDigitalChest", 32768);
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("digitalchest").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).slot(0, 80, 24).outputSlot(1, 80, 64).addInventory().create();
}
}

View file

@ -5,6 +5,7 @@ import net.minecraft.inventory.ISidedInventory;
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.IInventoryProvider;
@ -12,10 +13,15 @@ import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
public class TileIndustrialElectrolyzer extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory, IRecipeCrafterProvider {
public class TileIndustrialElectrolyzer extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, ISidedInventory, IRecipeCrafterProvider, IContainerProvider {
public int tickTime;
public Inventory inventory = new Inventory(8, "TileIndustrialElectrolyzer", 64, this);
@ -24,36 +30,36 @@ public class TileIndustrialElectrolyzer extends TilePowerAcceptor implements IWr
public TileIndustrialElectrolyzer() {
super(2);
// Input slots
int[] inputs = new int[2];
final int[] inputs = new int[2];
inputs[0] = 0;
inputs[1] = 1;
int[] outputs = new int[4];
final int[] outputs = new int[4];
outputs[0] = 2;
outputs[1] = 3;
outputs[2] = 4;
outputs[3] = 5;
crafter = new RecipeCrafter(Reference.industrialElectrolyzerRecipe, this, 2, 4, inventory, inputs, outputs);
this.crafter = new RecipeCrafter(Reference.industrialElectrolyzerRecipe, this, 2, 4, this.inventory, inputs, outputs);
}
@Override
public void updateEntity() {
super.updateEntity();
crafter.updateEntity();
charge(6);
this.crafter.updateEntity();
this.charge(6);
}
@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();
}
@ -63,7 +69,7 @@ public class TileIndustrialElectrolyzer extends TilePowerAcceptor implements IWr
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.INDUSTRIAL_ELECTROLYZER, 1);
}
@ -72,15 +78,15 @@ public class TileIndustrialElectrolyzer extends TilePowerAcceptor implements IWr
}
@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;
}
@ -96,25 +102,25 @@ public class TileIndustrialElectrolyzer extends TilePowerAcceptor implements IWr
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3, 4, 5 } : new int[] { 0, 1, 2, 3, 4, 5 };
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side) {
public boolean canInsertItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
if (slotIndex >= 1)
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 == 2 || slotIndex == 3 || slotIndex == 4 || slotIndex == 5;
}
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;
}
@ -125,12 +131,12 @@ public class TileIndustrialElectrolyzer extends TilePowerAcceptor implements IWr
}
@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;
}
@ -151,11 +157,19 @@ public class TileIndustrialElectrolyzer extends TilePowerAcceptor implements IWr
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("industrialelectrolyzer").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 80, 51).slot(1, 50, 51).outputSlot(2, 50, 19).outputSlot(3, 70, 19)
.outputSlot(4, 90, 19).outputSlot(5, 110, 19).energySlot(6, 18, 51).syncEnergyValue().syncCrafterValue()
.addInventory().create();
}
}

View file

@ -1,6 +1,7 @@
package techreborn.tiles;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
@ -8,12 +9,18 @@ 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;
import reborncore.common.util.Inventory;
public class TileIronFurnace extends TileLegacyMachineBase implements IInventoryProvider, ISidedInventory {
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
public class TileIronFurnace extends TileLegacyMachineBase
implements IInventoryProvider, ISidedInventory, IContainerProvider {
private static final int[] SLOTS_TOP = new int[] { 0 };
private static final int[] SLOTS_BOTTOM = new int[] { 2, 1 };
@ -30,100 +37,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 +136,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 +171,28 @@ 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;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("ironfurnace").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 56, 17).outputSlot(1, 116, 34).fuelSlot(2, 56, 53)
.syncIntegerValue(this::getBurnTime, this::setBurnTime)
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create();
}
}

View file

@ -3,17 +3,23 @@ package techreborn.tiles;
import net.minecraft.entity.player.EntityPlayer;
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.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.init.ModItems;
import techreborn.items.ItemParts;
public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
public class TileMatterFabricator extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IContainerProvider {
public static int fabricationRate = 10000;
public int tickTime;
@ -27,17 +33,17 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
@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();
}
@ -47,7 +53,7 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.MATTER_FABRICATOR, 1);
}
@ -77,7 +83,7 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
// }
public int maxProgresstime() {
return fabricationRate;
return TileMatterFabricator.fabricationRate;
}
@Override
@ -86,14 +92,14 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
if (!super.world.isRemote) {
for (int i = 0; i < 6; i++) {
ItemStack stack = inventory.getStackInSlot(i);
final ItemStack stack = this.inventory.getStackInSlot(i);
if (this.amplifier < 10000 && stack != ItemStack.EMPTY) {
int amp = (int) ((long) (getValue(stack) / 32));
if (ItemUtils.isItemEqual(stack, inventory.getStackInSlot(i), true, true)) {
if (canUseEnergy(1)) {
useEnergy(1);
final int amp = this.getValue(stack) / 32;
if (ItemUtils.isItemEqual(stack, this.inventory.getStackInSlot(i), true, true)) {
if (this.canUseEnergy(1)) {
this.useEnergy(1);
this.amplifier += amp;
inventory.decrStackSize(i, 1);
this.inventory.decrStackSize(i, 1);
}
}
}
@ -120,27 +126,27 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
private boolean spaceForOutput() {
return inventory.getStackInSlot(6) == ItemStack.EMPTY
|| ItemUtils.isItemEqual(inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)
&& inventory.getStackInSlot(6).getCount() < 64;
return this.inventory.getStackInSlot(6) == ItemStack.EMPTY
|| ItemUtils.isItemEqual(this.inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)
&& this.inventory.getStackInSlot(6).getCount() < 64;
}
private void addOutputProducts() {
if (inventory.getStackInSlot(6) == ItemStack.EMPTY) {
inventory.setInventorySlotContents(6, new ItemStack(ModItems.UU_MATTER));
} else if (ItemUtils.isItemEqual(inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)) {
inventory.getStackInSlot(6).setCount(Math.min(64, 1 + inventory.getStackInSlot(6).getCount()));
if (this.inventory.getStackInSlot(6) == ItemStack.EMPTY) {
this.inventory.setInventorySlotContents(6, new ItemStack(ModItems.UU_MATTER));
} else if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(6), new ItemStack(ModItems.UU_MATTER), true, true)) {
this.inventory.getStackInSlot(6).setCount(Math.min(64, 1 + this.inventory.getStackInSlot(6).getCount()));
}
}
public boolean decreaseStoredEnergy(double aEnergy, boolean aIgnoreTooLessEnergy) {
public boolean decreaseStoredEnergy(final double aEnergy, final boolean aIgnoreTooLessEnergy) {
if (this.getEnergy() - aEnergy < 0 && !aIgnoreTooLessEnergy) {
return false;
} else {
setEnergy(this.getEnergy() - aEnergy);
this.setEnergy(this.getEnergy() - aEnergy);
if (this.getEnergy() < 0) {
setEnergy(0);
this.setEnergy(0);
return false;
} else {
return true;
@ -149,7 +155,7 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
// TODO ic2
public int getValue(ItemStack itemStack) {
public int getValue(final ItemStack itemStack) {
// int value = getValue(Recipes.matterAmplifier.getOutputFor(itemStack,
// false));
if (itemStack.getItem() == ModItems.PARTS && itemStack.getItemDamage() == ItemParts.getPartByName("scrap").getItemDamage()) {
@ -173,12 +179,12 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
}
@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;
}
@ -199,6 +205,29 @@ public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchab
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int getProgress() {
return this.progresstime;
}
public void setProgress(final int progress) {
this.progresstime = progress;
}
public int getProgressScaled(final int scale) {
if (this.progresstime != 0) {
return this.progresstime * scale / this.maxProgresstime();
}
return 0;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("matterfabricator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 33, 17).slot(1, 33, 35).slot(2, 33, 53).slot(3, 51, 17)
.slot(4, 51, 35).slot(5, 51, 53).outputSlot(6, 116, 35).syncEnergyValue()
.syncIntegerValue(this::getProgress, this::setProgress).addInventory().create();
}
}

View file

@ -1,8 +1,19 @@
package techreborn.tiles;
public class TileQuantumChest extends TileTechStorageBase {
import net.minecraft.entity.player.EntityPlayer;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
public class TileQuantumChest extends TileTechStorageBase implements IContainerProvider {
public TileQuantumChest() {
super("TileQuantumChest", Integer.MAX_VALUE);
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("quantumchest").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).slot(0, 80, 24).outputSlot(1, 80, 64).addInventory().create();
}
}

View file

@ -8,6 +8,7 @@ import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import reborncore.api.IListInfoProvider;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
@ -15,63 +16,67 @@ import reborncore.common.tile.TileLegacyMachineBase;
import reborncore.common.util.FluidUtils;
import reborncore.common.util.Inventory;
import reborncore.common.util.Tank;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import java.util.List;
public class TileQuantumTank extends TileLegacyMachineBase
implements IInventoryProvider, IWrenchable, IListInfoProvider {
implements IInventoryProvider, IWrenchable, IListInfoProvider, IContainerProvider {
public Tank tank = new Tank("TileQuantumTank", Integer.MAX_VALUE, this);
public Inventory inventory = new Inventory(3, "TileQuantumTank", 64, this);
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
readFromNBTWithoutCoords(tagCompound);
this.readFromNBTWithoutCoords(tagCompound);
}
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {
tank.readFromNBT(tagCompound);
public void readFromNBTWithoutCoords(final NBTTagCompound tagCompound) {
this.tank.readFromNBT(tagCompound);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
writeToNBTWithoutCoords(tagCompound);
this.writeToNBTWithoutCoords(tagCompound);
return tagCompound;
}
public NBTTagCompound writeToNBTWithoutCoords(NBTTagCompound tagCompound) {
tank.writeToNBT(tagCompound);
public NBTTagCompound writeToNBTWithoutCoords(final NBTTagCompound tagCompound) {
this.tank.writeToNBT(tagCompound);
return tagCompound;
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
getPos().getY(), getPos().getZ());
readFromNBT(packet.getNbtCompound());
public void onDataPacket(final NetworkManager net, final SPacketUpdateTileEntity packet) {
this.world.markBlockRangeForRenderUpdate(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(),
this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
this.readFromNBT(packet.getNbtCompound());
}
@Override
public void updateEntity() {
super.updateEntity();
if (!world.isRemote) {
if (FluidUtils.drainContainers(tank, inventory, 0, 1)
|| FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluidType()))
if (!this.world.isRemote) {
if (FluidUtils.drainContainers(this.tank, this.inventory, 0, 1)
|| FluidUtils.fillContainers(this.tank, this.inventory, 0, 1, this.tank.getFluidType()))
this.syncWithAll();
if (tank.getFluidType() != null && getStackInSlot(2) == ItemStack.EMPTY) {
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) {
setInventorySlotContents(2, ItemStack.EMPTY);
if (this.tank.getFluidType() != null && this.getStackInSlot(2) == ItemStack.EMPTY) {
this.inventory.setInventorySlotContents(2, new ItemStack(this.tank.getFluidType().getBlock()));
} else if (this.tank.getFluidType() == null && this.getStackInSlot(2) != ItemStack.EMPTY) {
this.setInventorySlotContents(2, ItemStack.EMPTY);
}
}
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
public boolean hasCapability(final Capability<?> capability, final EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return true;
}
@ -79,25 +84,25 @@ public class TileQuantumTank extends TileLegacyMachineBase
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
public <T> T getCapability(final Capability<T> capability, final EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return (T) tank;
return (T) this.tank;
}
return super.getCapability(capability, facing);
}
@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();
}
@ -107,34 +112,41 @@ public class TileQuantumTank extends TileLegacyMachineBase
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
return getDropWithNBT();
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return this.getDropWithNBT();
}
public ItemStack getDropWithNBT() {
NBTTagCompound tileEntity = new NBTTagCompound();
ItemStack dropStack = new ItemStack(ModBlocks.QUANTUM_TANK, 1);
writeToNBTWithoutCoords(tileEntity);
final NBTTagCompound tileEntity = new NBTTagCompound();
final ItemStack dropStack = new ItemStack(ModBlocks.QUANTUM_TANK, 1);
this.writeToNBTWithoutCoords(tileEntity);
dropStack.setTagCompound(new NBTTagCompound());
dropStack.getTagCompound().setTag("tileEntity", tileEntity);
return dropStack;
}
@Override
public void addInfo(List<String> info, boolean isRealTile) {
public void addInfo(final List<String> info, final boolean isRealTile) {
if (isRealTile) {
if (tank.getFluid() != null) {
info.add(tank.getFluidAmount() + " of " + tank.getFluidType().getName());
if (this.tank.getFluid() != null) {
info.add(this.tank.getFluidAmount() + " of " + this.tank.getFluidType().getName());
} else {
info.add("Empty");
}
}
info.add("Capacity " + tank.getCapacity() + " mb");
info.add("Capacity " + this.tank.getCapacity() + " mb");
}
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("quantumtank").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).fluidSlot(0, 80, 17).outputSlot(1, 80, 53).fakeSlot(2, 59, 42).addInventory()
.create();
}
}

View file

@ -6,17 +6,23 @@ import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.api.RollingMachineRecipe;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
//TODO add tick and power bars.
public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
public class TileRollingMachine extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IContainerProvider {
public final InventoryCrafting craftMatrix = new InventoryCrafting(new RollingTileContainer(), 3, 3);
public Inventory inventory = new Inventory(3, "TileRollingMachine", 64, this);
@ -37,12 +43,12 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable
}
@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;
}
@ -64,72 +70,72 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable
@Override
public void updateEntity() {
super.updateEntity();
charge(2);
if (!world.isRemote) {
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world);
if (currentRecipe != null && canMake()) {
if (tickTime >= runTime) {
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world);
if (currentRecipe != null) {
this.charge(2);
if (!this.world.isRemote) {
this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world);
if (this.currentRecipe != null && this.canMake()) {
if (this.tickTime >= this.runTime) {
this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world);
if (this.currentRecipe != null) {
boolean hasCrafted = false;
if (inventory.getStackInSlot(0) == ItemStack.EMPTY) {
inventory.setInventorySlotContents(0, currentRecipe);
tickTime = -1;
if (this.inventory.getStackInSlot(0) == ItemStack.EMPTY) {
this.inventory.setInventorySlotContents(0, this.currentRecipe);
this.tickTime = -1;
hasCrafted = true;
} else {
if (inventory.getStackInSlot(0).getCount() + currentRecipe.getCount() <= currentRecipe
.getMaxStackSize()) {
ItemStack stack = inventory.getStackInSlot(0);
stack.setCount(stack.getCount() + currentRecipe.getCount());
inventory.setInventorySlotContents(0, stack);
tickTime = -1;
if (this.inventory.getStackInSlot(0).getCount() + this.currentRecipe.getCount() <= this.currentRecipe
.getMaxStackSize()) {
final ItemStack stack = this.inventory.getStackInSlot(0);
stack.setCount(stack.getCount() + this.currentRecipe.getCount());
this.inventory.setInventorySlotContents(0, stack);
this.tickTime = -1;
hasCrafted = true;
}
}
if (hasCrafted) {
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
craftMatrix.decrStackSize(i, 1);
for (int i = 0; i < this.craftMatrix.getSizeInventory(); i++) {
this.craftMatrix.decrStackSize(i, 1);
}
currentRecipe = null;
this.currentRecipe = null;
}
}
}
}
if (currentRecipe != null) {
if (canUseEnergy(euTick) && tickTime < runTime) {
useEnergy(euTick);
tickTime++;
if (this.currentRecipe != null) {
if (this.canUseEnergy(this.euTick) && this.tickTime < this.runTime) {
this.useEnergy(this.euTick);
this.tickTime++;
}
}
if (currentRecipe == null) {
tickTime = -1;
if (this.currentRecipe == null) {
this.tickTime = -1;
}
} else {
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world);
if (currentRecipe != null) {
inventory.setInventorySlotContents(1, currentRecipe);
this.currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world);
if (this.currentRecipe != null) {
this.inventory.setInventorySlotContents(1, this.currentRecipe);
} else {
inventory.setInventorySlotContents(1, ItemStack.EMPTY);
this.inventory.setInventorySlotContents(1, ItemStack.EMPTY);
}
}
}
public boolean canMake() {
return RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world) != null;
return RollingMachineRecipe.instance.findMatchingRecipe(this.craftMatrix, this.world) != null;
}
@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,29 +145,29 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.ROLLING_MACHINE, 1);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound);
isRunning = tagCompound.getBoolean("isRunning");
tickTime = tagCompound.getInteger("tickTime");
ItemUtils.readInvFromNBT(this.craftMatrix, "Crafting", tagCompound);
this.isRunning = tagCompound.getBoolean("isRunning");
this.tickTime = tagCompound.getInteger("tickTime");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound);
writeUpdateToNBT(tagCompound);
ItemUtils.writeInvToNBT(this.craftMatrix, "Crafting", tagCompound);
this.writeUpdateToNBT(tagCompound);
return tagCompound;
}
public void writeUpdateToNBT(NBTTagCompound tagCompound) {
tagCompound.setBoolean("isRunning", isRunning);
tagCompound.setInteger("tickTime", tickTime);
public void writeUpdateToNBT(final NBTTagCompound tagCompound) {
tagCompound.setBoolean("isRunning", this.isRunning);
tagCompound.setInteger("tickTime", this.tickTime);
}
@Override
@ -176,15 +182,41 @@ public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
private static class RollingTileContainer extends Container {
@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
public boolean canInteractWith(final EntityPlayer entityplayer) {
return true;
}
}
public int getBurnTime() {
return this.tickTime;
}
public void setBurnTime(final int burnTime) {
this.tickTime = burnTime;
}
public int getBurnTimeRemainingScaled(final int scale) {
if (this.tickTime == 0 || this.runTime == 0) {
return 0;
}
return this.tickTime * scale / this.runTime;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("rollingmachine").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this.craftMatrix).slot(0, 30, 17).slot(1, 48, 17).slot(2, 66, 17).slot(3, 30, 35)
.slot(4, 48, 35).slot(5, 66, 35).slot(6, 30, 53).slot(7, 48, 53).slot(8, 66, 53)
.onCraft(inv -> this.inventory.setInventorySlotContents(1,
RollingMachineRecipe.instance.findMatchingRecipe(inv, this.world)))
.addInventory().tile(this).outputSlot(0, 124, 35).energySlot(2, 8, 51).syncEnergyValue()
.syncIntegerValue(this::getBurnTime, this::setBurnTime).addInventory().create();
}
}

View file

@ -5,19 +5,25 @@ 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.api.ScrapboxList;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.init.ModItems;
import java.util.Random;
public class TileScrapboxinator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory {
public class TileScrapboxinator extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, ISidedInventory, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileScrapboxinator", 64, this);
public int capacity = 1000;
@ -33,88 +39,88 @@ public class TileScrapboxinator extends TilePowerAcceptor implements IWrenchable
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() {
boolean burning = isBurning();
final boolean burning = this.isBurning();
boolean updateInventory = false;
if (getEnergy() <= cost && canOpen()) {
if (getEnergy() > cost) {
if (this.getEnergy() <= this.cost && this.canOpen()) {
if (this.getEnergy() > this.cost) {
updateInventory = true;
}
}
if (isBurning() && canOpen()) {
updateState();
if (this.isBurning() && this.canOpen()) {
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.canOpen() && !world.isRemote) {
int random = new Random().nextInt(ScrapboxList.stacks.size());
ItemStack out = ScrapboxList.stacks.get(random).copy();
if (getStackInSlot(output) == null) {
useEnergy(cost);
setInventorySlotContents(output, out);
if (this.canOpen() && !this.world.isRemote) {
final int random = new Random().nextInt(ScrapboxList.stacks.size());
final ItemStack out = ScrapboxList.stacks.get(random).copy();
if (this.getStackInSlot(this.output) == null) {
this.useEnergy(this.cost);
this.setInventorySlotContents(this.output, out);
}
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 canOpen() {
return getStackInSlot(input1) != ItemStack.EMPTY && getStackInSlot(output) == ItemStack.EMPTY;
return this.getStackInSlot(this.input1) != ItemStack.EMPTY && this.getStackInSlot(this.output) == ItemStack.EMPTY;
}
public boolean isBurning() {
return getEnergy() > cost;
return this.getEnergy() > this.cost;
}
public void updateState() {
IBlockState blockState = world.getBlockState(pos);
final IBlockState blockState = this.world.getBlockState(this.pos);
if (blockState.getBlock() instanceof BlockMachineBase) {
BlockMachineBase blockMachineBase = (BlockMachineBase) blockState.getBlock();
if (blockState.getValue(BlockMachineBase.ACTIVE) != progress > 0)
blockMachineBase.setActive(progress > 0, world, pos);
final BlockMachineBase blockMachineBase = (BlockMachineBase) blockState.getBlock();
if (blockState.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();
}
@ -124,7 +130,7 @@ public class TileScrapboxinator extends TilePowerAcceptor implements IWrenchable
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.SCRAPBOXINATOR, 1);
}
@ -134,12 +140,12 @@ public class TileScrapboxinator extends TilePowerAcceptor implements IWrenchable
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2 } : new int[] { 0, 1, 2 };
}
@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;
if (slotIndex == 1) {
@ -147,26 +153,26 @@ public class TileScrapboxinator extends TilePowerAcceptor implements IWrenchable
return true;
}
}
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 == 2;
}
@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;
}
@ -187,6 +193,23 @@ public class TileScrapboxinator extends TilePowerAcceptor implements IWrenchable
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int getProgress() {
return this.progress;
}
public void setProgress(final int progress) {
this.progress = progress;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("scrapboxinator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).filterSlot(0, 56, 34, stack -> stack.getItem() == ModItems.SCRAP_BOX)
.outputSlot(1, 116, 34).upgradeSlot(2, 152, 8).upgradeSlot(3, 152, 26).upgradeSlot(4, 152, 44)
.upgradeSlot(5, 152, 62).syncEnergyValue().syncIntegerValue(this::getProgress, this::setProgress)
.addInventory().create();
}
}

View file

@ -9,9 +9,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.wrapper.InvWrapper;
import powercrystals.minefactoryreloaded.api.IDeepStorageUnit;
import reborncore.api.IListInfoProvider;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
@ -23,14 +21,12 @@ import java.util.ArrayList;
import java.util.List;
public class TileTechStorageBase extends TileLegacyMachineBase
implements IInventoryProvider, IWrenchable, IListInfoProvider, IDeepStorageUnit {
public InvWrapper invWrapper;
public ItemStack storedItem;
implements IInventoryProvider, IWrenchable, IListInfoProvider, IDeepStorageUnit {
public final int maxCapacity;
public final Inventory inventory;
public InvWrapper invWrapper;
public ItemStack storedItem;
public TileTechStorageBase(String name, int maxCapacity) {
this.maxCapacity = maxCapacity;
@ -43,7 +39,7 @@ public class TileTechStorageBase extends TileLegacyMachineBase
if (!world.isRemote) {
if (this.getStackInSlot(0) != ItemStack.EMPTY) {
if (this.getStoredItemType().isEmpty() || (this.storedItem.isEmpty()
&& ItemUtils.isItemEqual(this.getStackInSlot(0), this.getStackInSlot(1), true, true))) {
&& ItemUtils.isItemEqual(this.getStackInSlot(0), this.getStackInSlot(1), true, true))) {
this.storedItem = this.getStackInSlot(0);
this.setInventorySlotContents(0, ItemStack.EMPTY);
@ -70,10 +66,10 @@ public class TileTechStorageBase extends TileLegacyMachineBase
this.setInventorySlotContents(1, delivered);
this.syncWithAll();
} else if (ItemUtils.isItemEqual(this.storedItem, this.getStackInSlot(1), true, true)
&& this.getStackInSlot(1).getCount() < this.getStackInSlot(1).getMaxStackSize()) {
&& this.getStackInSlot(1).getCount() < this.getStackInSlot(1).getMaxStackSize()) {
int wanted = Math.min(this.storedItem.getCount(),
this.getStackInSlot(1).getMaxStackSize() - this.getStackInSlot(1).getCount());
this.getStackInSlot(1).getMaxStackSize() - this.getStackInSlot(1).getCount());
this.getStackInSlot(1).setCount(this.getStackInSlot(1).getCount() + wanted);
this.storedItem.shrink(wanted);
@ -83,28 +79,13 @@ public class TileTechStorageBase extends TileLegacyMachineBase
this.syncWithAll();
}
}
if (this.getStackInSlot(2) == ItemStack.EMPTY
&& (!this.storedItem.isEmpty() || !this.getStackInSlot(1).isEmpty())) {
ItemStack fake = storedItem.isEmpty() ? this.getStackInSlot(1).copy() : storedItem.copy();
fake.setCount(1);
this.setInventorySlotContents(2, fake);
} else if (!ItemUtils.isItemEqual(this.getStackInSlot(2), this.storedItem, true, true)) {
ItemStack fake = storedItem.isEmpty() ? this.getStackInSlot(1).copy() : storedItem.copy();
fake.setCount(1);
this.setInventorySlotContents(2, fake);
}
}
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
getPos().getY(), getPos().getZ());
getPos().getY(), getPos().getZ());
readFromNBT(packet.getNbtCompound());
}
@ -259,7 +240,8 @@ public class TileTechStorageBase extends TileLegacyMachineBase
@Override
public boolean hasCapability(final net.minecraftforge.common.capabilities.Capability<?> capability,
@javax.annotation.Nullable final net.minecraft.util.EnumFacing facing) {
@javax.annotation.Nullable
final net.minecraft.util.EnumFacing facing) {
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
}

View file

@ -1,20 +1,26 @@
package techreborn.tiles.fusionReactor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.api.reactor.FusionReactorRecipe;
import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
public class TileEntityFusionController extends TilePowerAcceptor implements IInventoryProvider {
public class TileEntityFusionController extends TilePowerAcceptor implements IInventoryProvider, IContainerProvider {
public Inventory inventory = new Inventory(3, "TileEntityFusionController", 64, this);
@ -39,18 +45,18 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
public boolean canAcceptEnergy(final EnumFacing direction) {
return !(direction == EnumFacing.DOWN || direction == EnumFacing.UP);
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
public boolean canProvideEnergy(final EnumFacing direction) {
return direction == EnumFacing.DOWN || direction == EnumFacing.UP;
}
@Override
public double getMaxOutput() {
if (!hasStartedCrafting) {
if (!this.hasStartedCrafting) {
return 0;
}
return 1000000;
@ -58,7 +64,7 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
@Override
public double getMaxInput() {
if (hasStartedCrafting) {
if (this.hasStartedCrafting) {
return 0;
}
return 8192;
@ -70,68 +76,68 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
crafingTickTime = tagCompound.getInteger("crafingTickTime");
finalTickTime = tagCompound.getInteger("finalTickTime");
neededPower = tagCompound.getInteger("neededPower");
hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
this.crafingTickTime = tagCompound.getInteger("crafingTickTime");
this.finalTickTime = tagCompound.getInteger("finalTickTime");
this.neededPower = tagCompound.getInteger("neededPower");
this.hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
if (crafingTickTime == -1) {
crafingTickTime = 0;
if (this.crafingTickTime == -1) {
this.crafingTickTime = 0;
}
if (finalTickTime == -1) {
finalTickTime = 0;
if (this.finalTickTime == -1) {
this.finalTickTime = 0;
}
if (neededPower == -1) {
neededPower = 0;
if (this.neededPower == -1) {
this.neededPower = 0;
}
tagCompound.setInteger("crafingTickTime", crafingTickTime);
tagCompound.setInteger("finalTickTime", finalTickTime);
tagCompound.setInteger("neededPower", neededPower);
tagCompound.setBoolean("hasStartedCrafting", hasStartedCrafting);
tagCompound.setInteger("crafingTickTime", this.crafingTickTime);
tagCompound.setInteger("finalTickTime", this.finalTickTime);
tagCompound.setInteger("neededPower", this.neededPower);
tagCompound.setBoolean("hasStartedCrafting", this.hasStartedCrafting);
return tagCompound;
}
public boolean checkCoils() {
if ((isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() + 1))
&& (isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ()))
&& (isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() - 1))
&& (isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ() + 1))
&& (isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ()))
&& (isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ() - 1))
&& (isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() + 2))
&& (isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() + 1))
&& (isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() - 1))
&& (isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() - 2))
&& (isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() + 2))
&& (isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() + 1))
&& (isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() - 1))
&& (isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() - 2))
&& (isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() + 3))
&& (isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() + 2))
&& (isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() - 2))
&& (isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() - 3))
&& (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() + 3))
&& (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() + 2))
&& (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 2))
&& (isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 3))
&& (isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() + 3))
&& (isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() - 3))) {
coilStatus = 1;
if (this.isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() + 1)
&& this.isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ())
&& this.isCoil(this.getPos().getX() + 3, this.getPos().getY(), this.getPos().getZ() - 1)
&& this.isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ() + 1)
&& this.isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ())
&& this.isCoil(this.getPos().getX() - 3, this.getPos().getY(), this.getPos().getZ() - 1)
&& this.isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() + 2)
&& this.isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() + 1)
&& this.isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() - 1)
&& this.isCoil(this.getPos().getX() + 2, this.getPos().getY(), this.getPos().getZ() - 2)
&& this.isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() + 2)
&& this.isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() + 1)
&& this.isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() - 1)
&& this.isCoil(this.getPos().getX() - 2, this.getPos().getY(), this.getPos().getZ() - 2)
&& this.isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() + 3)
&& this.isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() + 2)
&& this.isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() - 2)
&& this.isCoil(this.getPos().getX() + 1, this.getPos().getY(), this.getPos().getZ() - 3)
&& this.isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() + 3)
&& this.isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() + 2)
&& this.isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 2)
&& this.isCoil(this.getPos().getX() - 1, this.getPos().getY(), this.getPos().getZ() - 3)
&& this.isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() + 3)
&& this.isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() - 3)) {
this.coilStatus = 1;
return true;
}
coilStatus = 0;
this.coilStatus = 0;
return false;
}
private boolean isCoil(int x, int y, int z) {
return world.getBlockState(new BlockPos(x, y, z)).getBlock() == ModBlocks.FUSION_COIL;
private boolean isCoil(final int x, final int y, final int z) {
return this.world.getBlockState(new BlockPos(x, y, z)).getBlock() == ModBlocks.FUSION_COIL;
}
@Override
@ -139,104 +145,104 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
super.updateEntity();
// TODO improve this code a lot
if (world.getTotalWorldTime() % 20 == 0) {
checkCoils();
if (this.world.getTotalWorldTime() % 20 == 0) {
this.checkCoils();
}
if (!world.isRemote) {
if (coilStatus == 1) {
if (currentRecipe == null) {
if (inventory.hasChanged || crafingTickTime != 0) {
for (FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (ItemUtils.isItemEqual(getStackInSlot(topStackSlot), reactorRecipe.getTopInput(), true,
true, true)) {
if (!this.world.isRemote) {
if (this.coilStatus == 1) {
if (this.currentRecipe == null) {
if (this.inventory.hasChanged || this.crafingTickTime != 0) {
for (final FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if (ItemUtils.isItemEqual(this.getStackInSlot(this.topStackSlot), reactorRecipe.getTopInput(), true,
true, true)) {
if (reactorRecipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot),
reactorRecipe.getBottomInput(), true, true, true)) {
if (!ItemUtils.isItemEqual(this.getStackInSlot(this.bottomStackSlot),
reactorRecipe.getBottomInput(), true, true, true)) {
break;
}
}
if (canFitStack(reactorRecipe.getOutput(), outputStackSlot, true)) {
currentRecipe = reactorRecipe;
if (crafingTickTime != 0) {
finalTickTime = currentRecipe.getTickTime();
neededPower = (int) currentRecipe.getStartEU();
if (this.canFitStack(reactorRecipe.getOutput(), this.outputStackSlot, true)) {
this.currentRecipe = reactorRecipe;
if (this.crafingTickTime != 0) {
this.finalTickTime = this.currentRecipe.getTickTime();
this.neededPower = (int) this.currentRecipe.getStartEU();
}
hasStartedCrafting = false;
crafingTickTime = 0;
finalTickTime = currentRecipe.getTickTime();
neededPower = (int) currentRecipe.getStartEU();
this.hasStartedCrafting = false;
this.crafingTickTime = 0;
this.finalTickTime = this.currentRecipe.getTickTime();
this.neededPower = (int) this.currentRecipe.getStartEU();
break;
}
}
}
}
} else {
if (inventory.hasChanged) {
if (!validateRecipe()) {
resetCrafter();
if (this.inventory.hasChanged) {
if (!this.validateRecipe()) {
this.resetCrafter();
return;
}
}
if (!hasStartedCrafting) {
if (canUseEnergy(currentRecipe.getStartEU() + 64)) {
useEnergy(currentRecipe.getStartEU());
hasStartedCrafting = true;
if (!this.hasStartedCrafting) {
if (this.canUseEnergy(this.currentRecipe.getStartEU() + 64)) {
this.useEnergy(this.currentRecipe.getStartEU());
this.hasStartedCrafting = true;
}
} else {
if (crafingTickTime < currentRecipe.getTickTime()) {
if (currentRecipe.getEuTick() > 0) { // Power gen
addEnergy(currentRecipe.getEuTick()); // Waste
if (this.crafingTickTime < this.currentRecipe.getTickTime()) {
if (this.currentRecipe.getEuTick() > 0) { // Power gen
this.addEnergy(this.currentRecipe.getEuTick()); // Waste
// power
// if it
// has
// no
// where
// to go
crafingTickTime++;
this.crafingTickTime++;
} else { // Power user
if (canUseEnergy(currentRecipe.getEuTick() * -1)) {
setEnergy(getEnergy() - (currentRecipe.getEuTick() * -1));
crafingTickTime++;
if (this.canUseEnergy(this.currentRecipe.getEuTick() * -1)) {
this.setEnergy(this.getEnergy() - this.currentRecipe.getEuTick() * -1);
this.crafingTickTime++;
}
}
} else {
if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true)) {
if (getStackInSlot(outputStackSlot) == ItemStack.EMPTY) {
setInventorySlotContents(outputStackSlot, currentRecipe.getOutput().copy());
if (this.canFitStack(this.currentRecipe.getOutput(), this.outputStackSlot, true)) {
if (this.getStackInSlot(this.outputStackSlot) == ItemStack.EMPTY) {
this.setInventorySlotContents(this.outputStackSlot, this.currentRecipe.getOutput().copy());
} else {
decrStackSize(outputStackSlot, -currentRecipe.getOutput().getCount());
this.decrStackSize(this.outputStackSlot, -this.currentRecipe.getOutput().getCount());
}
decrStackSize(topStackSlot, currentRecipe.getTopInput().getCount());
if (currentRecipe.getBottomInput() != ItemStack.EMPTY) {
decrStackSize(bottomStackSlot, currentRecipe.getBottomInput().getCount());
this.decrStackSize(this.topStackSlot, this.currentRecipe.getTopInput().getCount());
if (this.currentRecipe.getBottomInput() != ItemStack.EMPTY) {
this.decrStackSize(this.bottomStackSlot, this.currentRecipe.getBottomInput().getCount());
}
resetCrafter();
this.resetCrafter();
}
}
}
}
} else {
if (currentRecipe != null) {
resetCrafter();
if (this.currentRecipe != null) {
this.resetCrafter();
}
}
}
if (inventory.hasChanged) {
inventory.hasChanged = false;
if (this.inventory.hasChanged) {
this.inventory.hasChanged = false;
}
}
private boolean validateRecipe() {
if (ItemUtils.isItemEqual(getStackInSlot(topStackSlot), currentRecipe.getTopInput(), true, true, true)) {
if (currentRecipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), currentRecipe.getBottomInput(), true, true,
true)) {
if (ItemUtils.isItemEqual(this.getStackInSlot(this.topStackSlot), this.currentRecipe.getTopInput(), true, true, true)) {
if (this.currentRecipe.getBottomInput() != null) {
if (!ItemUtils.isItemEqual(this.getStackInSlot(this.bottomStackSlot), this.currentRecipe.getBottomInput(), true, true,
true)) {
return false;
}
}
if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true)) {
if (this.canFitStack(this.currentRecipe.getOutput(), this.outputStackSlot, true)) {
return true;
}
}
@ -244,22 +250,22 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
}
private void resetCrafter() {
currentRecipe = null;
crafingTickTime = -1;
finalTickTime = -1;
neededPower = -1;
hasStartedCrafting = false;
this.currentRecipe = null;
this.crafingTickTime = -1;
this.finalTickTime = -1;
this.neededPower = -1;
this.hasStartedCrafting = false;
}
public boolean canFitStack(ItemStack stack, int slot, boolean oreDic) {// Checks to see if it can fit the stack
public boolean canFitStack(final ItemStack stack, final int slot, final boolean oreDic) {// Checks to see if it can fit the stack
if (stack == ItemStack.EMPTY) {
return true;
}
if (inventory.getStackInSlot(slot) == ItemStack.EMPTY) {
if (this.inventory.getStackInSlot(slot) == ItemStack.EMPTY) {
return true;
}
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, oreDic)) {
if (stack.getCount() + inventory.getStackInSlot(slot).getCount() <= stack.getMaxStackSize()) {
if (ItemUtils.isItemEqual(this.inventory.getStackInSlot(slot), stack, true, true, oreDic)) {
if (stack.getCount() + this.inventory.getStackInSlot(slot).getCount() <= stack.getMaxStackSize()) {
return true;
}
}
@ -283,6 +289,53 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
public int getCoilStatus() {
return this.coilStatus;
}
public void setCoilStatus(final int coilStatus) {
this.coilStatus = coilStatus;
}
public int getCrafingTickTime() {
return this.crafingTickTime;
}
public void setCrafingTickTime(final int crafingTickTime) {
this.crafingTickTime = crafingTickTime;
}
public int getFinalTickTime() {
return this.finalTickTime;
}
public void setFinalTickTime(final int finalTickTime) {
this.finalTickTime = finalTickTime;
}
public int getNeededPower() {
return this.neededPower;
}
public void setNeededPower(final int neededPower) {
this.neededPower = neededPower;
}
public int getProgressScaled() {
return Math.max(0, Math.min(24, (this.getCrafingTickTime() > 0 ? 1 : 0)
+ this.getCrafingTickTime() * 24 / (this.finalTickTime < 1 ? 1 : this.finalTickTime)));
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("fusionreactor").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 88, 17).slot(1, 88, 53).outputSlot(2, 148, 35).syncEnergyValue()
.syncIntegerValue(this::getCoilStatus, this::setCoilStatus)
.syncIntegerValue(this::getCrafingTickTime, this::setCrafingTickTime)
.syncIntegerValue(this::getFinalTickTime, this::setFinalTickTime)
.syncIntegerValue(this::getNeededPower, this::setNeededPower).addInventory().create();
}
}

View file

@ -2,12 +2,17 @@ package techreborn.tiles.generator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import reborncore.api.power.EnumPowerTier;
import techreborn.api.generator.EFluidGenerator;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
public class TileDieselGenerator extends TileBaseFluidGenerator {
public class TileDieselGenerator extends TileBaseFluidGenerator implements IContainerProvider {
public TileDieselGenerator() {
super(EFluidGenerator.DIESEL, ConfigTechReborn.ThermalGeneratorTier, "TileDieselGenerator", 1000 * 10,
@ -15,7 +20,7 @@ public class TileDieselGenerator extends TileBaseFluidGenerator {
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.DIESEL_GENERATOR, 1);
}
@ -33,4 +38,11 @@ public class TileDieselGenerator extends TileBaseFluidGenerator {
public EnumPowerTier getTier() {
return EnumPowerTier.LOW;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("dieselgenerator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 80, 17).outputSlot(1, 80, 53).fakeSlot(2, 59, 42).syncEnergyValue()
.addInventory().create();
}
}

View file

@ -2,19 +2,24 @@ package techreborn.tiles.generator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import reborncore.api.power.EnumPowerTier;
import techreborn.api.generator.EFluidGenerator;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
public class TileGasTurbine extends TileBaseFluidGenerator {
public class TileGasTurbine extends TileBaseFluidGenerator implements IContainerProvider {
public TileGasTurbine() {
super(EFluidGenerator.GAS, ConfigTechReborn.ThermalGeneratorTier, "TileGasTurbine", 1000 * 10, 16);
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.GAS_TURBINE, 1);
}
@ -27,4 +32,11 @@ public class TileGasTurbine extends TileBaseFluidGenerator {
public double getMaxPower() {
return ConfigTechReborn.ThermalGeneratorCharge;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("gasturbine").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 80, 17).outputSlot(1, 80, 53).fakeSlot(2, 59, 42).syncEnergyValue()
.addInventory().create();
}
}

View file

@ -13,9 +13,12 @@ import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
public class TileGenerator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
public class TileGenerator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, IContainerProvider {
public static int outputAmount = 10;
public Inventory inventory = new Inventory(2, "TileGenerator", 64, this);
public int fuelSlot = 0;
@ -31,69 +34,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();
}
@ -104,16 +107,16 @@ public class TileGenerator extends TilePowerAcceptor implements IWrenchable, IIn
@Override
public double getMaxPower() {
return 100;
return 10000;
}
@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 +136,40 @@ 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);
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("generator").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).fuelSlot(0, 80, 54).energySlot(1, 8, 72).syncEnergyValue()
.syncIntegerValue(this::getBurnTime, this::setBurnTime)
.syncIntegerValue(this::getTotalBurnTime, this::setTotalBurnTime).addInventory().create();
}
}

View file

@ -2,19 +2,24 @@ package techreborn.tiles.generator;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import reborncore.api.power.EnumPowerTier;
import techreborn.api.generator.EFluidGenerator;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
public class TileSemifluidGenerator extends TileBaseFluidGenerator {
public class TileSemifluidGenerator extends TileBaseFluidGenerator implements IContainerProvider {
public TileSemifluidGenerator() {
super(EFluidGenerator.SEMIFLUID, ConfigTechReborn.ThermalGeneratorTier, "TileSemifluidGenerator", 1000 * 10, 8);
}
@Override
public ItemStack getWrenchDrop(EntityPlayer arg0) {
public ItemStack getWrenchDrop(final EntityPlayer arg0) {
return new ItemStack(ModBlocks.SEMIFLUID_GENERATOR, 1);
}
@ -27,4 +32,11 @@ public class TileSemifluidGenerator extends TileBaseFluidGenerator {
public double getMaxPower() {
return ConfigTechReborn.ThermalGeneratorCharge;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("semifluidgenerator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 80, 17).outputSlot(1, 80, 53).fakeSlot(2, 59, 42).syncEnergyValue()
.addInventory().create();
}
}

View file

@ -5,13 +5,18 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import reborncore.api.power.EnumPowerTier;
import reborncore.common.util.FluidUtils;
import techreborn.api.generator.EFluidGenerator;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
public class TileThermalGenerator extends TileBaseFluidGenerator {
public class TileThermalGenerator extends TileBaseFluidGenerator implements IContainerProvider {
public TileThermalGenerator() {
super(EFluidGenerator.THERMAL, ConfigTechReborn.ThermalGeneratorTier, "TileThermalGenerator", 1000 * 10,
@ -19,7 +24,7 @@ public class TileThermalGenerator extends TileBaseFluidGenerator {
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.THERMAL_GENERATOR, 1);
}
@ -28,7 +33,7 @@ public class TileThermalGenerator extends TileBaseFluidGenerator {
super.updateEntity();
if (!this.world.isRemote) {
if (acceptFluid() && FluidUtils.drainContainers(this.tank, this.inventory, 0, 1))
if (this.acceptFluid() && FluidUtils.drainContainers(this.tank, this.inventory, 0, 1))
this.syncWithAll();
for (final EnumFacing direction : EnumFacing.values()) {
if (this.world
@ -57,4 +62,11 @@ public class TileThermalGenerator extends TileBaseFluidGenerator {
public EnumPowerTier getTier() {
return EnumPowerTier.LOW;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("thermalgenerator").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 80, 17).outputSlot(1, 80, 53).fakeSlot(2, 59, 42).syncEnergyValue()
.addInventory().create();
}
}

View file

@ -1,7 +1,6 @@
package techreborn.tiles.multiblock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
@ -9,6 +8,7 @@ import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
@ -18,16 +18,21 @@ import reborncore.common.multiblock.IMultiblockPart;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.api.recipe.ITileRecipeHandler;
import techreborn.api.recipe.machines.BlastFurnaceRecipe;
import techreborn.blocks.BlockMachineCasing;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.multiblocks.MultiBlockCasing;
import techreborn.tiles.TileMachineCasing;
public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory, ITileRecipeHandler<BlastFurnaceRecipe>, IRecipeCrafterProvider {
public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable, IInventoryProvider,
ITileRecipeHandler<BlastFurnaceRecipe>, IRecipeCrafterProvider, IContainerProvider {
public static int euTick = 5;
public int tickTime;
@ -35,36 +40,38 @@ public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable,
public RecipeCrafter crafter;
public int capacity = 1000;
private int cachedHeat;
public TileBlastFurnace() {
super(ConfigTechReborn.CentrifugeTier);
// TODO configs
int[] inputs = new int[2];
final int[] inputs = new int[2];
inputs[0] = 0;
inputs[1] = 1;
int[] outputs = new int[2];
final int[] outputs = new int[2];
outputs[0] = 2;
outputs[1] = 3;
crafter = new RecipeCrafter(Reference.blastFurnaceRecipe, this, 2, 2, inventory, inputs, outputs);
this.crafter = new RecipeCrafter(Reference.blastFurnaceRecipe, this, 2, 2, this.inventory, inputs, outputs);
}
@Override
public void updateEntity() {
super.updateEntity();
crafter.updateEntity();
this.crafter.updateEntity();
}
@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();
}
@ -74,39 +81,39 @@ public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable,
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.INDUSTRIAL_BLAST_FURNACE, 1);
}
public int getHeat() {
for (EnumFacing direction : EnumFacing.values()) {
TileEntity tileEntity = world.getTileEntity(new BlockPos(getPos().getX() + direction.getFrontOffsetX(),
getPos().getY() + direction.getFrontOffsetY(), getPos().getZ() + direction.getFrontOffsetZ()));
for (final EnumFacing direction : EnumFacing.values()) {
final TileEntity tileEntity = this.world.getTileEntity(new BlockPos(this.getPos().getX() + direction.getFrontOffsetX(),
this.getPos().getY() + direction.getFrontOffsetY(), this.getPos().getZ() + direction.getFrontOffsetZ()));
if (tileEntity instanceof TileMachineCasing) {
if (((TileMachineCasing) tileEntity).isConnected()
&& ((TileMachineCasing) tileEntity).getMultiblockController().isAssembled()) {
MultiBlockCasing casing = ((TileMachineCasing) tileEntity).getMultiblockController();
Location location = new Location(getPos().getX(), getPos().getY(), getPos().getZ(), direction);
&& ((TileMachineCasing) tileEntity).getMultiblockController().isAssembled()) {
final MultiBlockCasing casing = ((TileMachineCasing) tileEntity).getMultiblockController();
final Location location = new Location(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), direction);
location.modifyPositionFromSide(direction, 1);
int heat = 0;
if (world.getBlockState(new BlockPos(location.getX(), location.getY() - 1, location.getZ()))
.getBlock() == tileEntity.getBlockType()) {
if (this.world.getBlockState(new BlockPos(location.getX(), location.getY() - 1, location.getZ()))
.getBlock() == tileEntity.getBlockType()) {
return 0;
}
for (IMultiblockPart part : casing.connectedParts) {
BlockMachineCasing casing1 = (BlockMachineCasing) world.getBlockState(part.getPos())
.getBlock();
for (final IMultiblockPart part : casing.connectedParts) {
final BlockMachineCasing casing1 = (BlockMachineCasing) this.world.getBlockState(part.getPos())
.getBlock();
heat += casing1
.getHeatFromState(part.getWorld().getBlockState(part.getWorldLocation().toBlockPos()));
.getHeatFromState(part.getWorld().getBlockState(part.getWorldLocation().toBlockPos()));
// TODO meta fix
}
if (world.getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))
.getBlock().getUnlocalizedName().equals("tile.lava")
&& world
.getBlockState(new BlockPos(location.getX(), location.getY() + 1, location.getZ()))
.getBlock().getUnlocalizedName().equals("tile.lava")) {
if (this.world.getBlockState(new BlockPos(location.getX(), location.getY(), location.getZ()))
.getBlock().getUnlocalizedName().equals("tile.lava")
&& this.world
.getBlockState(new BlockPos(location.getX(), location.getY() + 1, location.getZ()))
.getBlock().getUnlocalizedName().equals("tile.lava")) {
heat += 500;
}
return heat;
@ -117,50 +124,50 @@ public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable,
}
@Override
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
getPos().getY(), getPos().getZ());
readFromNBT(packet.getNbtCompound());
public void onDataPacket(final NetworkManager net, final SPacketUpdateTileEntity packet) {
this.world.markBlockRangeForRenderUpdate(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), this.getPos().getX(),
this.getPos().getY(), this.getPos().getZ());
this.readFromNBT(packet.getNbtCompound());
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
tickTime = tagCompound.getInteger("tickTime");
this.tickTime = tagCompound.getInteger("tickTime");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
writeUpdateToNBT(tagCompound);
this.writeUpdateToNBT(tagCompound);
return tagCompound;
}
public void writeUpdateToNBT(NBTTagCompound tagCompound) {
tagCompound.setInteger("tickTime", tickTime);
public void writeUpdateToNBT(final NBTTagCompound tagCompound) {
tagCompound.setInteger("tickTime", this.tickTime);
}
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3 } : new int[] { 0, 1, 2, 3 };
}
@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 == 2 || slotIndex == 3;
}
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;
}
@ -171,12 +178,12 @@ public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable,
}
@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;
}
@ -196,26 +203,42 @@ public class TileBlastFurnace extends TilePowerAcceptor implements IWrenchable,
}
@Override
public boolean canCraft(TileEntity tile, BlastFurnaceRecipe recipe) {
public boolean canCraft(final TileEntity tile, final BlastFurnaceRecipe recipe) {
if (tile instanceof TileBlastFurnace) {
TileBlastFurnace blastFurnace = (TileBlastFurnace) tile;
final TileBlastFurnace blastFurnace = (TileBlastFurnace) tile;
return blastFurnace.getHeat() >= recipe.neededHeat;
}
return false;
}
@Override
public boolean onCraft(TileEntity tile, BlastFurnaceRecipe recipe) {
public boolean onCraft(final TileEntity tile, final BlastFurnaceRecipe recipe) {
return true;
}
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
public void setHeat(final int heat) {
this.cachedHeat = heat;
}
public int getCachedHeat() {
return this.cachedHeat;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("blastfurnace").player(player.inventory).inventory().hotbar()
.addInventory().tile(this).slot(0, 50, 27).slot(1, 50, 47).outputSlot(2, 92, 36).outputSlot(3, 110, 36)
.syncEnergyValue().syncCrafterValue().syncIntegerValue(this::getHeat, this::setHeat).addInventory()
.create();
}
}

View file

@ -1,11 +1,11 @@
package techreborn.tiles.multiblock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
@ -13,13 +13,15 @@ import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import static techreborn.tiles.multiblock.MultiblockChecker.CASING_REINFORCED;
import static techreborn.tiles.multiblock.MultiblockChecker.ZERO_OFFSET;
public class TileImplosionCompressor extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory, IRecipeCrafterProvider {
public class TileImplosionCompressor extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public Inventory inventory = new Inventory(4, "TileImplosionCompressor", 64, this);
public MultiblockChecker multiblockChecker;
@ -27,29 +29,29 @@ public class TileImplosionCompressor extends TilePowerAcceptor implements IWrenc
public TileImplosionCompressor() {
super(2);
int[] inputs = new int[] { 0, 1 };
int[] outputs = new int[] { 2, 3 };
crafter = new RecipeCrafter(Reference.implosionCompressorRecipe, this, 2, 2, inventory, inputs, outputs);
final int[] inputs = new int[] { 0, 1 };
final int[] outputs = new int[] { 2, 3 };
this.crafter = new RecipeCrafter(Reference.implosionCompressorRecipe, this, 2, 2, this.inventory, inputs, outputs);
}
@Override
public void validate() {
super.validate();
multiblockChecker = new MultiblockChecker(world, getPos().down(3));
this.multiblockChecker = new MultiblockChecker(this.world, this.getPos().down(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();
}
@ -59,56 +61,56 @@ public class TileImplosionCompressor extends TilePowerAcceptor implements IWrenc
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.IMPLOSION_COMPRESSOR, 1);
}
public boolean getMutliBlock() {
boolean down = multiblockChecker.checkRectY(1, 1, CASING_REINFORCED, ZERO_OFFSET);
boolean up = multiblockChecker.checkRectY(1, 1, CASING_REINFORCED, new BlockPos(0, 2, 0));
boolean chamber = multiblockChecker.checkRingYHollow(1, 1, CASING_REINFORCED, new BlockPos(0, 1, 0));
final boolean down = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_REINFORCED, MultiblockChecker.ZERO_OFFSET);
final boolean up = this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_REINFORCED, new BlockPos(0, 2, 0));
final boolean chamber = this.multiblockChecker.checkRingYHollow(1, 1, MultiblockChecker.CASING_REINFORCED, new BlockPos(0, 1, 0));
return down && chamber && up;
}
@Override
public void update() {
super.update();
if (getMutliBlock()) {
crafter.updateEntity();
if (this.getMutliBlock()) {
this.crafter.updateEntity();
}
}
@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;
}
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return new int[] { 0, 1, 2, 3 };
}
@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 || index == 1;
}
@Override
public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction) {
public boolean canExtractItem(final int index, final ItemStack stack, final EnumFacing direction) {
return index == 2 || index == 3;
}
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;
}
@ -119,12 +121,12 @@ public class TileImplosionCompressor extends TilePowerAcceptor implements IWrenc
}
@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;
}
@ -145,12 +147,19 @@ public class TileImplosionCompressor extends TilePowerAcceptor implements IWrenc
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("implosioncompressor").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 37, 26).slot(1, 37, 44).outputSlot(2, 93, 35).outputSlot(3, 111, 35)
.syncEnergyValue().syncCrafterValue().addInventory().create();
}
}

View file

@ -3,7 +3,6 @@ package techreborn.tiles.multiblock;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
@ -12,6 +11,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.recipe.IRecipeCrafterProvider;
import reborncore.api.tile.IInventoryProvider;
@ -21,22 +21,22 @@ import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.FluidUtils;
import reborncore.common.util.Inventory;
import reborncore.common.util.Tank;
import techreborn.api.Reference;
import techreborn.api.recipe.ITileRecipeHandler;
import techreborn.api.recipe.machines.IndustrialGrinderRecipe;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import static techreborn.tiles.multiblock.MultiblockChecker.CASING_NORMAL;
import static techreborn.tiles.multiblock.MultiblockChecker.CASING_REINFORCED;
import static techreborn.tiles.multiblock.MultiblockChecker.ZERO_OFFSET;
public class TileIndustrialGrinder extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, ISidedInventory, ITileRecipeHandler<IndustrialGrinderRecipe>, IRecipeCrafterProvider {
public class TileIndustrialGrinder extends TilePowerAcceptor implements IWrenchable, IInventoryProvider,
ITileRecipeHandler<IndustrialGrinderRecipe>, IRecipeCrafterProvider, IContainerProvider {
public static final int TANK_CAPACITY = 16000;
public Inventory inventory = new Inventory(6, "TileGrinder", 64, this);
public Tank tank = new Tank("TileGrinder", TANK_CAPACITY, this);
public Tank tank = new Tank("TileGrinder", TileIndustrialGrinder.TANK_CAPACITY, this);
public RecipeCrafter crafter;
public MultiblockChecker multiblockChecker;
@ -44,29 +44,30 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
super(ConfigTechReborn.CentrifugeTier);
// TODO configs
int[] inputs = new int[2];
final int[] inputs = new int[2];
inputs[0] = 0;
inputs[1] = 1;
int[] outputs = new int[4];
final int[] outputs = new int[4];
outputs[0] = 2;
outputs[1] = 3;
outputs[2] = 4;
outputs[3] = 5;
crafter = new RecipeCrafter(Reference.industrialGrinderRecipe, this, 1, 4, inventory, inputs, outputs);
this.crafter = new RecipeCrafter(Reference.industrialGrinderRecipe, this, 1, 4, this.inventory, inputs,
outputs);
}
@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();
}
@ -76,16 +77,19 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.INDUSTRIAL_GRINDER, 1);
}
public boolean getMutliBlock() {
boolean down = multiblockChecker.checkRectY(1, 1, CASING_NORMAL, ZERO_OFFSET);
boolean up = multiblockChecker.checkRectY(1, 1, CASING_NORMAL, new BlockPos(0, 2, 0));
boolean blade = multiblockChecker.checkRingY(1, 1, CASING_REINFORCED, new BlockPos(0, 1, 0));
IBlockState centerBlock = multiblockChecker.getBlock(0, 1, 0);
boolean center = centerBlock.getBlock() == Blocks.WATER;
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;
return down && center && blade && up;
}
@ -93,29 +97,29 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
public void update() {
super.update();
if (multiblockChecker == null) {
BlockPos pos = getPos().offset(getFacing().getOpposite(), 2).down();
multiblockChecker = new MultiblockChecker(world, pos);
if (this.multiblockChecker == null) {
final BlockPos pos = this.getPos().offset(this.getFacing().getOpposite(), 2).down();
this.multiblockChecker = new MultiblockChecker(this.world, pos);
}
if (getMutliBlock()) {
crafter.updateEntity();
if (this.getMutliBlock()) {
this.crafter.updateEntity();
}
FluidUtils.drainContainers(tank, inventory, 1, 5);
FluidUtils.drainContainers(this.tank, this.inventory, 1, 5);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
tank.readFromNBT(tagCompound);
crafter.readFromNBT(tagCompound);
this.tank.readFromNBT(tagCompound);
this.crafter.readFromNBT(tagCompound);
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tank.writeToNBT(tagCompound);
crafter.writeToNBT(tagCompound);
this.tank.writeToNBT(tagCompound);
this.crafter.writeToNBT(tagCompound);
return tagCompound;
}
@ -130,7 +134,7 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
public boolean hasCapability(final Capability<?> capability, final EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return true;
}
@ -138,34 +142,34 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
public <T> T getCapability(final Capability<T> capability, final EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return (T) tank;
return (T) this.tank;
}
return super.getCapability(capability, facing);
}
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3, 4, 5 } : new int[] { 0, 1, 2, 3, 4, 5 };
}
@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 == 2 || slotIndex == 3 || slotIndex == 4 || slotIndex == 5;
}
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;
}
@ -176,12 +180,12 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
}
@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;
}
@ -201,9 +205,9 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
}
@Override
public boolean canCraft(TileEntity tile, IndustrialGrinderRecipe recipe) {
FluidStack recipeFluid = recipe.fluidStack;
FluidStack tankFluid = tank.getFluid();
public boolean canCraft(final TileEntity tile, final IndustrialGrinderRecipe recipe) {
final FluidStack recipeFluid = recipe.fluidStack;
final FluidStack tankFluid = this.tank.getFluid();
if (recipe.fluidStack == null) {
return true;
}
@ -219,9 +223,9 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
}
@Override
public boolean onCraft(TileEntity tile, IndustrialGrinderRecipe recipe) {
FluidStack recipeFluid = recipe.fluidStack;
FluidStack tankFluid = tank.getFluid();
public boolean onCraft(final TileEntity tile, final IndustrialGrinderRecipe recipe) {
final FluidStack recipeFluid = recipe.fluidStack;
final FluidStack tankFluid = this.tank.getFluid();
if (recipe.fluidStack == null) {
return true;
}
@ -231,7 +235,7 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
if (tankFluid.isFluidEqual(recipeFluid)) {
if (tankFluid.amount >= recipeFluid.amount) {
if (tankFluid.amount == recipeFluid.amount)
tank.setFluid(null);
this.tank.setFluid(null);
else
tankFluid.amount -= recipeFluid.amount;
return true;
@ -242,12 +246,20 @@ public class TileIndustrialGrinder extends TilePowerAcceptor
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("industrialgrinder").player(player.inventory).inventory(8, 84).hotbar(8, 142)
.addInventory().tile(this).slot(0, 32, 26).slot(1, 32, 44).outputSlot(2, 77, 35).outputSlot(3, 95, 35)
.outputSlot(4, 113, 35).outputSlot(5, 131, 35).syncEnergyValue().syncCrafterValue().addInventory()
.create();
}
}

View file

@ -4,7 +4,6 @@ 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.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
@ -12,7 +11,7 @@ import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
import net.minecraftforge.oredict.OreDictionary;
import reborncore.api.IListInfoProvider;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
@ -20,16 +19,17 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.FluidUtils;
import reborncore.common.util.Inventory;
import reborncore.common.util.Tank;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.items.ItemDusts;
import java.util.Random;
import static techreborn.tiles.multiblock.MultiblockChecker.CASING_NORMAL;
import static techreborn.tiles.multiblock.MultiblockChecker.CASING_REINFORCED;
import static techreborn.tiles.multiblock.MultiblockChecker.ZERO_OFFSET;
public class TileIndustrialSawmill extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory, IListInfoProvider {
public class TileIndustrialSawmill extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IContainerProvider {
public Inventory inventory = new Inventory(5, "Sawmill", 64, this);
public Tank tank = new Tank("Sawmill", 16000, this);
@ -44,83 +44,84 @@ public class TileIndustrialSawmill extends TilePowerAcceptor implements IWrencha
@Override
public void update() {
super.update();
if (getMutliBlock()) {
ItemStack wood = inventory.getStackInSlot(0);
if (tickTime == 0) {
if (wood != null) {
for (int id : OreDictionary.getOreIDs(wood)) {
String name = OreDictionary.getOreName(id);
if (name.equals("logWood") &&
canAddOutput(2, 10) &&
canAddOutput(3, 5) &&
canAddOutput(4, 3) &&
canUseEnergy(128.0F) &&
!tank.isEmpty() &&
tank.getFluid().amount >= 1000) {
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) {
wood.shrink(1);
if (wood.getCount() == 0)
setInventorySlotContents(0, ItemStack.EMPTY);
tank.drain(1000, true);
useEnergy(128.0F);
tickTime = 1;
this.setInventorySlotContents(0, ItemStack.EMPTY);
this.tank.drain(1000, true);
this.useEnergy(128.0F);
this.syncWithAll();
this.tickTime = 1;
}
}
}
} else if (++tickTime > 100) {
Random rnd = world.rand;
addOutput(2, new ItemStack(Blocks.PLANKS, 6 + rnd.nextInt(4)));
} else if (++this.tickTime > 100) {
final Random rnd = this.world.rand;
this.addOutput(2, new ItemStack(Blocks.PLANKS, 6 + rnd.nextInt(4)));
if (rnd.nextInt(4) != 0) {
ItemStack pulp = ItemDusts.getDustByName("sawDust", 2 + rnd.nextInt(3));
addOutput(3, pulp);
final ItemStack pulp = ItemDusts.getDustByName("sawDust", 2 + rnd.nextInt(3));
this.addOutput(3, pulp);
}
if (rnd.nextInt(3) == 0) {
ItemStack paper = new ItemStack(Items.PAPER, 1 + rnd.nextInt(2));
addOutput(4, paper);
final ItemStack paper = new ItemStack(Items.PAPER, 1 + rnd.nextInt(2));
this.addOutput(4, paper);
}
tickTime = 0;
this.tickTime = 0;
}
}
FluidUtils.drainContainers(tank, inventory, 1, 4);
FluidUtils.drainContainers(this.tank, this.inventory, 1, 4);
}
public void addOutput(int slot, ItemStack stack) {
if (getStackInSlot(slot) == ItemStack.EMPTY)
setInventorySlotContents(slot, stack);
getStackInSlot(slot).grow(stack.getCount());
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());
}
public boolean canAddOutput(int slot, int amount) {
ItemStack stack = getStackInSlot(slot);
return stack == ItemStack.EMPTY || getInventoryStackLimit() - stack.getCount() >= amount;
public boolean canAddOutput(final int slot, final int amount) {
final ItemStack stack = this.getStackInSlot(slot);
return stack == ItemStack.EMPTY || this.getInventoryStackLimit() - stack.getCount() >= amount;
}
@Override
public void validate() {
super.validate();
multiblockChecker = new MultiblockChecker(world, getPos().down(3));
this.multiblockChecker = new MultiblockChecker(this.world, this.getPos().down(3));
}
public boolean getMutliBlock() {
boolean down = multiblockChecker.checkRectY(1, 1, CASING_NORMAL, ZERO_OFFSET);
boolean up = multiblockChecker.checkRectY(1, 1, CASING_NORMAL, new BlockPos(0, 2, 0));
boolean blade = multiblockChecker.checkRingY(1, 1, CASING_REINFORCED, new BlockPos(0, 1, 0));
IBlockState centerBlock = multiblockChecker.getBlock(0, 1, 0);
boolean center = centerBlock.getBlock() == Blocks.WATER;
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;
return down && center && blade && up;
}
@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();
}
@ -130,27 +131,27 @@ public class TileIndustrialSawmill extends TilePowerAcceptor implements IWrencha
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.INDUSTRIAL_SAWMILL, 1);
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(final NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound);
tank.readFromNBT(tagCompound);
tickTime = tagCompound.getInteger("tickTime");
this.tank.readFromNBT(tagCompound);
this.tickTime = tagCompound.getInteger("tickTime");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
super.writeToNBT(tagCompound);
tank.writeToNBT(tagCompound);
tagCompound.setInteger("tickTime", tickTime);
this.tank.writeToNBT(tagCompound);
tagCompound.setInteger("tickTime", this.tickTime);
return tagCompound;
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
public boolean hasCapability(final Capability<?> capability, final EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return true;
}
@ -158,31 +159,31 @@ public class TileIndustrialSawmill extends TilePowerAcceptor implements IWrencha
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
public <T> T getCapability(final Capability<T> capability, final EnumFacing facing) {
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
return (T) tank;
return (T) this.tank;
}
return super.getCapability(capability, facing);
}
@Override
public int[] getSlotsForFace(EnumFacing side) {
public int[] getSlotsForFace(final EnumFacing side) {
return new int[] { 0, 2, 3, 4, 5 };
}
@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 >= 2;
}
public int getProgressScaled(int scale) {
if (tickTime != 0) {
return tickTime * scale / 100;
public int getProgressScaled(final int scale) {
if (this.tickTime != 0) {
return this.tickTime * scale / 100;
}
return 0;
}
@ -193,12 +194,12 @@ public class TileIndustrialSawmill extends TilePowerAcceptor implements IWrencha
}
@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;
}
@ -219,7 +220,13 @@ public class TileIndustrialSawmill extends TilePowerAcceptor implements IWrencha
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@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();
}
}

View file

@ -1,10 +1,10 @@
package techreborn.tiles.multiblock;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
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.IInventoryProvider;
@ -12,13 +12,15 @@ import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import static techreborn.tiles.multiblock.MultiblockChecker.CASING_REINFORCED;
import static techreborn.tiles.multiblock.MultiblockChecker.ZERO_OFFSET;
public class TileVacuumFreezer extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, ISidedInventory {
public class TileVacuumFreezer extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public Inventory inventory = new Inventory(3, "TileVacuumFreezer", 64, this);
public MultiblockChecker multiblockChecker;
@ -26,26 +28,26 @@ public class TileVacuumFreezer extends TilePowerAcceptor implements IWrenchable,
public TileVacuumFreezer() {
super(2);
int[] inputs = new int[] { 0 };
int[] outputs = new int[] { 1 };
crafter = new RecipeCrafter(Reference.vacuumFreezerRecipe, this, 2, 1, inventory, inputs, outputs);
final int[] inputs = new int[] { 0 };
final int[] outputs = new int[] { 1 };
this.crafter = new RecipeCrafter(Reference.vacuumFreezerRecipe, this, 2, 1, this.inventory, inputs, outputs);
}
@Override
public void validate() {
super.validate();
multiblockChecker = new MultiblockChecker(world, getPos().down());
this.multiblockChecker = new MultiblockChecker(this.world, this.getPos().down());
}
@Override
public void update() {
super.update();
if (getMultiBlock())
crafter.updateEntity();
if (this.getMultiBlock())
this.crafter.updateEntity();
}
public boolean getMultiBlock() {
return multiblockChecker.checkRectY(1, 1, CASING_REINFORCED, ZERO_OFFSET);
return this.multiblockChecker.checkRectY(1, 1, MultiblockChecker.CASING_REINFORCED, MultiblockChecker.ZERO_OFFSET);
}
@Override
@ -54,12 +56,12 @@ public class TileVacuumFreezer extends TilePowerAcceptor implements IWrenchable,
}
@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;
}
@ -79,17 +81,17 @@ public class TileVacuumFreezer extends TilePowerAcceptor implements IWrenchable,
}
@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();
}
@ -99,53 +101,60 @@ public class TileVacuumFreezer extends TilePowerAcceptor implements IWrenchable,
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.ALLOY_SMELTER, 1);
}
@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 Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@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;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("vacuumfreezer").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).slot(0, 55, 45).outputSlot(1, 101, 45).syncEnergyValue().syncCrafterValue().addInventory()
.create();
}
}

View file

@ -1,22 +1,24 @@
package techreborn.tiles.storage;
import reborncore.api.IListInfoProvider;
import net.minecraft.entity.player.EntityPlayer;
import reborncore.api.power.EnumPowerTier;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import java.util.List;
/**
* Created by modmuss50 on 14/03/2016.
*/
public class TileBatBox extends TileEnergyStorage implements IListInfoProvider {
public class TileBatBox extends TileEnergyStorage implements IContainerProvider {
public TileBatBox() {
super("BatBox", 2, ModBlocks.BATTERY_BOX, EnumPowerTier.LOW, 32, 32, 40000);
}
@Override
public void addInfo(List<String> info, boolean isRealTile) {
info.add("Batbox");
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("batbox").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).energySlot(0, 62, 45).energySlot(1, 98, 45).syncEnergyValue().addInventory().create();
}
}

View file

@ -1,15 +1,26 @@
package techreborn.tiles.storage;
import net.minecraft.entity.player.EntityPlayer;
import reborncore.api.power.EnumPowerTier;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
/**
* Created by modmuss50 on 14/03/2016.
*/
public class TileMFE extends TileEnergyStorage {
public class TileMFE extends TileEnergyStorage implements IContainerProvider {
public TileMFE() {
super("MFE", 2, ModBlocks.MVSU, EnumPowerTier.MEDIUM, 512, 512, 600000);
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("mfe").player(player.inventory).inventory().hotbar().armor()
.complete(8, 18).addArmor().addInventory().tile(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create();
}
}

View file

@ -1,14 +1,25 @@
package techreborn.tiles.storage;
import net.minecraft.entity.player.EntityPlayer;
import reborncore.api.power.EnumPowerTier;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
/**
* Created by modmuss50 on 14/03/2016.
*/
public class TileMFSU extends TileEnergyStorage {
public class TileMFSU extends TileEnergyStorage implements IContainerProvider {
public TileMFSU() {
super("MFSU", 2, ModBlocks.HVSU, EnumPowerTier.HIGH, 2048, 2048, 1000000);
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("mfsu").player(player.inventory).inventory().hotbar().armor()
.complete(8, 18).addArmor().addInventory().tile(this).energySlot(0, 62, 45).energySlot(1, 98, 45)
.syncEnergyValue().addInventory().create();
}
}

View file

@ -1,7 +1,6 @@
package techreborn.tiles.teir1;
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;
@ -12,10 +11,13 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.recipes.RecipeCrafter;
import reborncore.common.util.Inventory;
import techreborn.api.Reference;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.utils.upgrade.UpgradeHandler;
public class TileCompressor extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, ISidedInventory {
public class TileCompressor extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileCompressor", 64, this);
@ -26,32 +28,34 @@ public class TileCompressor extends TilePowerAcceptor implements IWrenchable, II
public TileCompressor() {
super(1);
int[] inputs = new int[] { 0 };
int[] outputs = new int[] { 1 };
crafter = new RecipeCrafter(Reference.compressorRecipe, this, 2, 1, inventory, inputs, outputs);
upgradeHandler = new UpgradeHandler(crafter, inventory, 2, 3, 4, 5);
final int[] inputs = new int[] { 0 };
final int[] outputs = new int[] { 1 };
this.crafter = new RecipeCrafter(Reference.compressorRecipe, 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);
if (!this.world.isRemote) {
super.update();
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();
}
@ -61,7 +65,7 @@ public class TileCompressor extends TilePowerAcceptor implements IWrenchable, II
}
@Override
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
return new ItemStack(ModBlocks.COMPRESSOR, 1);
}
@ -71,39 +75,43 @@ public class TileCompressor extends TilePowerAcceptor implements IWrenchable, II
// ISidedInventory
@Override
public int[] getSlotsForFace(EnumFacing side) {
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2 } : new int[] { 0, 1, 2 };
public int[] getSlotsForFace(final EnumFacing side) {
if (side.equals(EnumFacing.UP))
return new int[] { 0 };
else if (side.equals(EnumFacing.DOWN))
return new int[] { 1 };
return new int[0];
}
@Override
public boolean canInsertItem(int Index, ItemStack itemStack, EnumFacing side) {
public boolean canInsertItem(final int Index, final ItemStack itemStack, final EnumFacing side) {
return Index == 0;
}
@Override
public boolean canExtractItem(int Index, ItemStack itemStack, EnumFacing side) {
public boolean canExtractItem(final int Index, final ItemStack itemStack, final EnumFacing side) {
return Index == 1;
}
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;
}
@ -124,11 +132,18 @@ public class TileCompressor extends TilePowerAcceptor implements IWrenchable, II
@Override
public Inventory getInventory() {
return inventory;
return this.inventory;
}
@Override
public RecipeCrafter getRecipeCrafter() {
return crafter;
return this.crafter;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("compressor").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).slot(0, 55, 45).outputSlot(1, 101, 45).syncEnergyValue().syncCrafterValue().addInventory()
.create();
}
}

View file

@ -2,19 +2,24 @@ package techreborn.tiles.teir1;
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.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.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory {
public class TileElectricFurnace extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileElectricFurnace", 64, this);
public int capacity = 1000;
@ -23,86 +28,85 @@ public class TileElectricFurnace extends TilePowerAcceptor implements IWrenchabl
public int cost = 8;
int input1 = 0;
int output = 1;
private static final int[] SLOTS_TOP = new int[] { 0 };
private static final int[] SLOTS_BOTTOM = new int[] { 1 };
private static final int[] SLOTS_SIDES = new int[] { 1 };
public TileElectricFurnace() {
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();
boolean updateInventory = false;
if (isBurning() && canSmelt()) {
updateState();
if (!this.world.isRemote) {
super.update();
progress++;
if (progress % 10 == 0) {
useEnergy(cost);
final boolean burning = this.isBurning();
boolean updateInventory = false;
if (this.isBurning() && this.canSmelt()) {
this.updateState();
this.progress++;
if (this.progress % 10 == 0) {
this.useEnergy(this.cost);
}
if (this.progress >= this.fuelScale) {
this.progress = 0;
this.cookItems();
updateInventory = true;
}
} else {
this.progress = 0;
this.updateState();
}
if (progress >= fuelScale) {
progress = 0;
cookItems();
if (burning != this.isBurning()) {
updateInventory = true;
}
} else {
progress = 0;
updateState();
}
if (burning != isBurning()) {
updateInventory = true;
}
if (updateInventory) {
markDirty();
if (updateInventory) {
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 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 +114,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 +143,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 +153,38 @@ 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) {
if (side.equals(EnumFacing.UP))
return new int[] { 0 };
else if (side.equals(EnumFacing.DOWN))
return new int[] { 1 };
return new int[0];
}
@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 +205,21 @@ 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;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("electricfurnace").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).slot(0, 55, 45).outputSlot(1, 101, 45).syncEnergyValue()
.syncIntegerValue(this::getBurnTime, this::setBurnTime).addInventory().create();
}
}

View file

@ -6,19 +6,20 @@ 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.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
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, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileExtractor", 64, this);
@ -29,34 +30,36 @@ 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);
if (!this.world.isRemote) {
super.update();
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 +69,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 +78,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,32 +129,38 @@ 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);
public int[] getSlotsForFace(final EnumFacing side) {
if (side.equals(EnumFacing.UP))
return new int[] { 0 };
else if (side.equals(EnumFacing.DOWN))
return new int[] { 1 };
return new int[0];
}
@Override
public int[] getSlotsForFace(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;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("extractor").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).slot(0, 55, 45).outputSlot(1, 101, 45).syncEnergyValue().syncCrafterValue().addInventory()
.create();
}
}

View file

@ -1,29 +1,29 @@
package techreborn.tiles.teir1;
import net.minecraft.entity.player.EntityPlayer;
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.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
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 {
public class TileGrinder extends TilePowerAcceptor
implements IWrenchable, IInventoryProvider, IRecipeCrafterProvider, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileGrinder", 64, this);
@ -34,34 +34,36 @@ 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();
//charge(3); TODO
charge(3);
public void update() {
if (!this.world.isRemote) {
super.update();
this.upgradeHandler.tick();
//charge(3); TODO
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 +73,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 +82,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 +133,43 @@ 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);
public int[] getSlotsForFace(final EnumFacing side) {
if (side.equals(EnumFacing.UP))
return new int[] { 0 };
else if (side.equals(EnumFacing.DOWN))
return new int[] { 1 };
return new int[0];
}
@Override
public int[] getSlotsForFace(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;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("grinder").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).slot(0, 55, 45).outputSlot(1, 101, 45).syncEnergyValue().syncCrafterValue().addInventory()
.create();
}
}

View file

@ -2,7 +2,6 @@ package techreborn.tiles.teir1;
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;
@ -11,126 +10,112 @@ import reborncore.common.IWrenchable;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.client.container.IContainerProvider;
import techreborn.client.container.builder.BuiltContainer;
import techreborn.client.container.builder.ContainerBuilder;
import techreborn.init.ModBlocks;
import techreborn.items.ItemParts;
public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, ISidedInventory {
public class TileRecycler extends TilePowerAcceptor implements IWrenchable, IInventoryProvider, IContainerProvider {
public Inventory inventory = new Inventory(6, "TileRecycler", 64, this);
public int capacity = 1000;
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;
private final Inventory inventory = new Inventory(6, "TileRecycler", 64, this);
private final int capacity = 1000;
private final int cost = 2;
private final int time = 15;
private final int chance = 6;
private boolean isBurning;
private int progress;
public TileRecycler() {
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();
boolean updateInventory = false;
if (getEnergy() <= cost && canRecycle()) {
if (getEnergy() > cost) {
updateInventory = true;
}
}
if (isBurning() && canRecycle()) {
updateState();
progress++;
if (progress >= time) {
progress = 0;
recycleItems();
boolean updateInventory = false;
if (this.canRecycle() && !this.isBurning() && this.getEnergy() != 0)
this.setBurning(true);
else if (this.isBurning()) {
if (this.useEnergy(this.cost) != this.cost)
this.setBurning(false);
this.progress++;
if (this.progress >= this.time) {
this.progress = 0;
this.recycleItems();
updateInventory = true;
this.setBurning(false);
}
} else {
progress = 0;
updateState();
}
if (burning != isBurning()) {
updateInventory = true;
}
this.updateState();
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 (randomchance == 1) {
setInventorySlotContents(output, itemstack.copy());
}
} else if (getStackInSlot(output).isItemEqual(itemstack)) {
useEnergy(cost);
if (randomchance == 1) {
getStackInSlot(output).setCount(itemstack.getCount());
}
}
if (getStackInSlot(input1).getCount() > 1) {
useEnergy(cost);
this.decrStackSize(input1, 1);
} else {
useEnergy(cost);
setInventorySlotContents(input1, ItemStack.EMPTY);
}
if (randomchance == 1) {
if (this.getStackInSlot(1).isEmpty())
this.setInventorySlotContents(1, itemstack.copy());
else
this.getStackInSlot(1).grow(itemstack.getCount());
}
this.decrStackSize(0, 1);
}
public boolean canRecycle() {
return getStackInSlot(input1) != null && hasSlotGotSpace(output);
return this.getStackInSlot(0) != ItemStack.EMPTY && this.hasSlotGotSpace(1);
}
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.isBurning;
}
public void setBurning(final boolean burning) {
this.isBurning = burning;
}
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.isBurning)
blockMachineBase.setActive(this.isBurning, 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 +125,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 +135,38 @@ 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) {
if (side.equals(EnumFacing.UP))
return new int[] { 0 };
else if (side.equals(EnumFacing.DOWN))
return new int[] { 1 };
return new int[0];
}
@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 == 1)
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 == 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;
}
@ -198,6 +187,21 @@ 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;
}
@Override
public BuiltContainer createContainer(final EntityPlayer player) {
return new ContainerBuilder("recycler").player(player.inventory).inventory().hotbar().addInventory()
.tile(this).slot(0, 55, 45).slot(1, 101, 45).syncEnergyValue()
.syncIntegerValue(this::getProgress, this::setProgress).addInventory().create();
}
}