Energy storage should drop inventory. Closes #1919

This commit is contained in:
drcrazy 2019-12-23 13:06:18 +03:00
parent 2afca5534b
commit 6dc1124bc6
11 changed files with 50 additions and 59 deletions

View file

@ -35,7 +35,7 @@ import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.RebornInventory; import reborncore.common.util.RebornInventory;
import team.reborn.energy.Energy; import team.reborn.energy.Energy;
import team.reborn.energy.EnergyTier; import team.reborn.energy.EnergyTier;
import techreborn.blocks.storage.BlockEnergyStorage; import techreborn.blocks.storage.EnergyStorageBlock;
/** /**
* Created by Rushmead * Created by Rushmead
@ -114,7 +114,8 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
// TileMachineBase // TileMachineBase
@Override @Override
public void setFacing(Direction enumFacing) { public void setFacing(Direction enumFacing) {
world.setBlockState(pos, world.getBlockState(pos).with(BlockEnergyStorage.FACING, enumFacing)); if (world == null) { return; }
world.setBlockState(pos, world.getBlockState(pos).with(EnergyStorageBlock.FACING, enumFacing));
} }
@Override @Override
@ -123,8 +124,8 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
return null; return null;
} }
Block block = world.getBlockState(pos).getBlock(); Block block = world.getBlockState(pos).getBlock();
if (block instanceof BlockEnergyStorage) { if (block instanceof EnergyStorageBlock) {
return ((BlockEnergyStorage) block).getFacing(world.getBlockState(pos)); return ((EnergyStorageBlock) block).getFacing(world.getBlockState(pos));
} }
return null; return null;
} }

View file

@ -34,7 +34,7 @@ import reborncore.client.containerBuilder.builder.BuiltContainer;
import reborncore.client.containerBuilder.builder.ContainerBuilder; import reborncore.client.containerBuilder.builder.ContainerBuilder;
import team.reborn.energy.EnergyTier; import team.reborn.energy.EnergyTier;
import techreborn.blockentity.storage.EnergyStorageBlockEntity; import techreborn.blockentity.storage.EnergyStorageBlockEntity;
import techreborn.blocks.storage.BlockLapotronicSU; import techreborn.blocks.storage.LapotronicSUBlock;
import techreborn.config.TechRebornConfig; import techreborn.config.TechRebornConfig;
import techreborn.init.TRBlockEntities; import techreborn.init.TRBlockEntities;
import techreborn.init.TRContent; import techreborn.init.TRContent;
@ -87,8 +87,8 @@ public class LapotronicSUBlockEntity extends EnergyStorageBlockEntity implements
@Override @Override
public Direction getFacingEnum() { public Direction getFacingEnum() {
Block block = world.getBlockState(pos).getBlock(); Block block = world.getBlockState(pos).getBlock();
if (block instanceof BlockLapotronicSU) { if (block instanceof LapotronicSUBlock) {
return ((BlockLapotronicSU) block).getFacing(world.getBlockState(pos)); return ((LapotronicSUBlock) block).getFacing(world.getBlockState(pos));
} }
return null; return null;
} }

View file

@ -29,9 +29,9 @@ import net.minecraft.world.BlockView;
import techreborn.blockentity.storage.AdjustableSUBlockEntity; import techreborn.blockentity.storage.AdjustableSUBlockEntity;
import techreborn.client.EGui; import techreborn.client.EGui;
public class BlockAdjustableSU extends BlockEnergyStorage { public class AdjustableSUBlock extends EnergyStorageBlock {
public BlockAdjustableSU() { public AdjustableSUBlock() {
super("AESU", EGui.AESU); super("AESU", EGui.AESU);
} }

View file

@ -46,19 +46,19 @@ import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.common.BaseBlockEntityProvider; import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.blocks.BlockWrenchEventHandler; import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity; import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.ItemHandlerUtils;
import reborncore.common.util.WrenchUtils; import reborncore.common.util.WrenchUtils;
import java.util.Locale;
/** /**
* Created by Rushmead * Created by Rushmead
*/ */
public abstract class BlockEnergyStorage extends BaseBlockEntityProvider { public abstract class EnergyStorageBlock extends BaseBlockEntityProvider {
public static DirectionProperty FACING = Properties.FACING; public static DirectionProperty FACING = Properties.FACING;
public String name; public String name;
public IMachineGuiHandler gui; public IMachineGuiHandler gui;
public BlockEnergyStorage(String name, IMachineGuiHandler gui) { public EnergyStorageBlock(String name, IMachineGuiHandler gui) {
super(FabricBlockSettings.of(Material.METAL).strength(2f, 2f).build()); super(FabricBlockSettings.of(Material.METAL).strength(2f, 2f).build());
this.setDefaultState(this.getStateManager().getDefaultState().with(FACING, Direction.NORTH)); this.setDefaultState(this.getStateManager().getDefaultState().with(FACING, Direction.NORTH));
this.name = name; this.name = name;
@ -74,26 +74,17 @@ public abstract class BlockEnergyStorage extends BaseBlockEntityProvider {
return state.get(FACING); return state.get(FACING);
} }
public String getSimpleName(String fullName) { // BaseBlockEntityProvider
if (fullName.equalsIgnoreCase("Batbox")) { @Override
return "lv_storage"; public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
super.onPlaced(worldIn, pos, state, placer, stack);
Direction facing = placer.getHorizontalFacing().getOpposite();
if (placer.pitch < -50) {
facing = Direction.DOWN;
} else if (placer.pitch > 50) {
facing = Direction.UP;
} }
if (fullName.equalsIgnoreCase("MEDIUM_VOLTAGE_SU")) { setFacing(facing, worldIn, pos);
return "mv_storage";
}
if (fullName.equalsIgnoreCase("HIGH_VOLTAGE_SU")) {
return "hv_storage";
}
if (fullName.equalsIgnoreCase("AESU")) {
return "ev_storage_adjust";
}
if (fullName.equalsIgnoreCase("IDSU")) {
return "ev_storage_transmitter";
}
if (fullName.equalsIgnoreCase("LESU")) {
return "ev_multi";
}
return fullName.toLowerCase(Locale.ROOT);
} }
// Block // Block
@ -102,6 +93,7 @@ public abstract class BlockEnergyStorage extends BaseBlockEntityProvider {
builder.add(FACING); builder.add(FACING);
} }
@SuppressWarnings("deprecation")
@Override @Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) { public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
ItemStack stack = playerIn.getStackInHand(Hand.MAIN_HAND); ItemStack stack = playerIn.getStackInHand(Hand.MAIN_HAND);
@ -126,24 +118,22 @@ public abstract class BlockEnergyStorage extends BaseBlockEntityProvider {
return super.onUse(state, worldIn, pos, playerIn, hand, hitResult); return super.onUse(state, worldIn, pos, playerIn, hand, hitResult);
} }
@SuppressWarnings("deprecation")
@Override @Override
public void onPlaced(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, public void onBlockRemoved(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
ItemStack stack) { if (state.getBlock() != newState.getBlock()) {
super.onPlaced(worldIn, pos, state, placer, stack); ItemHandlerUtils.dropContainedItems(worldIn, pos);
Direction facing = placer.getHorizontalFacing().getOpposite(); super.onBlockRemoved(state, worldIn, pos, newState, isMoving);
if (placer.pitch < -50) {
facing = Direction.DOWN;
} else if (placer.pitch > 50) {
facing = Direction.UP;
} }
setFacing(facing, worldIn, pos);
} }
@SuppressWarnings("deprecation")
@Override @Override
public boolean hasComparatorOutput(BlockState state) { public boolean hasComparatorOutput(BlockState state) {
return true; return true;
} }
@SuppressWarnings("deprecation")
@Override @Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) { public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return PowerAcceptorBlockEntity.calculateComparatorOutputFromEnergy(world.getBlockEntity(pos)); return PowerAcceptorBlockEntity.calculateComparatorOutputFromEnergy(world.getBlockEntity(pos));

View file

@ -32,9 +32,9 @@ import techreborn.client.EGui;
/** /**
* Created by modmuss50 on 14/03/2016. * Created by modmuss50 on 14/03/2016.
*/ */
public class BlockHighVoltageSU extends BlockEnergyStorage { public class HighVoltageSUBlock extends EnergyStorageBlock {
public BlockHighVoltageSU() { public HighVoltageSUBlock() {
super("high_voltage_su", EGui.HIGH_VOLTAGE_SU); super("high_voltage_su", EGui.HIGH_VOLTAGE_SU);
} }

View file

@ -35,9 +35,9 @@ import net.minecraft.world.World;
import techreborn.blockentity.storage.idsu.InterdimensionalSUBlockEntity; import techreborn.blockentity.storage.idsu.InterdimensionalSUBlockEntity;
import techreborn.client.EGui; import techreborn.client.EGui;
public class BlockInterdimensionalSU extends BlockEnergyStorage { public class InterdimensionalSUBlock extends EnergyStorageBlock {
public BlockInterdimensionalSU() { public InterdimensionalSUBlock() {
super("IDSU", EGui.IDSU); super("IDSU", EGui.IDSU);
} }

View file

@ -46,9 +46,9 @@ import techreborn.blockentity.storage.lesu.LSUStorageBlockEntity;
/** /**
* Energy storage block for LESU * Energy storage block for LESU
*/ */
public class BlockLSUStorage extends BaseBlockEntityProvider { public class LSUStorageBlock extends BaseBlockEntityProvider {
public BlockLSUStorage() { public LSUStorageBlock() {
super(FabricBlockSettings.of(Material.METAL).strength(2f, 2f).build()); super(FabricBlockSettings.of(Material.METAL).strength(2f, 2f).build());
BlockWrenchEventHandler.wrenableBlocks.add(this); BlockWrenchEventHandler.wrenableBlocks.add(this);
} }

View file

@ -29,9 +29,9 @@ import net.minecraft.world.BlockView;
import techreborn.blockentity.storage.lesu.LapotronicSUBlockEntity; import techreborn.blockentity.storage.lesu.LapotronicSUBlockEntity;
import techreborn.client.EGui; import techreborn.client.EGui;
public class BlockLapotronicSU extends BlockEnergyStorage { public class LapotronicSUBlock extends EnergyStorageBlock {
public BlockLapotronicSU() { public LapotronicSUBlock() {
super("LESU", EGui.LESU); super("LESU", EGui.LESU);
} }

View file

@ -32,9 +32,9 @@ import techreborn.blockentity.storage.LowVoltageSUBlockEntity;
/** /**
* Created by modmuss50 on 14/03/2016. * Created by modmuss50 on 14/03/2016.
*/ */
public class BlockLowVoltageSU extends BlockEnergyStorage { public class LowVoltageSUBlock extends EnergyStorageBlock {
public BlockLowVoltageSU() { public LowVoltageSUBlock() {
super("low_voltage_su", EGui.LOW_VOLTAGE_SU); super("low_voltage_su", EGui.LOW_VOLTAGE_SU);
} }

View file

@ -32,9 +32,9 @@ import techreborn.client.EGui;
/** /**
* Created by modmuss50 on 14/03/2016. * Created by modmuss50 on 14/03/2016.
*/ */
public class BlockMediumVoltageSU extends BlockEnergyStorage { public class MediumVoltageSUBlock extends EnergyStorageBlock {
public BlockMediumVoltageSU() { public MediumVoltageSUBlock() {
super("medium_voltage_su", EGui.MEDIUM_VOLTAGE_SU); super("medium_voltage_su", EGui.MEDIUM_VOLTAGE_SU);
} }

View file

@ -438,14 +438,14 @@ public class TRContent {
QUANTUM_CHEST(new GenericMachineBlock(EGui.QUANTUM_CHEST, QuantumChestBlockEntity::new)), QUANTUM_CHEST(new GenericMachineBlock(EGui.QUANTUM_CHEST, QuantumChestBlockEntity::new)),
QUANTUM_TANK(new GenericMachineBlock(EGui.QUANTUM_TANK, QuantumTankBlockEntity::new)), QUANTUM_TANK(new GenericMachineBlock(EGui.QUANTUM_TANK, QuantumTankBlockEntity::new)),
ADJUSTABLE_SU(new BlockAdjustableSU()), ADJUSTABLE_SU(new AdjustableSUBlock()),
CHARGE_O_MAT(new GenericMachineBlock(EGui.CHARGEBENCH, ChargeOMatBlockEntity::new)), CHARGE_O_MAT(new GenericMachineBlock(EGui.CHARGEBENCH, ChargeOMatBlockEntity::new)),
INTERDIMENSIONAL_SU(new BlockInterdimensionalSU()), INTERDIMENSIONAL_SU(new InterdimensionalSUBlock()),
LAPOTRONIC_SU(new BlockLapotronicSU()), LAPOTRONIC_SU(new LapotronicSUBlock()),
LSU_STORAGE(new BlockLSUStorage()), LSU_STORAGE(new LSUStorageBlock()),
LOW_VOLTAGE_SU(new BlockLowVoltageSU()), LOW_VOLTAGE_SU(new LowVoltageSUBlock()),
MEDIUM_VOLTAGE_SU(new BlockMediumVoltageSU()), MEDIUM_VOLTAGE_SU(new MediumVoltageSUBlock()),
HIGH_VOLTAGE_SU(new BlockHighVoltageSU()), HIGH_VOLTAGE_SU(new HighVoltageSUBlock()),
LV_TRANSFORMER(new BlockLVTransformer()), LV_TRANSFORMER(new BlockLVTransformer()),
MV_TRANSFORMER(new BlockMVTransformer()), MV_TRANSFORMER(new BlockMVTransformer()),
HV_TRANSFORMER(new BlockHVTransformer()), HV_TRANSFORMER(new BlockHVTransformer()),