Revert "Fusion reactor fixes & rewrite, energy fixes."

This reverts commit 06fad2264f.
This commit is contained in:
modmuss50 2016-08-10 00:30:08 +01:00
parent 22fd152ec9
commit 8a0d981018
13 changed files with 386 additions and 279 deletions

View file

@ -1,20 +1,20 @@
package techreborn.tiles;
import net.minecraft.util.math.BlockPos;
import reborncore.api.power.tile.IEnergyProducerTile;
import reborncore.common.IWrenchable;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import reborncore.api.power.EnumPowerTier;
import reborncore.common.tile.TilePowerAcceptor;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.tile.TilePowerAcceptorProducer;
import reborncore.common.util.Inventory;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.power.EnergyUtils;
public class TileAesu extends TilePowerAcceptor implements IEnergyProducerTile, IWrenchable {
public class TileAesu extends TilePowerAcceptorProducer implements IWrenchable {
public static final int MAX_OUTPUT = ConfigTechReborn.AesuMaxOutput;
public static final int MAX_STORAGE = ConfigTechReborn.AesuMaxStorage;
@ -44,11 +44,19 @@ public class TileAesu extends TilePowerAcceptor implements IEnergyProducerTile,
if (!worldObj.isRemote && getEnergy() > 0) {
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
double disposed = emitEnergy(getFacingEnum(), maxOutput);
if (maxOutput != 0 && disposed != 0) useEnergy(disposed);
for(EnumFacing facing : EnumFacing.VALUES) {
double disposed = emitEnergy(facing, maxOutput);
if(disposed != 0) {
maxOutput -= disposed;
useEnergy(disposed);
if (maxOutput == 0) return;
}
}
}
}
//TODO move to RebornCore
public double emitEnergy(EnumFacing enumFacing, double amount) {
BlockPos pos = getPos().offset(enumFacing);
EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver(
@ -59,16 +67,6 @@ public class TileAesu extends TilePowerAcceptor implements IEnergyProducerTile,
return 0;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
return getFacingEnum() != direction;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
return getFacingEnum() == direction;
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {

View file

@ -5,12 +5,10 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.power.tile.IEnergyProducerTile;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.explosion.RebornExplosion;
import reborncore.common.tile.TilePowerAcceptor;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.tile.TilePowerAcceptorProducer;
import reborncore.common.util.Inventory;
import reborncore.common.util.ItemUtils;
import techreborn.api.reactor.FusionReactorRecipe;
@ -18,16 +16,21 @@ import techreborn.api.reactor.FusionReactorRecipeHelper;
import techreborn.init.ModBlocks;
import techreborn.power.EnergyUtils;
public class TileEntityFusionController extends TilePowerAcceptor implements IEnergyProducerTile, IInventoryProvider {
public class TileEntityFusionController extends TilePowerAcceptorProducer implements IInventoryProvider
{
public Inventory inventory = new Inventory(3, "TileEntityFusionController", 64, this);
public boolean hasCoils;
public int recipeTickTime = 0;
public FusionReactorRecipe recipe = null;
public boolean repeatSameRecipe = false;
// 0= no coils, 1 = coils
public int coilStatus = 0;
public int crafingTickTime = 0;
public int finalTickTime = 0;
public int neededPower = 0;
int topStackSlot = 0;
int bottomStackSlot = 1;
int outputStackSlot = 2;
FusionReactorRecipe currentRecipe = null;
boolean hasStartedCrafting = false;
@Override
public double getMaxPower() {
@ -36,54 +39,66 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IEn
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
return recipeTickTime == 0;
return hasStartedCrafting;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
return recipeTickTime != 0;
return !hasStartedCrafting;
}
@Override
public double getMaxOutput() {
if (!hasStartedCrafting)
{
return 0;
}
return 1000000;
}
@Override
public EnumPowerTier getTier() {
public EnumPowerTier getTier()
{
return EnumPowerTier.INSANE;
}
@Override
public void readFromNBT(NBTTagCompound tagCompound) {
public void readFromNBT(NBTTagCompound tagCompound)
{
super.readFromNBT(tagCompound);
if(tagCompound.hasKey("recipeTickTime") && checkCoils()) {
ItemStack topInput = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag("TopInput"));
ItemStack bottomInput = ItemStack.loadItemStackFromNBT(tagCompound.getCompoundTag("BottomInput"));
FusionReactorRecipe newRecipe = findNewNBTRecipe(topInput, bottomInput);
if(newRecipe != null) {
this.recipeTickTime = tagCompound.getInteger("recipeTickTime");
this.repeatSameRecipe = tagCompound.getBoolean("repeatSameRecipe");
this.recipe = newRecipe;
}
}
crafingTickTime = tagCompound.getInteger("crafingTickTime");
finalTickTime = tagCompound.getInteger("finalTickTime");
neededPower = tagCompound.getInteger("neededPower");
hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound)
{
super.writeToNBT(tagCompound);
if(recipe != null) {
tagCompound.setTag("TopInput", recipe.getTopInput().writeToNBT(new NBTTagCompound()));
tagCompound.setTag("BottomInput", recipe.getBottomInput().writeToNBT(new NBTTagCompound()));
tagCompound.setInteger("recipeTickTime", recipeTickTime);
tagCompound.setBoolean("repeatSameRecipe", repeatSameRecipe);
if (crafingTickTime == -1)
{
crafingTickTime = 0;
}
if (finalTickTime == -1)
{
finalTickTime = 0;
}
if (neededPower == -1)
{
neededPower = 0;
}
tagCompound.setInteger("crafingTickTime", crafingTickTime);
tagCompound.setInteger("finalTickTime", finalTickTime);
tagCompound.setInteger("neededPower", neededPower);
tagCompound.setBoolean("hasStartedCrafting", hasStartedCrafting);
return tagCompound;
}
public boolean checkCoils() {
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))
@ -107,140 +122,211 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IEn
&& (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))) {
hasCoils = true;
&& (isCoil(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ() - 3)))
{
coilStatus = 1;
return true;
}
hasCoils = false;
coilStatus = 0;
return false;
}
private boolean isCoil(int x, int y, int z) {
private boolean isCoil(int x, int y, int z)
{
return worldObj.getBlockState(new BlockPos(x, y, z)).getBlock() == ModBlocks.FusionCoil;
}
@Override
public void update() {
public void update()
{
super.update();
// TODO improve this code a lot
if (!worldObj.isRemote) {
if (worldObj.getTotalWorldTime() % 20 == 0) {
checkCoils();
}
if (worldObj.getTotalWorldTime() % 20 == 0)
{
checkCoils();
}
if (hasCoils) {
if (recipe == null || inventory.hasChanged) {
FusionReactorRecipe newRecipe = findNewRecipe();
if (newRecipe != null && newRecipe != recipe) {
this.recipe = newRecipe;
this.repeatSameRecipe = false;
this.recipeTickTime = 0;
if (!worldObj.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 (reactorRecipe.getBottomInput() != null)
{
if (!ItemUtils.isItemEqual(getStackInSlot(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();
}
hasStartedCrafting = false;
crafingTickTime = 0;
finalTickTime = currentRecipe.getTickTime();
neededPower = (int) currentRecipe.getStartEU();
break;
}
}
}
}
} else
{
if (inventory.hasChanged)
{
if (!validateRecipe())
{
resetCrafter();
return;
}
}
if (!hasStartedCrafting)
{
if (canUseEnergy(currentRecipe.getStartEU() + 64))
{
useEnergy(currentRecipe.getStartEU());
hasStartedCrafting = true;
}
} else
{
if (crafingTickTime < currentRecipe.getTickTime())
{
if (currentRecipe.getEuTick() > 0)
{ // Power gen
addEnergy(currentRecipe.getEuTick()); // Waste
// power
// if it
// has
// no
// where
// to go
crafingTickTime++;
} else
{ // Power user
if (canUseEnergy(currentRecipe.getEuTick() * -1))
{
setEnergy(getEnergy() - (currentRecipe.getEuTick() * -1));
crafingTickTime++;
}
}
} else
{
if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true))
{
if (getStackInSlot(outputStackSlot) == null)
{
setInventorySlotContents(outputStackSlot, currentRecipe.getOutput().copy());
} else
{
decrStackSize(outputStackSlot, -currentRecipe.getOutput().stackSize);
}
decrStackSize(topStackSlot, currentRecipe.getTopInput().stackSize);
if (currentRecipe.getBottomInput() != null)
{
decrStackSize(bottomStackSlot, currentRecipe.getBottomInput().stackSize);
}
resetCrafter();
}
}
}
}
if (recipe != null) {
if (recipeTickTime == 0) {
if (canUseEnergy(recipe.getStartEU())) {
useEnergy(recipe.getStartEU());
consumeInputStacks();
++recipeTickTime;
}
} else if (++recipeTickTime >= recipe.getTickTime()) {
addOutputStack(recipe.getOutput());
FusionReactorRecipe newRecipe = findNewRecipe();
if (newRecipe == recipe) {
consumeInputStacks();
this.repeatSameRecipe = true;
recipeTickTime = 1;
} else {
this.recipe = null;
this.repeatSameRecipe = false;
recipeTickTime = 0;
}
} else {
double euTick = recipe.getEuTick();
if (euTick > 0) addEnergy(euTick);
else if (useEnergy(-euTick) != euTick) {
this.recipeTickTime = 0;
this.repeatSameRecipe = false;
this.recipe = null;
}
}
} else
{
if (currentRecipe != null)
{
resetCrafter();
}
}
}
if (!worldObj.isRemote && getEnergy() > 0 && recipeTickTime != 0) {
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
double disposed = 0;
for(EnumFacing facing : EnumFacing.VALUES) {
if(canProvideEnergy(facing)) {
double emitted = emitEnergy(facing, maxOutput);
maxOutput -= emitted;
disposed += emitted;
}
}
if (disposed != 0)
if (inventory.hasChanged)
{
inventory.hasChanged = false;
}
if (!worldObj.isRemote && getEnergy() > 0 && hasStartedCrafting) {
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
for(EnumFacing facing : EnumFacing.VALUES) {
double disposed = emitEnergy(facing, maxOutput);
if(disposed != 0) {
maxOutput -= disposed;
useEnergy(disposed);
if (maxOutput == 0) return;
}
}
}
}
public FusionReactorRecipe findNewRecipe() {
for(FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if(canFitStack(reactorRecipe.getOutput(), 2) &&
canEmptyStack(reactorRecipe.getTopInput(), 0) &&
canEmptyStack(reactorRecipe.getBottomInput(), 1)) {
return reactorRecipe;
}
}
return null;
}
public FusionReactorRecipe findNewNBTRecipe(ItemStack top, ItemStack bottom) {
for(FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
if(canFitStack(reactorRecipe.getOutput(), 2) &&
ItemUtils.isItemEqual(top, reactorRecipe.getTopInput(), true, true) &&
ItemUtils.isItemEqual(bottom, reactorRecipe.getBottomInput(), true, true)) {
return reactorRecipe;
}
}
return null;
}
//TODO move to RebornCore
public double emitEnergy(EnumFacing enumFacing, double amount) {
BlockPos pos = getPos().offset(enumFacing);
EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver(
worldObj, enumFacing.getOpposite(), pos);
if (receiver != null) {
if(receiver != null) {
return receiver.receiveEnergy(amount, false);
}
return 0;
}
public void consumeInputStacks() {
if(--getStackInSlot(0).stackSize == 0) setInventorySlotContents(0, null);
if(--getStackInSlot(1).stackSize == 0) setInventorySlotContents(1, null);
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))
{
return false;
}
}
if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true))
{
return true;
}
}
return false;
}
public void addOutputStack(ItemStack output) {
ItemStack stack = getStackInSlot(2);
if(stack == null) setInventorySlotContents(2, output);
else stack.stackSize++;
private void resetCrafter()
{
currentRecipe = null;
crafingTickTime = -1;
finalTickTime = -1;
neededPower = -1;
hasStartedCrafting = false;
}
public boolean canEmptyStack(ItemStack stack, int slot) {
return inventory.getStackInSlot(slot) != null &&
ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, true);
}
public boolean canFitStack(ItemStack stack, int slot) {
if (stack == null || inventory.getStackInSlot(slot) == null) {
public boolean canFitStack(ItemStack stack, int slot, boolean oreDic)
{// Checks to see if it can fit the stack
if (stack == null)
{
return true;
}
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, true)) {
if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize()) {
if (inventory.getStackInSlot(slot) == null)
{
return true;
}
if (ItemUtils.isItemEqual(inventory.getStackInSlot(slot), stack, true, true, oreDic))
{
if (stack.stackSize + inventory.getStackInSlot(slot).stackSize <= stack.getMaxStackSize())
{
return true;
}
}
@ -248,23 +334,25 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IEn
}
@Override
public String getName() {
public String getName()
{
return "Fusion Reactor";
}
@Override
public boolean hasCustomName() {
public boolean hasCustomName()
{
return false;
}
@Override
public ITextComponent getDisplayName() {
return new TextComponentString(getName());
public ITextComponent getDisplayName()
{
return null;
}
@Override
public Inventory getInventory() {
return inventory;
}
}

View file

@ -101,11 +101,19 @@ public class TileIDSU extends TilePowerAcceptorProducer implements IWrenchable {
if (!worldObj.isRemote && getEnergy() > 0) {
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
double disposed = emitEnergy(getFacingEnum(), maxOutput);
if (maxOutput != 0 && disposed != 0) useEnergy(disposed);
for(EnumFacing facing : EnumFacing.VALUES) {
double disposed = emitEnergy(facing, maxOutput);
if(disposed != 0) {
maxOutput -= disposed;
useEnergy(disposed);
if (maxOutput == 0) return;
}
}
}
}
//TODO move to RebornCore
public double emitEnergy(EnumFacing enumFacing, double amount) {
BlockPos pos = getPos().offset(enumFacing);
EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver(
@ -116,16 +124,6 @@ public class TileIDSU extends TilePowerAcceptorProducer implements IWrenchable {
return 0;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
return getFacingEnum() != direction;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
return getFacingEnum() == direction;
}
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
return false;

View file

@ -72,11 +72,19 @@ public class TileLesu extends TilePowerAcceptorProducer {// TODO wrench
if (!worldObj.isRemote && getEnergy() > 0) {
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
double disposed = emitEnergy(getFacingEnum(), maxOutput);
if (maxOutput != 0 && disposed != 0) useEnergy(disposed);
for(EnumFacing facing : EnumFacing.VALUES) {
double disposed = emitEnergy(facing, maxOutput);
if(disposed != 0) {
maxOutput -= disposed;
useEnergy(disposed);
if (maxOutput == 0) return;
}
}
}
}
//TODO move to RebornCore
public double emitEnergy(EnumFacing enumFacing, double amount) {
BlockPos pos = getPos().offset(enumFacing);
EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver(
@ -87,16 +95,6 @@ public class TileLesu extends TilePowerAcceptorProducer {// TODO wrench
return 0;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
return getFacingEnum() != direction;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
return getFacingEnum() == direction;
}
public double getEuChange() {
if (euChange == -1) {

View file

@ -9,7 +9,7 @@ import techreborn.init.ModBlocks;
public class TileBatBox extends TileEnergyStorage {
public TileBatBox() {
super("BatBox", 2, ModBlocks.batBox, EnumPowerTier.LOW, 40000);
super("BatBox", 2, ModBlocks.batBox, EnumPowerTier.LOW, 32, 32, 40000);
}
}

View file

@ -9,11 +9,9 @@ import net.minecraft.util.math.BlockPos;
import reborncore.api.IListInfoProvider;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.power.IEnergyItemInfo;
import reborncore.api.power.tile.IEnergyProducerTile;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.PoweredItem;
import reborncore.common.tile.TilePowerAcceptor;
import reborncore.common.tile.TilePowerAcceptorProducer;
import reborncore.common.util.Inventory;
import techreborn.blocks.storage.BlockEnergyStorage;
@ -24,19 +22,23 @@ import java.util.List;
/**
* Created by Rushmead
*/
public class TileEnergyStorage extends TilePowerAcceptor implements IEnergyProducerTile, IWrenchable, ITickable, IInventoryProvider, IListInfoProvider {
public class TileEnergyStorage extends TilePowerAcceptorProducer implements IWrenchable, ITickable, IInventoryProvider, IListInfoProvider {
public Inventory inventory;
public String name;
public Block wrenchDrop;
public EnumPowerTier tier;
public int maxInput;
public int maxOutput;
public int maxStorage;
public TileEnergyStorage(String name, int invSize, Block wrenchDrop, EnumPowerTier tier, int maxStorage) {
public TileEnergyStorage(String name, int invSize, Block wrenchDrop, EnumPowerTier tier, int maxInput, int maxOuput, int maxStorage) {
inventory = new Inventory(invSize, "Tile" + name, 64, this);
this.wrenchDrop = wrenchDrop;
this.tier = tier;
this.name = name;
this.maxInput = maxInput;
this.maxOutput = maxOuput;
this.maxStorage = maxStorage;
}
@ -91,13 +93,23 @@ public class TileEnergyStorage extends TilePowerAcceptor implements IEnergyProdu
}
}
if (!worldObj.isRemote && getEnergy() > 0) {
double maxOutput = getEnergy() > getMaxOutput() ? getMaxOutput() : getEnergy();
double disposed = emitEnergy(getFacingEnum(), maxOutput);
if (maxOutput != 0 && disposed != 0) useEnergy(disposed);
for(EnumFacing facing : EnumFacing.VALUES) {
double disposed = emitEnergy(facing, maxOutput);
if(disposed != 0) {
maxOutput -= disposed;
useEnergy(disposed);
if (maxOutput == 0) return;
}
}
}
}
//TODO move to RebornCore
public double emitEnergy(EnumFacing enumFacing, double amount) {
BlockPos pos = getPos().offset(enumFacing);
EnergyUtils.PowerNetReceiver receiver = EnergyUtils.getReceiver(
@ -108,16 +120,6 @@ public class TileEnergyStorage extends TilePowerAcceptor implements IEnergyProdu
return 0;
}
@Override
public boolean canAcceptEnergy(EnumFacing direction) {
return getFacingEnum() != direction;
}
@Override
public boolean canProvideEnergy(EnumFacing direction) {
return getFacingEnum() == direction;
}
@Override
public void setFacing(EnumFacing enumFacing) {
worldObj.setBlockState(pos, worldObj.getBlockState(pos).withProperty(BlockEnergyStorage.FACING, enumFacing));

View file

@ -9,7 +9,7 @@ import techreborn.init.ModBlocks;
public class TileMFE extends TileEnergyStorage {
public TileMFE() {
super("MFE", 2, ModBlocks.mfe, EnumPowerTier.HIGH, 4000000);
super("MFE", 2, ModBlocks.mfe, EnumPowerTier.MEDIUM, 512, 512, 4000000);
}
}

View file

@ -9,7 +9,7 @@ import techreborn.init.ModBlocks;
public class TileMFSU extends TileEnergyStorage {
public TileMFSU() {
super("MFSU", 2, ModBlocks.mfsu, EnumPowerTier.EXTREME, 40000000);
super("MFSU", 2, ModBlocks.mfsu, EnumPowerTier.HIGH, 2048, 2048, 40000000);
}
}