Convert FusionReactor
This commit is contained in:
parent
bd16289c60
commit
b93fe6c5ad
7 changed files with 222 additions and 349 deletions
|
@ -5,11 +5,13 @@ 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.init.ModBlocks;
|
||||
|
@ -39,18 +41,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 +60,7 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
|
|||
|
||||
@Override
|
||||
public double getMaxInput() {
|
||||
if (hasStartedCrafting) {
|
||||
if (this.hasStartedCrafting) {
|
||||
return 0;
|
||||
}
|
||||
return 8192;
|
||||
|
@ -70,68 +72,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 +141,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 +246,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 +285,43 @@ 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)));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue