Polish to the reactor

This commit is contained in:
Modmuss50 2015-11-16 21:50:09 +00:00
parent b506c2e091
commit 7db2e0dc8c
6 changed files with 132 additions and 76 deletions

View file

@ -54,6 +54,8 @@ public class BlockFusionControlComputer extends BlockMachineBase {
@Override @Override
public boolean onBlockActivated(World world, int x, int y, int z, public boolean onBlockActivated(World world, int x, int y, int z,
EntityPlayer player, int side, float hitX, float hitY, float hitZ) { EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
TileEntityFusionController tileEntityFusionController = (TileEntityFusionController) world.getTileEntity(x, y, z);
tileEntityFusionController.checkCoils();
if (!player.isSneaking()) if (!player.isSneaking())
player.openGui(Core.INSTANCE, GuiHandler.fusionID, world, x, y, player.openGui(Core.INSTANCE, GuiHandler.fusionID, world, x, y,
z); z);

View file

@ -97,6 +97,15 @@ public class ContainerFusionReactor extends RebornContainer {
} else if(id == 4){ } else if(id == 4){
this.neededEU = value; this.neededEU = value;
} }
if(tickTime == -1){
tickTime = 0;
}
if(finalTickTime == -1){
finalTickTime = 0;
}
if(neededEU == -1){
neededEU = 0;
}
} }
public int getProgressScaled(){ public int getProgressScaled(){

View file

@ -27,8 +27,8 @@ public class GuiFusionReactor extends GuiContainer {
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString("EU: " + containerFusionReactor.energy, 11, 8, 16448255); this.fontRendererObj.drawString("EU: " + containerFusionReactor.energy, 11, 8, 16448255);
this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.coilStatus == 1 ? "Yes" : "No") , 11, 16, 16448255); this.fontRendererObj.drawString("Coils: " + (containerFusionReactor.coilStatus == 1 ? "Yes" : "No"), 11, 16, 16448255);
this.fontRendererObj.drawString("Start EU: " + containerFusionReactor.neededEU, 11, 24, 16448255); this.fontRendererObj.drawString("Start EU: " + percentage(containerFusionReactor.neededEU, containerFusionReactor.energy), 11, 24, 16448255);
} }
@ -45,4 +45,10 @@ public class GuiFusionReactor extends GuiContainer {
drawTexturedModalRect(k + 111, l + 34, 176, 14, containerFusionReactor.getProgressScaled(), 16); drawTexturedModalRect(k + 111, l + 34, 176, 14, containerFusionReactor.getProgressScaled(), 16);
} }
public int percentage(int MaxValue, int CurrentValue) {
if (CurrentValue == 0)
return 0;
return (int) ((CurrentValue * 100.0f) / MaxValue);
}
} }

View file

@ -68,7 +68,7 @@ public class FustionReacorRecipeHandler extends TemplateRecipeHandler {
symbols.setGroupingSeparator('.'); symbols.setGroupingSeparator('.');
formatter.setDecimalFormatSymbols(symbols); formatter.setDecimalFormatSymbols(symbols);
GuiDraw.drawString("Start: " + formatter.format(genericRecipe.recipe.getStartEU()) + "EU", 16, 105, -1); GuiDraw.drawString("Start: " + formatter.format(genericRecipe.recipe.getStartEU()) + "EU", 16, 105, -1);
GuiDraw.drawString("EU/t: " + formatter.format(new Integer((int) (genericRecipe.recipe.getEuTick() * genericRecipe.recipe.getTickTime())).longValue()), 16, 115, -1); GuiDraw.drawString("EU/t: " + genericRecipe.recipe.getEuTick() , 16, 115, -1);
GuiDraw.drawString("Ticks to process: " + genericRecipe.recipe.getTickTime(), 14, 125, -1); GuiDraw.drawString("Ticks to process: " + genericRecipe.recipe.getTickTime(), 14, 125, -1);
GuiDraw.drawString("Time to process: " + genericRecipe.recipe.getTickTime() / 20 + " seconds", 14, 135, -1); GuiDraw.drawString("Time to process: " + genericRecipe.recipe.getTickTime() / 20 + " seconds", 14, 135, -1);
} }

