Add sapper base logic code (MVP) along with rest of it
This commit is contained in:
parent
b176230f77
commit
6dc00090d1
6 changed files with 219 additions and 0 deletions
|
@ -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<BlockPos, BlockState> 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<BlockPos, BlockState> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -99,6 +99,7 @@ public final class GuiType<T extends BlockEntity> implements IMachineGuiHandler
|
||||||
public static final GuiType<DistillationTowerBlockEntity> DISTILLATION_TOWER = register("distillation_tower", () -> () -> GuiDistillationTower::new);
|
public static final GuiType<DistillationTowerBlockEntity> DISTILLATION_TOWER = register("distillation_tower", () -> () -> GuiDistillationTower::new);
|
||||||
public static final GuiType<ElectricFurnaceBlockEntity> ELECTRIC_FURNACE = register("electric_furnace", () -> () -> GuiElectricFurnace::new);
|
public static final GuiType<ElectricFurnaceBlockEntity> ELECTRIC_FURNACE = register("electric_furnace", () -> () -> GuiElectricFurnace::new);
|
||||||
public static final GuiType<ExtractorBlockEntity> EXTRACTOR = register("extractor", () -> () -> GuiExtractor::new);
|
public static final GuiType<ExtractorBlockEntity> EXTRACTOR = register("extractor", () -> () -> GuiExtractor::new);
|
||||||
|
public static final GuiType<TapperBlockEntity> TAPPER = register("tapper", () -> () -> GuiTapper::new);
|
||||||
public static final GuiType<FusionControlComputerBlockEntity> FUSION_CONTROLLER = register("fusion_controller", () -> () -> GuiFusionReactor::new);
|
public static final GuiType<FusionControlComputerBlockEntity> FUSION_CONTROLLER = register("fusion_controller", () -> () -> GuiFusionReactor::new);
|
||||||
public static final GuiType<GasTurbineBlockEntity> GAS_TURBINE = register("gas_turbine", () -> () -> GuiGasTurbine::new);
|
public static final GuiType<GasTurbineBlockEntity> GAS_TURBINE = register("gas_turbine", () -> () -> GuiGasTurbine::new);
|
||||||
public static final GuiType<SolidFuelGeneratorBlockEntity> GENERATOR = register("generator", () -> () -> GuiGenerator::new);
|
public static final GuiType<SolidFuelGeneratorBlockEntity> GENERATOR = register("generator", () -> () -> GuiGenerator::new);
|
||||||
|
|
60
src/main/java/techreborn/client/gui/GuiTapper.java
Normal file
60
src/main/java/techreborn/client/gui/GuiTapper.java
Normal file
|
@ -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<BuiltScreenHandler> {
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -342,6 +342,12 @@ public class TechRebornConfig {
|
||||||
@Config(config = "machines", category = "extractor", key = "ExtractorMaxEnergy", comment = "Extractor Max Energy (Value in EU)")
|
@Config(config = "machines", category = "extractor", key = "ExtractorMaxEnergy", comment = "Extractor Max Energy (Value in EU)")
|
||||||
public static int extractorMaxEnergy = 1_000;
|
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)")
|
@Config(config = "machines", category = "compressor", key = "CompressorInput", comment = "Compressor Max Input (Value in EU)")
|
||||||
public static int compressorMaxInput = 32;
|
public static int compressorMaxInput = 32;
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ public class TRBlockEntities {
|
||||||
public static final BlockEntityType<IndustrialSawmillBlockEntity> INDUSTRIAL_SAWMILL = register(IndustrialSawmillBlockEntity::new, "industrial_sawmill", TRContent.Machine.INDUSTRIAL_SAWMILL);
|
public static final BlockEntityType<IndustrialSawmillBlockEntity> INDUSTRIAL_SAWMILL = register(IndustrialSawmillBlockEntity::new, "industrial_sawmill", TRContent.Machine.INDUSTRIAL_SAWMILL);
|
||||||
public static final BlockEntityType<SolidFuelGeneratorBlockEntity> SOLID_FUEL_GENEREATOR = register(SolidFuelGeneratorBlockEntity::new, "solid_fuel_generator", TRContent.Machine.SOLID_FUEL_GENERATOR);
|
public static final BlockEntityType<SolidFuelGeneratorBlockEntity> SOLID_FUEL_GENEREATOR = register(SolidFuelGeneratorBlockEntity::new, "solid_fuel_generator", TRContent.Machine.SOLID_FUEL_GENERATOR);
|
||||||
public static final BlockEntityType<ExtractorBlockEntity> EXTRACTOR = register(ExtractorBlockEntity::new, "extractor", TRContent.Machine.EXTRACTOR);
|
public static final BlockEntityType<ExtractorBlockEntity> EXTRACTOR = register(ExtractorBlockEntity::new, "extractor", TRContent.Machine.EXTRACTOR);
|
||||||
|
public static final BlockEntityType<TapperBlockEntity> TAPPER = register(TapperBlockEntity::new, "tapper", TRContent.Machine.TAPPER);
|
||||||
public static final BlockEntityType<CompressorBlockEntity> COMPRESSOR = register(CompressorBlockEntity::new, "compressor", TRContent.Machine.COMPRESSOR);
|
public static final BlockEntityType<CompressorBlockEntity> COMPRESSOR = register(CompressorBlockEntity::new, "compressor", TRContent.Machine.COMPRESSOR);
|
||||||
public static final BlockEntityType<ElectricFurnaceBlockEntity> ELECTRIC_FURNACE = register(ElectricFurnaceBlockEntity::new, "electric_furnace", TRContent.Machine.ELECTRIC_FURNACE);
|
public static final BlockEntityType<ElectricFurnaceBlockEntity> ELECTRIC_FURNACE = register(ElectricFurnaceBlockEntity::new, "electric_furnace", TRContent.Machine.ELECTRIC_FURNACE);
|
||||||
public static final BlockEntityType<SolarPanelBlockEntity> SOLAR_PANEL = register(SolarPanelBlockEntity::new, "solar_panel", TRContent.SolarPanels.values());
|
public static final BlockEntityType<SolarPanelBlockEntity> SOLAR_PANEL = register(SolarPanelBlockEntity::new, "solar_panel", TRContent.SolarPanels.values());
|
||||||
|
|
|
@ -520,6 +520,7 @@ public class TRContent {
|
||||||
COMPRESSOR(new GenericMachineBlock(GuiType.COMPRESSOR, CompressorBlockEntity::new)),
|
COMPRESSOR(new GenericMachineBlock(GuiType.COMPRESSOR, CompressorBlockEntity::new)),
|
||||||
DISTILLATION_TOWER(new GenericMachineBlock(GuiType.DISTILLATION_TOWER, DistillationTowerBlockEntity::new)),
|
DISTILLATION_TOWER(new GenericMachineBlock(GuiType.DISTILLATION_TOWER, DistillationTowerBlockEntity::new)),
|
||||||
EXTRACTOR(new GenericMachineBlock(GuiType.EXTRACTOR, ExtractorBlockEntity::new)),
|
EXTRACTOR(new GenericMachineBlock(GuiType.EXTRACTOR, ExtractorBlockEntity::new)),
|
||||||
|
TAPPER(new GenericMachineBlock(GuiType.TAPPER, TapperBlockEntity::new)),
|
||||||
FLUID_REPLICATOR(new GenericMachineBlock(GuiType.FLUID_REPLICATOR, FluidReplicatorBlockEntity::new)),
|
FLUID_REPLICATOR(new GenericMachineBlock(GuiType.FLUID_REPLICATOR, FluidReplicatorBlockEntity::new)),
|
||||||
GRINDER(new DataDrivenMachineBlock("techreborn:grinder")),
|
GRINDER(new DataDrivenMachineBlock("techreborn:grinder")),
|
||||||
ELECTRIC_FURNACE(new GenericMachineBlock(GuiType.ELECTRIC_FURNACE, ElectricFurnaceBlockEntity::new)),
|
ELECTRIC_FURNACE(new GenericMachineBlock(GuiType.ELECTRIC_FURNACE, ElectricFurnaceBlockEntity::new)),
|
||||||
|
|
Loading…
Reference in a new issue