Convert RollingMachine

This commit is contained in:
Ourten 2017-01-08 14:00:19 +01:00
parent 8a0a133e02
commit ad890079ec
8 changed files with 140 additions and 185 deletions

View file

@ -6,12 +6,14 @@ 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.init.ModBlocks;
@ -37,12 +39,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 +66,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 +141,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 +178,30 @@ 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;
}
}