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 team.reborn.energy.Energy;
import team.reborn.energy.EnergyTier;
import techreborn.blocks.storage.BlockEnergyStorage;
import techreborn.blocks.storage.EnergyStorageBlock;
/**
* Created by Rushmead
@ -114,7 +114,8 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
// TileMachineBase
@Override
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
@ -123,8 +124,8 @@ public class EnergyStorageBlockEntity extends PowerAcceptorBlockEntity
return null;
}
Block block = world.getBlockState(pos).getBlock();
if (block instanceof BlockEnergyStorage) {
return ((BlockEnergyStorage) block).getFacing(world.getBlockState(pos));
if (block instanceof EnergyStorageBlock) {
return ((EnergyStorageBlock) block).getFacing(world.getBlockState(pos));
}
return null;
}

View file

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

View file

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

View file

@ -46,19 +46,19 @@ import reborncore.api.blockentity.IMachineGuiHandler;
import reborncore.common.BaseBlockEntityProvider;
import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.powerSystem.PowerAcceptorBlockEntity;
import reborncore.common.util.ItemHandlerUtils;
import reborncore.common.util.WrenchUtils;
import java.util.Locale;
/**
* Created by Rushmead
*/
public abstract class BlockEnergyStorage extends BaseBlockEntityProvider {
public abstract class EnergyStorageBlock extends BaseBlockEntityProvider {
public static DirectionProperty FACING = Properties.FACING;
public String name;
public IMachineGuiHandler gui;
public BlockEnergyStorage(String name, IMachineGuiHandler gui) {
public EnergyStorageBlock(String name, IMachineGuiHandler gui) {
super(FabricBlockSettings.of(Material.METAL).strength(2f, 2f).build());
this.setDefaultState(this.getStateManager().getDefaultState().with(FACING, Direction.NORTH));
this.name = name;
@ -74,26 +74,17 @@ public abstract class BlockEnergyStorage extends BaseBlockEntityProvider {
return state.get(FACING);
}
public String getSimpleName(String fullName) {
if (fullName.equalsIgnoreCase("Batbox")) {
return "lv_storage";
// BaseBlockEntityProvider
@Override
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")) {
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);
setFacing(facing, worldIn, pos);
}
// Block
@ -102,6 +93,7 @@ public abstract class BlockEnergyStorage extends BaseBlockEntityProvider {
builder.add(FACING);
}
@SuppressWarnings("deprecation")
@Override
public ActionResult onUse(BlockState state, World worldIn, BlockPos pos, PlayerEntity playerIn, Hand hand, BlockHitResult hitResult) {
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);
}
@SuppressWarnings("deprecation")
@Override
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;
public void onBlockRemoved(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
ItemHandlerUtils.dropContainedItems(worldIn, pos);
super.onBlockRemoved(state, worldIn, pos, newState, isMoving);
}
setFacing(facing, worldIn, pos);
}
@SuppressWarnings("deprecation")
@Override
public boolean hasComparatorOutput(BlockState state) {
return true;
}
@SuppressWarnings("deprecation")
@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return PowerAcceptorBlockEntity.calculateComparatorOutputFromEnergy(world.getBlockEntity(pos));

View file

@ -32,9 +32,9 @@ import techreborn.client.EGui;
/**
* 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);
}

View file

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

View file

@ -46,9 +46,9 @@ import techreborn.blockentity.storage.lesu.LSUStorageBlockEntity;
/**
* 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());
BlockWrenchEventHandler.wrenableBlocks.add(this);
}

View file

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

View file

@ -32,9 +32,9 @@ import techreborn.blockentity.storage.LowVoltageSUBlockEntity;
/**
* 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);
}

View file

@ -32,9 +32,9 @@ import techreborn.client.EGui;
/**
* 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);
}

View file

@ -438,14 +438,14 @@ public class TRContent {
QUANTUM_CHEST(new GenericMachineBlock(EGui.QUANTUM_CHEST, QuantumChestBlockEntity::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)),
INTERDIMENSIONAL_SU(new BlockInterdimensionalSU()),
LAPOTRONIC_SU(new BlockLapotronicSU()),
LSU_STORAGE(new BlockLSUStorage()),
LOW_VOLTAGE_SU(new BlockLowVoltageSU()),
MEDIUM_VOLTAGE_SU(new BlockMediumVoltageSU()),
HIGH_VOLTAGE_SU(new BlockHighVoltageSU()),
INTERDIMENSIONAL_SU(new InterdimensionalSUBlock()),
LAPOTRONIC_SU(new LapotronicSUBlock()),
LSU_STORAGE(new LSUStorageBlock()),
LOW_VOLTAGE_SU(new LowVoltageSUBlock()),
MEDIUM_VOLTAGE_SU(new MediumVoltageSUBlock()),
HIGH_VOLTAGE_SU(new HighVoltageSUBlock()),
LV_TRANSFORMER(new BlockLVTransformer()),
MV_TRANSFORMER(new BlockMVTransformer()),
HV_TRANSFORMER(new BlockHVTransformer()),