diff --git a/src/main/java/techreborn/blockentity/machine/tier1/TapperBlockEntity.java b/src/main/java/techreborn/blockentity/machine/tier1/TapperBlockEntity.java new file mode 100644 index 000000000..249637548 --- /dev/null +++ b/src/main/java/techreborn/blockentity/machine/tier1/TapperBlockEntity.java @@ -0,0 +1,150 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2020 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.blockentity.machine.tier1; + +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.sound.SoundCategory; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Direction; +import reborncore.client.screen.BuiltScreenHandlerProvider; +import reborncore.client.screen.builder.BuiltScreenHandler; +import reborncore.client.screen.builder.ScreenHandlerBuilder; +import reborncore.common.util.RebornInventory; +import techreborn.blockentity.machine.GenericMachineBlockEntity; +import techreborn.blocks.misc.BlockRubberLog; +import techreborn.config.TechRebornConfig; +import techreborn.init.ModSounds; +import techreborn.init.TRBlockEntities; +import techreborn.init.TRContent; + +import java.util.HashMap; +import java.util.Map; + +public class TapperBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider { + + private static final int ENERGY_SLOT = 0; + private static final int OUTPUT_SLOT = 1; + + //TODO LIST + // Check tree structure + // Move off to own functions + // Run every like 5 seconds or something slow + // GUI + // Textures + // Orientable + // Use energy (check before) + // Ensure storage before sapping + + public TapperBlockEntity() { + super(TRBlockEntities.TAPPER, "Tapper", TechRebornConfig.tapperMaxInput, TechRebornConfig.tapperMaxEnergy, TRContent.Machine.EXTRACTOR.block, ENERGY_SLOT); + this.inventory = new RebornInventory<>(2, "TapperBlockEntity", 64, this); + } + + @Override + public void tick() { + super.tick(); + + if(world == null || world.isClient) return; + + // TODO cleanup and refactor (MVP) + HashMap rubberLogs = new HashMap<>(); + + BlockPos originPos = this.pos.offset(Direction.NORTH); + BlockState originState = world.getBlockState(originPos); + if(originState.getBlock() != TRContent.RUBBER_LOG) return; // TODO CHECK STRUCTURE + + rubberLogs.put(originPos, originState); + + boolean shouldExit = false; + BlockPos current = originPos; + // Progress Up + while(!shouldExit){ + current = current.offset(Direction.UP); + + BlockState state = world.getBlockState(current); + if(state.getBlock() == TRContent.RUBBER_LOG){ + rubberLogs.put(current, state); + }else{ + shouldExit = true; + } + } + + // Progress Down + shouldExit = false; + current = originPos; + while(!shouldExit){ + current = current.offset(Direction.DOWN); + + BlockState state = world.getBlockState(current); + if(state.getBlock() == TRContent.RUBBER_LOG){ + rubberLogs.put(current, state); + }else{ + shouldExit = true; + } + } + + + int yield = 0; + + // Harvest sap + for (Map.Entry entry : rubberLogs.entrySet()) { + BlockPos pos = entry.getKey(); + BlockState state = entry.getValue(); + if(state.get(BlockRubberLog.HAS_SAP)){ + world.setBlockState(pos, state.with(BlockRubberLog.HAS_SAP, false).with(BlockRubberLog.SAP_SIDE, Direction.fromHorizontal(0))); + yield++; + } + } + + if(yield > 0){ + world.playSound(pos.getX(),pos.getY(),pos.getZ(), ModSounds.SAP_EXTRACT, SoundCategory.BLOCKS, 0.6F, 1F, false); + + + if(inventory.getStack(OUTPUT_SLOT).isEmpty()){ + ItemStack yieldStack = TRContent.Parts.SAP.getStack(); + yieldStack.setCount(yield); + this.inventory.setStack(OUTPUT_SLOT,yieldStack); + }else{ + ItemStack currentStack = inventory.getStack(OUTPUT_SLOT); + if(currentStack.getCount() + yield <= inventory.getStackLimit()){ + currentStack.increment(yield); + // TODO check room before harvesting + inventory.setStack(OUTPUT_SLOT, currentStack); + } + } + + } + } + + // IContainerProvider + @Override + public BuiltScreenHandler createScreenHandler(int syncID, final PlayerEntity player) { + return new ScreenHandlerBuilder("tapper").player(player.inventory).inventory().hotbar().addInventory().blockEntity(this) + .energySlot(0, 8, 72).outputSlot(1, 101, 45).syncEnergyValue() + .addInventory().create(this, syncID); + } +} diff --git a/src/main/java/techreborn/client/GuiType.java b/src/main/java/techreborn/client/GuiType.java index 0e0cd5689..d32287bbe 100644 --- a/src/main/java/techreborn/client/GuiType.java +++ b/src/main/java/techreborn/client/GuiType.java @@ -99,6 +99,7 @@ public final class GuiType implements IMachineGuiHandler public static final GuiType DISTILLATION_TOWER = register("distillation_tower", () -> () -> GuiDistillationTower::new); public static final GuiType ELECTRIC_FURNACE = register("electric_furnace", () -> () -> GuiElectricFurnace::new); public static final GuiType EXTRACTOR = register("extractor", () -> () -> GuiExtractor::new); + public static final GuiType TAPPER = register("tapper", () -> () -> GuiTapper::new); public static final GuiType FUSION_CONTROLLER = register("fusion_controller", () -> () -> GuiFusionReactor::new); public static final GuiType GAS_TURBINE = register("gas_turbine", () -> () -> GuiGasTurbine::new); public static final GuiType GENERATOR = register("generator", () -> () -> GuiGenerator::new); diff --git a/src/main/java/techreborn/client/gui/GuiTapper.java b/src/main/java/techreborn/client/gui/GuiTapper.java new file mode 100644 index 000000000..7b33a0f65 --- /dev/null +++ b/src/main/java/techreborn/client/gui/GuiTapper.java @@ -0,0 +1,60 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2020 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.client.gui; + +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.entity.player.PlayerEntity; +import reborncore.client.gui.builder.GuiBase; +import reborncore.client.gui.guibuilder.GuiBuilder; +import reborncore.client.screen.builder.BuiltScreenHandler; +import techreborn.blockentity.machine.tier1.ExtractorBlockEntity; +import techreborn.blockentity.machine.tier1.TapperBlockEntity; + +public class GuiTapper extends GuiBase { + + TapperBlockEntity blockEntity; + + public GuiTapper(int syncID, final PlayerEntity player, final TapperBlockEntity blockEntity) { + super(player, blockEntity, blockEntity.createScreenHandler(syncID, player)); + this.blockEntity = blockEntity; + } + + @Override + protected void drawBackground(MatrixStack matrixStack, final float f, final int mouseX, final int mouseY) { + super.drawBackground(matrixStack, f, mouseX, mouseY); + final Layer layer = Layer.BACKGROUND; + + drawSlot(matrixStack, 8, 72, layer); + drawOutputSlot(matrixStack, 101, 45, layer); + } + + @Override + protected void drawForeground(MatrixStack matrixStack, final int mouseX, final int mouseY) { + super.drawForeground(matrixStack, mouseX, mouseY); + final Layer layer = Layer.FOREGROUND; + + builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) blockEntity.getEnergy(), (int) blockEntity.getMaxPower(), mouseX, mouseY, 0, layer); + } +} diff --git a/src/main/java/techreborn/config/TechRebornConfig.java b/src/main/java/techreborn/config/TechRebornConfig.java index 0ce6c59b7..c71ac0c9d 100644 --- a/src/main/java/techreborn/config/TechRebornConfig.java +++ b/src/main/java/techreborn/config/TechRebornConfig.java @@ -342,6 +342,12 @@ public class TechRebornConfig { @Config(config = "machines", category = "extractor", key = "ExtractorMaxEnergy", comment = "Extractor Max Energy (Value in EU)") public static int extractorMaxEnergy = 1_000; + @Config(config = "machines", category = "extractor", key = "TapperInput", comment = "Tapper Max Input (Value in EU)") + public static int tapperMaxInput = 32; + + @Config(config = "machines", category = "extractor", key = "TapperMaxEnergy", comment = "Tapper Max Energy (Value in EU)") + public static int tapperMaxEnergy = 1_000; + @Config(config = "machines", category = "compressor", key = "CompressorInput", comment = "Compressor Max Input (Value in EU)") public static int compressorMaxInput = 32; diff --git a/src/main/java/techreborn/init/TRBlockEntities.java b/src/main/java/techreborn/init/TRBlockEntities.java index 87bb17d62..7f6355dc3 100644 --- a/src/main/java/techreborn/init/TRBlockEntities.java +++ b/src/main/java/techreborn/init/TRBlockEntities.java @@ -111,6 +111,7 @@ public class TRBlockEntities { public static final BlockEntityType INDUSTRIAL_SAWMILL = register(IndustrialSawmillBlockEntity::new, "industrial_sawmill", TRContent.Machine.INDUSTRIAL_SAWMILL); public static final BlockEntityType SOLID_FUEL_GENEREATOR = register(SolidFuelGeneratorBlockEntity::new, "solid_fuel_generator", TRContent.Machine.SOLID_FUEL_GENERATOR); public static final BlockEntityType EXTRACTOR = register(ExtractorBlockEntity::new, "extractor", TRContent.Machine.EXTRACTOR); + public static final BlockEntityType TAPPER = register(TapperBlockEntity::new, "tapper", TRContent.Machine.TAPPER); public static final BlockEntityType COMPRESSOR = register(CompressorBlockEntity::new, "compressor", TRContent.Machine.COMPRESSOR); public static final BlockEntityType ELECTRIC_FURNACE = register(ElectricFurnaceBlockEntity::new, "electric_furnace", TRContent.Machine.ELECTRIC_FURNACE); public static final BlockEntityType SOLAR_PANEL = register(SolarPanelBlockEntity::new, "solar_panel", TRContent.SolarPanels.values()); diff --git a/src/main/java/techreborn/init/TRContent.java b/src/main/java/techreborn/init/TRContent.java index 3810bb527..b71984f85 100644 --- a/src/main/java/techreborn/init/TRContent.java +++ b/src/main/java/techreborn/init/TRContent.java @@ -520,6 +520,7 @@ public class TRContent { COMPRESSOR(new GenericMachineBlock(GuiType.COMPRESSOR, CompressorBlockEntity::new)), DISTILLATION_TOWER(new GenericMachineBlock(GuiType.DISTILLATION_TOWER, DistillationTowerBlockEntity::new)), EXTRACTOR(new GenericMachineBlock(GuiType.EXTRACTOR, ExtractorBlockEntity::new)), + TAPPER(new GenericMachineBlock(GuiType.TAPPER, TapperBlockEntity::new)), FLUID_REPLICATOR(new GenericMachineBlock(GuiType.FLUID_REPLICATOR, FluidReplicatorBlockEntity::new)), GRINDER(new DataDrivenMachineBlock("techreborn:grinder")), ELECTRIC_FURNACE(new GenericMachineBlock(GuiType.ELECTRIC_FURNACE, ElectricFurnaceBlockEntity::new)),