View file

@ -85,7 +85,7 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
public double getDemandedEnergy() { public double getDemandedEnergy() {
if (!PowerSystem.EUPOWENET) if (!PowerSystem.EUPOWENET)
return 0; return 0;
return getMaxPower() - getEnergy(); return Math.min(getMaxPower() - getEnergy(), getMaxInput());
} }
@Override @Override
@ -117,7 +117,7 @@ public abstract class TilePowerAcceptor extends RFProviderTile implements
public double getOfferedEnergy() { public double getOfferedEnergy() {
if (!PowerSystem.EUPOWENET) if (!PowerSystem.EUPOWENET)
return 0; return 0;
return getEnergy(); return Math.min(getEnergy(), getMaxOutput());
} }
@Override @Override

View file

@ -42,21 +42,33 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
@Override @Override
public boolean canAcceptEnergy(ForgeDirection direction) { public boolean canAcceptEnergy(ForgeDirection direction) {
if(direction == ForgeDirection.DOWN || direction == ForgeDirection.UP){
return false;
}
return true; return true;
} }
@Override @Override
public boolean canProvideEnergy(ForgeDirection direction) { public boolean canProvideEnergy(ForgeDirection direction) {
return true; if(direction == ForgeDirection.DOWN || direction == ForgeDirection.UP){
return true;
}
return false;
} }
@Override @Override
public double getMaxOutput() { public double getMaxOutput() {
if(!hasStartedCrafting){
return 0;
}
return 1000000; return 1000000;
} }
@Override @Override
public double getMaxInput() { public double getMaxInput() {
if(hasStartedCrafting){
return 0;
}
return 8192; return 8192;
} }
@ -64,7 +76,10 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
public void readFromNBT(NBTTagCompound tagCompound) { public void readFromNBT(NBTTagCompound tagCompound) {
super.readFromNBT(tagCompound); super.readFromNBT(tagCompound);
inventory.readFromNBT(tagCompound); inventory.readFromNBT(tagCompound);
crafingTickTime = tagCompound.getInteger("crafingTickTime");
finalTickTime = tagCompound.getInteger("finalTickTime");
neededPower = tagCompound.getInteger("neededPower");
hasStartedCrafting = tagCompound.getBoolean("hasStartedCrafting");
} }
@Override @Override
@ -72,6 +87,19 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
super.writeToNBT(tagCompound); super.writeToNBT(tagCompound);
inventory.writeToNBT(tagCompound); inventory.writeToNBT(tagCompound);
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);
} }
@Override @Override
@ -135,7 +163,7 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
} }
private boolean checkCoils() { public boolean checkCoils() {
if ((isCoil(this.xCoord + 3, this.yCoord, this.zCoord + 1)) && if ((isCoil(this.xCoord + 3, this.yCoord, this.zCoord + 1)) &&
(isCoil(this.xCoord + 3, this.yCoord, this.zCoord)) && (isCoil(this.xCoord + 3, this.yCoord, this.zCoord)) &&
(isCoil(this.xCoord + 3, this.yCoord, this.zCoord - 1)) && (isCoil(this.xCoord + 3, this.yCoord, this.zCoord - 1)) &&
@ -175,77 +203,82 @@ public class TileEntityFusionController extends TilePowerAcceptor implements IIn
public void updateEntity() { public void updateEntity() {
super.updateEntity(); super.updateEntity();
//TODO improve this code a lot //TODO improve this code a lot
if(worldObj.getTotalWorldTime() % 20 == 0){
if (worldObj.getTotalWorldTime() % 20 == 0) {
checkCoils(); checkCoils();
} }
if(!worldObj.isRemote){ if (!worldObj.isRemote) {
if(coilStatus == 1){ if (coilStatus == 1) {
if(currentRecipe == null){ if (currentRecipe == null) {
if(inventory.hasChanged){ if (inventory.hasChanged || crafingTickTime != 0) {
for(FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes){ for (FusionReactorRecipe reactorRecipe : FusionReactorRecipeHelper.reactorRecipes) {
System.out.println(getStackInSlot(topStackSlot) + "@" + reactorRecipe.getTopInput()); System.out.println(getStackInSlot(topStackSlot) + "@" + reactorRecipe.getTopInput());
if(ItemUtils.isItemEqual(getStackInSlot(topStackSlot), reactorRecipe.getTopInput(), true, true, true)){ if (ItemUtils.isItemEqual(getStackInSlot(topStackSlot), reactorRecipe.getTopInput(), true, true, true)) {
if(reactorRecipe.getBottomInput() != null){ if (reactorRecipe.getBottomInput() != null) {
if(ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), reactorRecipe.getBottomInput(), true, true, true) == false){ if (ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), reactorRecipe.getBottomInput(), true, true, true) == false) {
break; 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;
}
} }
} }
if(canFitStack(reactorRecipe.getOutput(), outputStackSlot, true)){
currentRecipe = reactorRecipe;
hasStartedCrafting = false;
crafingTickTime = 0;
finalTickTime = currentRecipe.getTickTime();
neededPower = (int) currentRecipe.getStartEU();
break;
}
}
}
}
} else {
if(inventory.hasChanged){
if(!validateRecipe()){
resetCrafter();
}
}
if(!hasStartedCrafting){
if(canUseEnergy(currentRecipe.getStartEU())){
setEnergy(getEnergy() - 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 { } else {
if(canFitStack(currentRecipe.getOutput(), outputStackSlot, true)){ if (inventory.hasChanged) {
if(getStackInSlot(outputStackSlot) == null){ if (!validateRecipe()) {
setInventorySlotContents(outputStackSlot, currentRecipe.getOutput().copy()); resetCrafter();
} else {
decrStackSize(outputStackSlot, -currentRecipe.getOutput().stackSize);
} }
decrStackSize(topStackSlot, currentRecipe.getTopInput().stackSize);
if(currentRecipe.getBottomInput() != null){
decrStackSize(bottomStackSlot, currentRecipe.getBottomInput().stackSize);
}
resetCrafter();
} }
if (!hasStartedCrafting) {
if (canUseEnergy(currentRecipe.getStartEU())) {
setEnergy(getEnergy() - 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();
}
}
}
}
} else {
if (currentRecipe != null) {
resetCrafter();
} }
} }
} }
} else {
if(currentRecipe != null){
resetCrafter();
}
}
}
if (inventory.hasChanged) { if (inventory.hasChanged) {
@ -253,25 +286,25 @@ if(!worldObj.isRemote){
} }
} }
private boolean validateRecipe(){ private boolean validateRecipe() {
if(ItemUtils.isItemEqual(getStackInSlot(topStackSlot), currentRecipe.getTopInput(), true, true, true)){ if (ItemUtils.isItemEqual(getStackInSlot(topStackSlot), currentRecipe.getTopInput(), true, true, true)) {
if(currentRecipe.getBottomInput() != null){ if (currentRecipe.getBottomInput() != null) {
if(ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), currentRecipe.getBottomInput(), true, true, true) == false){ if (ItemUtils.isItemEqual(getStackInSlot(bottomStackSlot), currentRecipe.getBottomInput(), true, true, true) == false) {
return false; return false;
} }
} }
if(canFitStack(currentRecipe.getOutput(), outputStackSlot, true)){ if (canFitStack(currentRecipe.getOutput(), outputStackSlot, true)) {
return true; return true;
} }
} }
return false; return false;
} }
private void resetCrafter(){ private void resetCrafter() {
currentRecipe = null; currentRecipe = null;
crafingTickTime = 0; crafingTickTime = -1;
finalTickTime = 0; finalTickTime = -1;
neededPower = 0; neededPower = -1;
hasStartedCrafting = false; hasStartedCrafting = false;
} }
@ -289,4 +322,10 @@ if(!worldObj.isRemote){
} }
return false; return false;
} }
@Override
public void onLoaded() {
super.onLoaded();
checkCoils();
}
} }