Refactor and cleanup, awaiting new model.
This commit is contained in:
parent
55fbcb712e
commit
90c23b9d57
10 changed files with 193 additions and 138 deletions
|
@ -25,16 +25,25 @@
|
|||
package techreborn.blockentity.machine.tier1;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.block.entity.HopperBlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.Inventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.Tickable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import reborncore.api.items.InventoryBase;
|
||||
import reborncore.client.screen.BuiltScreenHandlerProvider;
|
||||
import reborncore.client.screen.builder.BuiltScreenHandler;
|
||||
import reborncore.client.screen.builder.ScreenHandlerBuilder;
|
||||
import reborncore.common.blockentity.MachineBaseBlockEntity;
|
||||
import reborncore.common.util.RebornInventory;
|
||||
import techreborn.blockentity.machine.GenericMachineBlockEntity;
|
||||
import techreborn.blockentity.machine.misc.ChargeOMatBlockEntity;
|
||||
import techreborn.blockentity.storage.item.StorageUnitBaseBlockEntity;
|
||||
import techreborn.blocks.misc.BlockRubberLog;
|
||||
import techreborn.config.TechRebornConfig;
|
||||
import techreborn.init.ModSounds;
|
||||
|
@ -42,108 +51,110 @@ import techreborn.init.TRBlockEntities;
|
|||
import techreborn.init.TRContent;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class TapperBlockEntity extends GenericMachineBlockEntity implements BuiltScreenHandlerProvider {
|
||||
import static reborncore.api.items.InventoryUtils.getInventoryAt;
|
||||
|
||||
public class TapperBlockEntity extends MachineBaseBlockEntity {
|
||||
|
||||
private static final int OUTPUT_SLOT = 0;
|
||||
|
||||
private RebornInventory<TapperBlockEntity> inventory = new RebornInventory<>(1, "TapperBlockEntity", 64, this);
|
||||
|
||||
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
|
||||
// States
|
||||
|
||||
public TapperBlockEntity() {
|
||||
super(TRBlockEntities.TAPPER, "Tapper", TechRebornConfig.tapperMaxInput, TechRebornConfig.tapperMaxEnergy, TRContent.Machine.EXTRACTOR.block, ENERGY_SLOT);
|
||||
this.inventory = new RebornInventory<>(2, "TapperBlockEntity", 64, this);
|
||||
super(TRBlockEntities.TAPPER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
super.tick();
|
||||
|
||||
if(world == null || world.isClient) return;
|
||||
|
||||
// TODO cleanup and refactor (MVP)
|
||||
HashMap<BlockPos, BlockState> rubberLogs = new HashMap<>();
|
||||
|
||||
if (world.getTime() % 100 != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
BlockPos originPos = this.pos.offset(Direction.NORTH);
|
||||
BlockState originState = world.getBlockState(originPos);
|
||||
if(originState.getBlock() != TRContent.RUBBER_LOG) return; // TODO CHECK STRUCTURE
|
||||
Inventory invBelow = getInventoryBelow();
|
||||
|
||||
rubberLogs.put(originPos, originState);
|
||||
if(originState.getBlock() != TRContent.RUBBER_LOG || invBelow == null) return;
|
||||
|
||||
HashMap<BlockPos, BlockState> sapLogs = new HashMap<>();
|
||||
|
||||
if(originState.get(BlockRubberLog.HAS_SAP)) {
|
||||
sapLogs.put(originPos, originState);
|
||||
}
|
||||
|
||||
// Get rubber logs with sap above origin
|
||||
addLogsWithSap(originPos, sapLogs);
|
||||
|
||||
// Harvest the sap to inventory, if possible.
|
||||
if(harvestSap(sapLogs, invBelow)){
|
||||
world.playSound(pos.getX(),pos.getY(),pos.getZ(), ModSounds.SAP_EXTRACT, SoundCategory.BLOCKS, 0.6F, 1F, false);
|
||||
}
|
||||
}
|
||||
|
||||
private Inventory getInventoryBelow() {
|
||||
return getInventoryAt(this.getWorld(), this.pos.offset(Direction.DOWN));
|
||||
}
|
||||
|
||||
private boolean harvestSap(HashMap<BlockPos, BlockState> sapLogs, Inventory invBelow){
|
||||
// Used for sound
|
||||
boolean hasSapped = false;
|
||||
|
||||
for (Map.Entry<BlockPos, BlockState> entry : sapLogs.entrySet()) {
|
||||
BlockPos pos = entry.getKey();
|
||||
BlockState state = entry.getValue();
|
||||
|
||||
ItemStack out = new ItemStack(TRContent.Parts.SAP, 1);
|
||||
out = HopperBlockEntity.transfer(null, invBelow, out, Direction.UP);
|
||||
if(out.isEmpty()){
|
||||
world.setBlockState(pos, state.with(BlockRubberLog.HAS_SAP, false).with(BlockRubberLog.SAP_SIDE, Direction.fromHorizontal(0)));
|
||||
hasSapped = true;
|
||||
}else{
|
||||
// Can't deposit into inventory, don't sap
|
||||
return hasSapped;
|
||||
}
|
||||
}
|
||||
|
||||
return hasSapped;
|
||||
}
|
||||
|
||||
private void addLogsWithSap(BlockPos originPos, HashMap<BlockPos, BlockState> sapLogs){
|
||||
boolean shouldExit = false;
|
||||
|
||||
BlockPos current = originPos;
|
||||
// Progress Up
|
||||
// Progress Up (Gravity fed, won't consider sap under current log), origin log has already been checked)
|
||||
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);
|
||||
if( state.get(BlockRubberLog.HAS_SAP)){
|
||||
sapLogs.put(current, state);
|
||||
}
|
||||
}else{
|
||||
shouldExit = true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
public boolean hasSlotConfig() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeUpgraded() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package techreborn.blocks.machine.tier1;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import reborncore.api.blockentity.IMachineGuiHandler;
|
||||
import techreborn.blocks.GenericMachineBlock;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class TapperBlock extends GenericMachineBlock {
|
||||
public TapperBlock(IMachineGuiHandler gui, Supplier<BlockEntity> blockEntityClass) {
|
||||
super(gui, blockEntityClass);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
return VoxelShapes.cuboid(2/16f, 0, 2/16f,14/16f,8/16f,14/16f);
|
||||
}
|
||||
}
|
|
@ -107,7 +107,7 @@ public class BlockRubberLog extends PillarBlock {
|
|||
if (state.get(HAS_SAP)) {
|
||||
return;
|
||||
}
|
||||
if (random.nextInt(50) == 0) {
|
||||
if (true) {
|
||||
Direction facing = Direction.fromHorizontal(random.nextInt(4));
|
||||
if (worldIn.getBlockState(pos.offset(Direction.DOWN, 1)).getBlock() == this
|
||||
&& worldIn.getBlockState(pos.up()).getBlock() == this) {
|
||||
|
|
|
@ -99,7 +99,6 @@ 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<ElectricFurnaceBlockEntity> ELECTRIC_FURNACE = register("electric_furnace", () -> () -> GuiElectricFurnace::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<GasTurbineBlockEntity> GAS_TURBINE = register("gas_turbine", () -> () -> GuiGasTurbine::new);
|
||||
public static final GuiType<SolidFuelGeneratorBlockEntity> GENERATOR = register("generator", () -> () -> GuiGenerator::new);
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* 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,12 +342,6 @@ 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;
|
||||
|
||||
|
|
|
@ -66,6 +66,7 @@ import techreborn.blocks.lighting.BlockLamp;
|
|||
import techreborn.blocks.machine.tier0.IronAlloyFurnaceBlock;
|
||||
import techreborn.blocks.machine.tier0.IronFurnaceBlock;
|
||||
import techreborn.blocks.machine.tier1.BlockPlayerDetector;
|
||||
import techreborn.blocks.machine.tier1.TapperBlock;
|
||||
import techreborn.blocks.misc.BlockAlarm;
|
||||
import techreborn.blocks.misc.BlockMachineCasing;
|
||||
import techreborn.blocks.misc.BlockMachineFrame;
|
||||
|
@ -520,7 +521,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)),
|
||||
TAPPER(new TapperBlock(null, 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)),
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"variants": {
|
||||
"": { "model": "techreborn:block/machines/tier1_machines/tapper" }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,78 @@
|
|||
{
|
||||
"credit": "Made with Blockbench",
|
||||
"textures": {
|
||||
"0": "techreborn:block/machines/tier0_machines/machine_side",
|
||||
"1": "techreborn:block/machines/tier0_machines/fluid_drain_top",
|
||||
"2": "techreborn:block/machines/tier0_machines/basic_unit_bottom",
|
||||
"3": "techreborn:block/machines/tier0_machines/crude_storage_unit_bottom",
|
||||
"particle": "techreborn:block/machines/tier0_machines/machine_side"
|
||||
},
|
||||
"elements": [
|
||||
{
|
||||
"from": [7, 11, -2],
|
||||
"to": [9, 13, 6],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [16, 13, -10]},
|
||||
"faces": {
|
||||
"north": {"uv": [4, 4, 6, 6], "texture": "#3"},
|
||||
"east": {"uv": [4, 4, 12, 6], "texture": "#3"},
|
||||
"south": {"uv": [4, 4, 6, 6], "texture": "#3"},
|
||||
"west": {"uv": [4, 4, 12, 6], "texture": "#3"},
|
||||
"up": {"uv": [4, 4, 6, 12], "texture": "#3"},
|
||||
"down": {"uv": [4, 4, 6, 12], "texture": "#3"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [6, 8, 6],
|
||||
"to": [10, 13, 10],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [14, 13, 15]},
|
||||
"faces": {
|
||||
"north": {"uv": [4, 4, 9, 9], "texture": "#3"},
|
||||
"east": {"uv": [4, 4, 9, 9], "texture": "#3"},
|
||||
"south": {"uv": [4, 4, 9, 9], "texture": "#3"},
|
||||
"west": {"uv": [4, 4, 9, 9], "texture": "#3"},
|
||||
"up": {"uv": [4, 4, 9, 9], "texture": "#3"},
|
||||
"down": {"uv": [4, 4, 9, 9], "texture": "#3"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [2, 0, 2],
|
||||
"to": [14, 8, 14],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [14, 8, 12]},
|
||||
"faces": {
|
||||
"north": {"uv": [0, 0, 16, 16], "texture": "#0"},
|
||||
"east": {"uv": [0, 0, 16, 16], "texture": "#0"},
|
||||
"south": {"uv": [0, 0, 16, 16], "texture": "#0"},
|
||||
"west": {"uv": [0, 0, 16, 16], "texture": "#0"},
|
||||
"up": {"uv": [0, 0, 16, 16], "texture": "#1"},
|
||||
"down": {"uv": [0, 0, 16, 16], "texture": "#2"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [5, 13, 7],
|
||||
"to": [11, 14, 9],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [16, 13, -2]},
|
||||
"faces": {
|
||||
"north": {"uv": [4, 2, 10, 3], "texture": "#0"},
|
||||
"east": {"uv": [4, 2, 6, 3], "texture": "#0"},
|
||||
"south": {"uv": [4, 2, 10, 3], "texture": "#0"},
|
||||
"west": {"uv": [4, 2, 6, 3], "texture": "#0"},
|
||||
"up": {"uv": [4, 2, 10, 4], "texture": "#0"},
|
||||
"down": {"uv": [4, 2, 10, 4], "texture": "#0"}
|
||||
}
|
||||
},
|
||||
{
|
||||
"from": [7, 13, 5],
|
||||
"to": [9, 14, 11],
|
||||
"rotation": {"angle": 0, "axis": "y", "origin": [16, 13, -2]},
|
||||
"faces": {
|
||||
"north": {"uv": [4, 2, 11, 4], "texture": "#0"},
|
||||
"east": {"uv": [4, 2, 11, 4], "texture": "#0"},
|
||||
"south": {"uv": [4, 2, 11, 4], "texture": "#0"},
|
||||
"west": {"uv": [4, 2, 11, 4], "texture": "#0"},
|
||||
"up": {"uv": [4, 2, 11, 4], "texture": "#0"},
|
||||
"down": {"uv": [4, 2, 11, 4], "texture": "#0"}
|
||||
}
|
||||
}
|
||||
],
|
||||
"display": {}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"parent": "techreborn:block/machines/tier1_machines/tapper"
|
||||
}
|
Loading…
Reference in a new issue