From c4ef2886530026a6e50d5b69bf4890ce4c518e47 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 14 Sep 2016 21:42:03 +0200 Subject: [PATCH] added bio reactor Closes #234 --- .../mod/blocks/BlockBioReactor.java | 65 +++++++ .../mod/blocks/InitBlocks.java | 24 +-- .../mod/creative/CreativeTab.java | 1 + .../mod/inventory/ContainerBioReactor.java | 101 +++++++++++ .../mod/inventory/GuiHandler.java | 135 +++++++------- .../mod/inventory/gui/GuiBioReactor.java | 83 +++++++++ .../mod/tile/TileEntityBase.java | 1 + .../mod/tile/TileEntityBioReactor.java | 166 ++++++++++++++++++ .../textures/gui/guiBioReactor.png | Bin 0 -> 2087 bytes 9 files changed, 489 insertions(+), 87 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockBioReactor.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBioReactor.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiBioReactor.java create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java create mode 100644 src/main/resources/assets/actuallyadditions/textures/gui/guiBioReactor.png diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockBioReactor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockBioReactor.java new file mode 100644 index 000000000..c21031491 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockBioReactor.java @@ -0,0 +1,65 @@ +/* + * This file ("BlockBioReactor.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.blocks; + +import de.ellpeck.actuallyadditions.mod.ActuallyAdditions; +import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase; +import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityBioReactor; +import net.minecraft.block.SoundType; +import net.minecraft.block.material.Material; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.EnumRarity; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class BlockBioReactor extends BlockContainerBase{ + + public BlockBioReactor(String name){ + super(Material.ROCK, name); + + this.setHarvestLevel("pickaxe", 0); + this.setHardness(2.0F); + this.setResistance(10.0F); + this.setSoundType(SoundType.STONE); + } + + @Override + public TileEntity createNewTileEntity(World worldIn, int meta){ + return new TileEntityBioReactor(); + } + + @Override + public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing par6, float par7, float par8, float par9){ + if(!world.isRemote){ + if(world.getTileEntity(pos) instanceof TileEntityBioReactor){ + player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.BIO_REACTOR.ordinal(), world, pos.getX(), pos.getY(), pos.getZ()); + } + } + return true; + } + + @Override + public EnumRarity getRarity(ItemStack stack){ + return EnumRarity.EPIC; + } + + @Override + public void breakBlock(World world, BlockPos pos, IBlockState state){ + this.dropInventory(world, pos); + super.breakBlock(world, pos, state); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java index 46c6c145d..4277bf227 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/InitBlocks.java @@ -27,7 +27,6 @@ public final class InitBlocks{ public static Block blockGiantChest; public static Block blockGiantChestMedium; public static Block blockGiantChestLarge; - public static Block blockGrinder; public static Block blockGrinderDouble; public static Block blockFurnaceDouble; @@ -38,22 +37,17 @@ public final class InitBlocks{ public static Block blockHeatCollector; public static Block blockItemRepairer; public static Block blockGreenhouseGlass; - public static Block blockBreaker; public static Block blockPlacer; public static Block blockDropper; - public static Block blockRice; public static Block blockCanola; public static Block blockFlax; public static Block blockCoffee; - public static Block blockCanolaPress; public static Block blockFermentingBarrel; - public static Block blockCoalGenerator; public static Block blockOilGenerator; - public static Block blockPhantomface; public static Block blockPhantomPlacer; public static Block blockPhantomBreaker; @@ -61,18 +55,13 @@ public final class InitBlocks{ public static Block blockPhantomEnergyface; public static Block blockPhantomRedstoneface; public static Block blockPlayerInterface; - public static Block blockFluidPlacer; public static Block blockFluidCollector; - public static Block blockLavaFactoryController; public static Block blockCoffeeMachine; - public static Block blockPhantomBooster; - public static Block blockEnergizer; public static Block blockEnervator; - public static Block blockTestifiBucksGreenWall; public static Block blockTestifiBucksWhiteWall; public static Block blockTestifiBucksGreenStairs; @@ -81,20 +70,15 @@ public final class InitBlocks{ public static Block blockTestifiBucksWhiteSlab; public static Block blockTestifiBucksGreenFence; public static Block blockTestifiBucksWhiteFence; - public static Block blockColoredLamp; public static Block blockColoredLampOn; public static Block blockLampPowerer; - public static Block blockTreasureChest; public static Block blockXPSolidifier; - public static Block blockSmileyCloud; - public static Block blockLeafGenerator; public static Block blockDirectionalBreaker; public static Block blockRangedCollector; - public static Block blockLaserRelay; public static Block blockLaserRelayAdvanced; public static Block blockLaserRelayExtreme; @@ -102,16 +86,12 @@ public final class InitBlocks{ public static Block blockLaserRelayItem; public static Block blockLaserRelayItemWhitelist; public static Block blockItemViewer; - public static Block blockBlackLotus; public static Block blockCrystal; public static Block blockCrystalEmpowered; public static Block blockAtomicReconstructor; - public static Block blockMiner; - public static Block blockFireworkBox; - public static Block blockQuartzWall; public static Block blockQuartzStair; public static Block blockQuartzSlab; @@ -121,18 +101,18 @@ public final class InitBlocks{ public static Block blockPillarQuartzWall; public static Block blockPillarQuartzStair; public static Block blockPillarQuartzSlab; - public static Block blockBookletStand; public static Block blockDisplayStand; public static Block blockShockSuppressor; public static Block blockEmpowerer; public static Block blockDistributorItem; - + public static Block blockBioReactor; public static Block blockTinyTorch; public static void init(){ ModUtil.LOGGER.info("Initializing Blocks..."); + blockBioReactor = new BlockBioReactor("blockBioReactor"); blockDistributorItem = new BlockDistributorItem("blockDistributorItem"); blockEmpowerer = new BlockEmpowerer("blockEmpowerer"); blockTinyTorch = new BlockTinyTorch("blockTinyTorch"); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java index 0d9c5ae79..867951254 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java @@ -100,6 +100,7 @@ public class CreativeTab extends CreativeTabs{ this.add(InitBlocks.blockCoalGenerator); this.add(InitBlocks.blockOilGenerator); this.add(InitBlocks.blockLeafGenerator); + this.add(InitBlocks.blockBioReactor); this.add(InitBlocks.blockItemRepairer); this.add(InitBlocks.blockFishingNet); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBioReactor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBioReactor.java new file mode 100644 index 000000000..333067712 --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerBioReactor.java @@ -0,0 +1,101 @@ +/* + * This file ("ContainerBioReactor.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.inventory; + +import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityBioReactor; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.Container; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; + +public class ContainerBioReactor extends Container{ + + private final TileEntityBioReactor tile; + + public ContainerBioReactor(InventoryPlayer inventory, TileEntityBase tile){ + this.tile = (TileEntityBioReactor)tile; + + for(int i = 0; i < 4; i++){ + for(int j = 0; j < 2; j++){ + this.addSlotToContainer(new Slot(this.tile, j+i*2, 50+j*18, 13+i*18)); + } + } + + for(int i = 0; i < 3; i++){ + for(int j = 0; j < 9; j++){ + this.addSlotToContainer(new Slot(inventory, j+i*9+9, 8+j*18, 97+i*18)); + } + } + for(int i = 0; i < 9; i++){ + this.addSlotToContainer(new Slot(inventory, i, 8+i*18, 155)); + } + } + + @Override + public ItemStack transferStackInSlot(EntityPlayer player, int slot){ + int inventoryStart = 8; + int inventoryEnd = inventoryStart+26; + int hotbarStart = inventoryEnd+1; + int hotbarEnd = hotbarStart+8; + + Slot theSlot = this.inventorySlots.get(slot); + + if(theSlot != null && theSlot.getHasStack()){ + ItemStack newStack = theSlot.getStack(); + ItemStack currentStack = newStack.copy(); + + //Other Slots in Inventory excluded + if(slot >= inventoryStart){ + //Shift from Inventory + if(TileEntityBioReactor.isValidItem(newStack.getItem())){ + if(!this.mergeItemStack(newStack, 0, 8, false)){ + return null; + } + } + // + + else if(slot >= inventoryStart && slot <= inventoryEnd){ + if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){ + return null; + } + } + else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){ + return null; + } + } + else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){ + return null; + } + + if(newStack.stackSize <= 0){ + theSlot.putStack(null); + } + else{ + theSlot.onSlotChanged(); + } + + if(newStack.stackSize == currentStack.stackSize){ + return null; + } + theSlot.onPickupFromSlot(player, newStack); + + return currentStack; + } + return null; + } + + @Override + public boolean canInteractWith(EntityPlayer player){ + return this.tile.isUseableByPlayer(player); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/GuiHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/GuiHandler.java index 83f067c17..b678ea7b1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/GuiHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/GuiHandler.java @@ -30,156 +30,160 @@ public class GuiHandler implements IGuiHandler{ } @Override - public Object getServerGuiElement(int id, EntityPlayer entityPlayer, World world, int x, int y, int z){ + public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z){ TileEntityBase tile = null; if(GuiTypes.values()[id].checkTileEntity){ tile = (TileEntityBase)world.getTileEntity(new BlockPos(x, y, z)); } switch(GuiTypes.values()[id]){ case FEEDER: - return new ContainerFeeder(entityPlayer.inventory, tile); + return new ContainerFeeder(player.inventory, tile); case GIANT_CHEST: - return new ContainerGiantChest(entityPlayer.inventory, tile, 0); + return new ContainerGiantChest(player.inventory, tile, 0); case GIANT_CHEST_PAGE_2: - return new ContainerGiantChest(entityPlayer.inventory, tile, 1); + return new ContainerGiantChest(player.inventory, tile, 1); case GIANT_CHEST_PAGE_3: - return new ContainerGiantChest(entityPlayer.inventory, tile, 2); + return new ContainerGiantChest(player.inventory, tile, 2); case CRAFTER: - return new ContainerCrafter(entityPlayer); + return new ContainerCrafter(player); case GRINDER: - return new ContainerGrinder(entityPlayer.inventory, tile, false); + return new ContainerGrinder(player.inventory, tile, false); case GRINDER_DOUBLE: - return new ContainerGrinder(entityPlayer.inventory, tile, true); + return new ContainerGrinder(player.inventory, tile, true); case FURNACE_DOUBLE: - return new ContainerFurnaceDouble(entityPlayer.inventory, tile); + return new ContainerFurnaceDouble(player.inventory, tile); case INPUTTER: - return new ContainerInputter(entityPlayer.inventory, tile, false); + return new ContainerInputter(player.inventory, tile, false); case INPUTTER_ADVANCED: - return new ContainerInputter(entityPlayer.inventory, tile, true); + return new ContainerInputter(player.inventory, tile, true); case REPAIRER: - return new ContainerRepairer(entityPlayer.inventory, tile); + return new ContainerRepairer(player.inventory, tile); case BREAKER: - return new ContainerBreaker(entityPlayer.inventory, tile); + return new ContainerBreaker(player.inventory, tile); case DROPPER: - return new ContainerDropper(entityPlayer.inventory, tile); + return new ContainerDropper(player.inventory, tile); case CANOLA_PRESS: - return new ContainerCanolaPress(entityPlayer.inventory, tile); + return new ContainerCanolaPress(player.inventory, tile); case FERMENTING_BARREL: - return new ContainerFermentingBarrel(entityPlayer.inventory, tile); + return new ContainerFermentingBarrel(player.inventory, tile); case COAL_GENERATOR: - return new ContainerCoalGenerator(entityPlayer.inventory, tile); + return new ContainerCoalGenerator(player.inventory, tile); case OIL_GENERATOR: - return new ContainerOilGenerator(entityPlayer.inventory, tile); + return new ContainerOilGenerator(player.inventory, tile); case PHANTOM_PLACER: - return new ContainerPhantomPlacer(entityPlayer.inventory, tile); + return new ContainerPhantomPlacer(player.inventory, tile); case FLUID_COLLECTOR: - return new ContainerFluidCollector(entityPlayer.inventory, tile); + return new ContainerFluidCollector(player.inventory, tile); case COFFEE_MACHINE: - return new ContainerCoffeeMachine(entityPlayer.inventory, tile); + return new ContainerCoffeeMachine(player.inventory, tile); case DRILL: - return new ContainerDrill(entityPlayer.inventory); + return new ContainerDrill(player.inventory); case FILTER: - return new ContainerFilter(entityPlayer.inventory); + return new ContainerFilter(player.inventory); case ENERGIZER: - return new ContainerEnergizer(entityPlayer, tile); + return new ContainerEnergizer(player, tile); case ENERVATOR: - return new ContainerEnervator(entityPlayer, tile); + return new ContainerEnervator(player, tile); case XP_SOLIDIFIER: - return new ContainerXPSolidifier(entityPlayer.inventory, tile); + return new ContainerXPSolidifier(player.inventory, tile); case CLOUD: return new ContainerSmileyCloud(); case DIRECTIONAL_BREAKER: - return new ContainerDirectionalBreaker(entityPlayer.inventory, tile); + return new ContainerDirectionalBreaker(player.inventory, tile); case RANGED_COLLECTOR: - return new ContainerRangedCollector(entityPlayer.inventory, tile); + return new ContainerRangedCollector(player.inventory, tile); case MINER: - return new ContainerMiner(entityPlayer.inventory, tile); + return new ContainerMiner(player.inventory, tile); case LASER_RELAY_ITEM_WHITELIST: - return new ContainerLaserRelayItemWhitelist(entityPlayer.inventory, tile); + return new ContainerLaserRelayItemWhitelist(player.inventory, tile); case BAG: - return new ContainerBag(entityPlayer.inventory, false); + return new ContainerBag(player.inventory, false); case VOID_BAG: - return new ContainerBag(entityPlayer.inventory, true); + return new ContainerBag(player.inventory, true); + case BIO_REACTOR: + return new ContainerBioReactor(player.inventory, tile); default: return null; } } @Override - public Object getClientGuiElement(int id, EntityPlayer entityPlayer, World world, int x, int y, int z){ + public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z){ TileEntityBase tile = null; if(GuiTypes.values()[id].checkTileEntity){ tile = (TileEntityBase)world.getTileEntity(new BlockPos(x, y, z)); } switch(GuiTypes.values()[id]){ case FEEDER: - return new GuiFeeder(entityPlayer.inventory, tile); + return new GuiFeeder(player.inventory, tile); case GIANT_CHEST: - return new GuiGiantChest(entityPlayer.inventory, tile, 0); + return new GuiGiantChest(player.inventory, tile, 0); case GIANT_CHEST_PAGE_2: - return new GuiGiantChest(entityPlayer.inventory, tile, 1); + return new GuiGiantChest(player.inventory, tile, 1); case GIANT_CHEST_PAGE_3: - return new GuiGiantChest(entityPlayer.inventory, tile, 2); + return new GuiGiantChest(player.inventory, tile, 2); case CRAFTER: - return new GuiCrafter(entityPlayer); + return new GuiCrafter(player); case GRINDER: - return new GuiGrinder(entityPlayer.inventory, tile); + return new GuiGrinder(player.inventory, tile); case GRINDER_DOUBLE: - return new GuiGrinder.GuiGrinderDouble(entityPlayer.inventory, tile); + return new GuiGrinder.GuiGrinderDouble(player.inventory, tile); case FURNACE_DOUBLE: - return new GuiFurnaceDouble(entityPlayer.inventory, tile); + return new GuiFurnaceDouble(player.inventory, tile); case INPUTTER: - return new GuiInputter(entityPlayer.inventory, tile, x, y, z, world, false); + return new GuiInputter(player.inventory, tile, x, y, z, world, false); case INPUTTER_ADVANCED: - return new GuiInputter(entityPlayer.inventory, tile, x, y, z, world, true); + return new GuiInputter(player.inventory, tile, x, y, z, world, true); case REPAIRER: - return new GuiRepairer(entityPlayer.inventory, tile); + return new GuiRepairer(player.inventory, tile); case BREAKER: - return new GuiBreaker(entityPlayer.inventory, tile); + return new GuiBreaker(player.inventory, tile); case DROPPER: - return new GuiDropper(entityPlayer.inventory, tile); + return new GuiDropper(player.inventory, tile); case CANOLA_PRESS: - return new GuiCanolaPress(entityPlayer.inventory, tile); + return new GuiCanolaPress(player.inventory, tile); case FERMENTING_BARREL: - return new GuiFermentingBarrel(entityPlayer.inventory, tile); + return new GuiFermentingBarrel(player.inventory, tile); case COAL_GENERATOR: - return new GuiCoalGenerator(entityPlayer.inventory, tile); + return new GuiCoalGenerator(player.inventory, tile); case OIL_GENERATOR: - return new GuiOilGenerator(entityPlayer.inventory, tile); + return new GuiOilGenerator(player.inventory, tile); case PHANTOM_PLACER: - return new GuiPhantomPlacer(entityPlayer.inventory, tile); + return new GuiPhantomPlacer(player.inventory, tile); case FLUID_COLLECTOR: - return new GuiFluidCollector(entityPlayer.inventory, tile); + return new GuiFluidCollector(player.inventory, tile); case COFFEE_MACHINE: - return new GuiCoffeeMachine(entityPlayer.inventory, tile, x, y, z, world); + return new GuiCoffeeMachine(player.inventory, tile, x, y, z, world); case DRILL: - return new GuiDrill(entityPlayer.inventory); + return new GuiDrill(player.inventory); case FILTER: - return new GuiFilter(entityPlayer.inventory); + return new GuiFilter(player.inventory); case ENERGIZER: - return new GuiEnergizer(entityPlayer, tile); + return new GuiEnergizer(player, tile); case ENERVATOR: - return new GuiEnervator(entityPlayer, tile); + return new GuiEnervator(player, tile); case XP_SOLIDIFIER: - return new GuiXPSolidifier(entityPlayer.inventory, tile, x, y, z, world); + return new GuiXPSolidifier(player.inventory, tile, x, y, z, world); case CLOUD: return new GuiSmileyCloud(tile, x, y, z, world); case BOOK: return new GuiBooklet(null, true, true); case DIRECTIONAL_BREAKER: - return new GuiDirectionalBreaker(entityPlayer.inventory, tile); + return new GuiDirectionalBreaker(player.inventory, tile); case RANGED_COLLECTOR: - return new GuiRangedCollector(entityPlayer.inventory, tile, x, y, z, world); + return new GuiRangedCollector(player.inventory, tile, x, y, z, world); case MINER: - return new GuiMiner(entityPlayer.inventory, tile); + return new GuiMiner(player.inventory, tile); case BOOK_STAND: return new GuiBookletStand(tile); case LASER_RELAY_ITEM_WHITELIST: - return new GuiLaserRelayItemWhitelist(entityPlayer.inventory, tile); + return new GuiLaserRelayItemWhitelist(player.inventory, tile); case BAG: - return new GuiBag(entityPlayer.inventory, false); + return new GuiBag(player.inventory, false); case VOID_BAG: - return new GuiBag(entityPlayer.inventory, true); + return new GuiBag(player.inventory, true); + case BIO_REACTOR: + return new GuiBioReactor(player.inventory, tile); default: return null; } @@ -219,7 +223,8 @@ public class GuiHandler implements IGuiHandler{ LASER_RELAY_ITEM_WHITELIST, FILTER(false), BAG(false), - VOID_BAG(false); + VOID_BAG(false), + BIO_REACTOR; public final boolean checkTileEntity; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiBioReactor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiBioReactor.java new file mode 100644 index 000000000..9c768a09b --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiBioReactor.java @@ -0,0 +1,83 @@ +/* + * This file ("GuiBioReactor.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.inventory.gui; + +import de.ellpeck.actuallyadditions.mod.inventory.ContainerBioReactor; +import de.ellpeck.actuallyadditions.mod.inventory.ContainerBreaker; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase; +import de.ellpeck.actuallyadditions.mod.tile.TileEntityBioReactor; +import de.ellpeck.actuallyadditions.mod.util.AssetUtil; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.renderer.GlStateManager; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import java.io.IOException; + +public class GuiBioReactor extends GuiContainer{ + + private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("guiBioReactor"); + private final TileEntityBioReactor tile; + private EnergyDisplay energy; + + public GuiBioReactor(InventoryPlayer inventory, TileEntityBase tile){ + super(new ContainerBioReactor(inventory, tile)); + this.tile = (TileEntityBioReactor)tile; + this.xSize = 176; + this.ySize = 93+86; + } + + @Override + public void initGui(){ + super.initGui(); + this.energy = new EnergyDisplay(this.guiLeft+116, this.guiTop+5, this.tile.storage); + } + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{ + super.mouseClicked(mouseX, mouseY, mouseButton); + this.energy.onMouseClick(mouseX, mouseY, mouseButton); + } + + + @Override + public void drawScreen(int x, int y, float f){ + super.drawScreen(x, y, f); + this.energy.drawOverlay(x, y); + } + + @Override + public void drawGuiContainerForegroundLayer(int x, int y){ + AssetUtil.displayNameString(this.fontRendererObj, this.xSize, -10, this.tile); + } + + @Override + public void drawGuiContainerBackgroundLayer(float f, int x, int y){ + GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F); + + this.mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION); + this.drawTexturedModalRect(this.guiLeft, this.guiTop+93, 0, 0, 176, 86); + + this.mc.getTextureManager().bindTexture(RES_LOC); + this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93); + + if(this.tile.burnTime > 0){ + int i = this.tile.burnTime*13/this.tile.maxBurnTime; + this.drawTexturedModalRect(this.guiLeft+87, this.guiTop+51+12-i, 176, 96-i, 14, i); + } + + if(this.tile.producePerTick > 0){ + this.drawCenteredString(this.fontRendererObj, this.tile.producePerTick+" RF/t", this.guiLeft+87, this.guiTop+86, 0xFFFFFF); + } + + this.energy.draw(); + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java index 7e9fc1679..5ed873a72 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBase.java @@ -109,6 +109,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{ register(TileEntityEmpowerer.class); register(TileEntityLaserRelayFluids.class); register(TileEntityDistributorItem.class); + register(TileEntityBioReactor.class); } private static void register(Class tileClass, String legacyName){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java new file mode 100644 index 000000000..e8db2f59b --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityBioReactor.java @@ -0,0 +1,166 @@ +/* + * This file ("TileEntityBioReactor.java") is part of the Actually Additions mod for Minecraft. + * It is created and owned by Ellpeck and distributed + * under the Actually Additions License to be found at + * http://ellpeck.de/actaddlicense + * View the source code at https://github.com/Ellpeck/ActuallyAdditions + * + * © 2015-2016 Ellpeck + */ + +package de.ellpeck.actuallyadditions.mod.tile; + +import cofh.api.energy.EnergyStorage; +import net.minecraft.block.IGrowable; +import net.minecraft.item.Item; +import net.minecraft.item.ItemFood; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.common.IPlantable; + +import java.util.ArrayList; +import java.util.List; + +public class TileEntityBioReactor extends TileEntityInventoryBase implements ISharingEnergyProvider{ + + public final EnergyStorage storage = new EnergyStorage(200000); + + public int burnTime; + public int maxBurnTime; + public int producePerTick; + + private int lastBurnTime; + private int lastProducePerTick; + + public TileEntityBioReactor(){ + super(8, "bioReactor"); + } + + @Override + public void updateEntity(){ + super.updateEntity(); + + if(this.burnTime <= 0){ + List types = null; + + if(this.storage.getEnergyStored() < this.storage.getMaxEnergyStored()){ + for(int i = 0; i < this.slots.length; i++){ + ItemStack stack = this.slots[i]; + if(stack != null){ + Item item = stack.getItem(); + if(isValidItem(item) && (types == null || !types.contains(item))){ + if(types == null){ + types = new ArrayList(); + } + types.add(item); + + stack.stackSize--; + if(stack.stackSize <= 0){ + this.slots[i] = null; + } + } + } + } + + this.markDirty(); + } + + if(types != null && !types.isEmpty()){ + int amount = types.size(); + this.producePerTick = (int)Math.pow(amount*2, 2); + + this.maxBurnTime = 200-(int)Math.pow(1.8, amount); + this.burnTime = this.maxBurnTime; + } + else{ + this.burnTime = 0; + this.maxBurnTime = 0; + this.producePerTick = 0; + } + } + else{ + this.burnTime--; + this.storage.receiveEnergy(this.producePerTick, false); + } + + if((this.lastBurnTime != this.burnTime || this.lastProducePerTick != this.producePerTick) && this.sendUpdateWithInterval()){ + this.lastBurnTime = this.burnTime; + this.lastProducePerTick = this.producePerTick; + } + } + + @Override + public void writeSyncableNBT(NBTTagCompound compound, NBTType type){ + super.writeSyncableNBT(compound, type); + + this.storage.writeToNBT(compound); + compound.setInteger("BurnTime", this.burnTime); + compound.setInteger("MaxBurnTime", this.maxBurnTime); + compound.setInteger("ProducePerTick", this.producePerTick); + } + + @Override + public void readSyncableNBT(NBTTagCompound compound, NBTType type){ + super.readSyncableNBT(compound, type); + + this.storage.readFromNBT(compound); + this.burnTime = compound.getInteger("BurnTime"); + this.maxBurnTime = compound.getInteger("MaxBurnTime"); + this.producePerTick = compound.getInteger("ProducePerTick"); + } + + public static boolean isValidItem(Item item){ + return item instanceof IPlantable || item instanceof IGrowable || item instanceof ItemFood; + } + + @Override + public boolean canInsertItem(int index, ItemStack stack, EnumFacing direction){ + return this.isItemValidForSlot(index, stack); + } + + @Override + public boolean canExtractItem(int index, ItemStack stack, EnumFacing direction){ + return false; + } + + @Override + public boolean isItemValidForSlot(int index, ItemStack stack){ + return isValidItem(stack.getItem()); + } + + @Override + public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate){ + return this.storage.extractEnergy(maxExtract, simulate); + } + + @Override + public int getEnergyStored(EnumFacing from){ + return this.storage.getEnergyStored(); + } + + @Override + public int getMaxEnergyStored(EnumFacing from){ + return this.storage.getMaxEnergyStored(); + } + + @Override + public boolean canConnectEnergy(EnumFacing from){ + return true; + } + + @Override + public int getEnergyToSplitShare(){ + return this.storage.getEnergyStored(); + } + + @Override + public boolean doesShareEnergy(){ + return true; + } + + @Override + public EnumFacing[] getEnergyShareSides(){ + return EnumFacing.values(); + } +} diff --git a/src/main/resources/assets/actuallyadditions/textures/gui/guiBioReactor.png b/src/main/resources/assets/actuallyadditions/textures/gui/guiBioReactor.png new file mode 100644 index 0000000000000000000000000000000000000000..a1889d681495e620ce32a2ac54a055a9385e5931 GIT binary patch literal 2087 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5893O0R7}x|G$6&2?&#~tz_78O`%fY(kk47* z5n0T@z_$#98Qbry%m)fembgZg1m~xflqVLYG880c=9TE>rIsj|=o#o48m#5wI>5ld zzQohTF{C2y?e&X=(w;)B4wXe|Cz^imj*nEWzs7R2;NFK-p)x{QV#(9l&9d6&N`6dg zRb=qhT_wLTU;VqvTg$D>moL|!AA9soiS&HuI+^Dtc^_A&yBnIPe|UX;eeiULJCCNH z?@M|Yp3J#a-M;S6kGUUbK5;MB+b9=rXWg|kcpz0r8)cQxqL<3$X=HZPuG z9qO&w-_7&_q%lNysf`}j0(&wP7w@b8UsqoD?@wgh|BPe5L%vsBgd4L>%hNM2eSZX+GCzC=F!zdo%FN+*M2GEM~ao%J>E7netWBiu#x$#91%QmpyuC zWz;E4u7udZtm*i{-PhCi`j_^H_rgN)>70+Vf8Xml93MLx78Hg>@i!)k>(8@8|GoSy zCy66X%-PG}cI>>}ryn{v($l${+z)<4mj3;A{%Y~A#js>=>CU(Yp75W}F&01Y_WY{X z_22irL!{iDPKeDn1v( zpnUxNz3M;rwi>&@llQq$?ghKbZ0x)d$$HLChP?W37qinl5VmZtXWmhSP$I+rK5qV3 zyQ{WwrU(m;<-e;o=BqFLyIAsl@ZHCu2+uvYsQ8}pW6k%K?>?@=5iCP0o1v5fNMVt# z-%!~9|L^(zr>o}||K9U_`hLrt^fSQ1tmHT2smH~wOclRg-<~bBLazUL?jD@aZ~q;`aQy3Z`{U>H2EH(1}a*Qv#Z(ebYbi{EStxj@Xx%y zO1Bg0sKqk!pEQds>;hh%3}Hw=+5PzS|F?d7mxq zd|sZt*;9LVYp?wuyBq%d`M(w3*eud^{r->QKpTiZNH`yZ*4e)g@scifSM_H}hN+7j%4H5wkzVrtM| z@@rRoop!~(vKsA*y2{E2=fob!R_?eQ!|-_jde#Yj&u#Yau_;LB{?Ipl{kMVH>`m6F>f#A5#s{nlSOzfw{T|l&&^fM>n{xVlLmt&>h15E{9QU zCEuN!OgcfbJ2taMEU^L_2&^v$Avo~={q61l8C{Mn>27;<`UA*?p00i_>zopr0H5!! AMF0Q* literal 0 HcmV?d00001