Generator logic

This commit is contained in:
modmuss50 2016-02-24 16:11:07 +00:00
parent c8453292b4
commit b61acffc68
4 changed files with 108 additions and 32 deletions

View file

@ -1,8 +1,11 @@
package techreborn.client.container;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.Slot;
import net.minecraft.inventory.SlotFurnaceFuel;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import reborncore.common.container.RebornContainer;
import techreborn.tiles.generator.TileGenerator;
@ -12,6 +15,10 @@ public class ContainerGenerator extends RebornContainer {
TileGenerator tile;
public int burnTime = 0;
public int totalBurnTime = 0;
public int energy;
@Override
public boolean canInteractWith(EntityPlayer player) {
return true;
@ -45,4 +52,46 @@ public class ContainerGenerator extends RebornContainer {
}
}
@Override
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (int i = 0; i < this.crafters.size(); i++) {
ICrafting icrafting = (ICrafting) this.crafters.get(i);
if (this.burnTime != tile.burnTime) {
icrafting.sendProgressBarUpdate(this, 0, tile.burnTime);
}
if (this.totalBurnTime != tile.totalBurnTime) {
icrafting.sendProgressBarUpdate(this, 1, tile.totalBurnTime);
}
if (this.energy != (int) tile.getEnergy()) {
icrafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy());
}
}
}
@Override
public void onCraftGuiOpened(ICrafting crafting) {
super.onCraftGuiOpened(crafting);
crafting.sendProgressBarUpdate(this, 0, tile.burnTime);
crafting.sendProgressBarUpdate(this, 1, tile.totalBurnTime);
crafting.sendProgressBarUpdate(this, 2, (int) tile.getEnergy());
}
@SideOnly(Side.CLIENT)
@Override
public void updateProgressBar(int id, int value) {
if (id == 0) {
this.burnTime = value;
} else if (id == 1) {
this.totalBurnTime = value;
} else if (id == 2) {
this.energy = value;
}
this.tile.setEnergy(energy);
}
public int getScaledBurnTime(int i) {
return (int) (((float) burnTime / (float) totalBurnTime) * i);
}
}

View file

@ -3,6 +3,7 @@ package techreborn.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.StatCollector;
import techreborn.client.container.ContainerGenerator;
@ -14,11 +15,14 @@ public class GuiGenerator extends GuiContainer {
TileGenerator generator;
ContainerGenerator containerGenerator;
public GuiGenerator(EntityPlayer player, TileGenerator generator) {
super(new ContainerGenerator(generator, player));
this.xSize = 176;
this.ySize = 167;
this.generator = generator;
this.containerGenerator = (ContainerGenerator) this.inventorySlots;
}
@Override
@ -41,11 +45,19 @@ public class GuiGenerator extends GuiContainer {
if (j > 0) {
this.drawTexturedModalRect(k + 56, l + 36 + 12 - j, 176, 12 - j, 14, j + 2);
}
if (containerGenerator.burnTime != 0)
{
j = containerGenerator.getScaledBurnTime(13);
this.drawTexturedModalRect(k + 56, l + 36 + 12 - j, 176, 12 - j, 14, j + 1);
}
}
protected void drawGuiContainerForegroundLayer(int p_146979_1_, int p_146979_2_) {
String name = StatCollector.translateToLocal("tile.techreborn.generator.name");
this.fontRendererObj.drawString(name, this.xSize / 2 - this.fontRendererObj.getStringWidth(name) / 2, 6, 4210752);
this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
this.fontRendererObj.drawString(containerGenerator.energy + "eu", 25, this.ySize- 150, 4210752);
}
}

View file

@ -160,7 +160,7 @@ public class TileAlloySmelter extends TilePowerAcceptor implements IWrenchable,
}
public int getProgressScaled(int scale) {
if (crafter.currentTickTime != 0) {
if (crafter.currentTickTime != 0 && crafter.currentNeededTicks != 0) {
return crafter.currentTickTime * scale / crafter.currentNeededTicks;
}
return 0;

View file

@ -3,14 +3,18 @@ package techreborn.tiles.generator;
import ic2.api.tile.IWrenchable;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
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.IInventory;
import net.minecraft.item.*;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.IChatComponent;
import net.minecraftforge.fml.common.network.PacketLoggingHandler;
import net.minecraftforge.fml.common.registry.GameRegistry;
import reborncore.common.blocks.BlockMachineBase;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.config.ConfigTechReborn;
@ -21,50 +25,61 @@ public class TileGenerator extends TilePowerAcceptor implements IWrenchable, IIn
public Inventory inventory = new Inventory(2, "TileGenerator", 64, this);
public int fuelSlot = 0;
public static int burnTime;
public int currentItemBurnTime;
public static int outputAmount = 40;
public int burnTime;
public int totalBurnTime = 0;
public static int outputAmount = 40; //This is in line with BC engines rf, sould properly use the conversion ratio here.
public boolean isBurning;
public boolean lastTickBurning;
ItemStack burnItem;
public TileGenerator(){
super(1);
}
public static int getItemBurnTime(ItemStack stack) {
if (stack == null) {
return 0;
@Override
public void updateEntity() {
super.updateEntity();
if(worldObj.isRemote){
return;
}
if (burnTime > 0) {
burnTime--;
addEnergy(outputAmount);
isBurning = true;
} else {
Item item = stack.getItem();
isBurning = false;
}
if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.air) {
Block block = Block.getBlockFromItem(item);
if (block == Blocks.wooden_slab) {
return 150;
}
if (block.getMaterial() == Material.wood) {
return 300;
}
if (block == Blocks.coal_block) {
return 16000;
if (burnTime == 0) {
updateState();
burnTime = totalBurnTime = getItemBurnTime(getStackInSlot(fuelSlot));
if (burnTime > 0) {
updateState();
burnItem = getStackInSlot(fuelSlot);
if(getStackInSlot(fuelSlot).stackSize == 1){
setInventorySlotContents(fuelSlot, null);
} else {
decrStackSize(fuelSlot, 1);
}
}
}
if (item instanceof ItemTool && ((ItemTool) item).getToolMaterialName().equals("WOOD")) return 200;
if (item instanceof ItemSword && ((ItemSword) item).getToolMaterialName().equals("WOOD")) return 200;
//if (item instanceof ItemHoe && ((ItemHoe) item).getToolMaterialName().equals("WOOD")) return 200;
if (item == Items.stick) return 100;
if (item == Items.coal) return 1600;
if (item == Items.lava_bucket) return 20000;
if (item == Item.getItemFromBlock(Blocks.sapling)) return 100;
if (item == Items.blaze_rod) return 2400;
return GameRegistry.getFuelValue(stack);
lastTickBurning = isBurning;
}
public void updateState(){
IBlockState blockState = worldObj.getBlockState(pos);
if(blockState.getBlock() instanceof BlockMachineBase){
BlockMachineBase blockMachineBase = (BlockMachineBase) blockState.getBlock();
if(blockState.getValue(BlockMachineBase.ACTIVE) != burnTime > 0)
blockMachineBase.setActive(burnTime > 0, worldObj, pos);
}
}
public static int getItemBurnTime(ItemStack stack) {
return TileEntityFurnace.getItemBurnTime(stack);
}
@Override
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
return false;