mirror of
https://github.com/XevianLight/Aphelion.git
synced 2026-05-11 10:00:54 +01:00
Multiblocks now use dummy blocks. BaseMultiblockDummyBlock created for all dummies to extend from.
This commit is contained in:
@@ -9,6 +9,7 @@ import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseEntityBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
@@ -19,10 +20,11 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.StateDefinition;
|
||||
import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.xevianlight.aphelion.block.dummy.BaseMultiblockDummyBlock;
|
||||
import net.xevianlight.aphelion.block.entity.custom.EAFPartEntity;
|
||||
import net.xevianlight.aphelion.block.entity.custom.ElectricArcFurnaceEntity;
|
||||
import net.xevianlight.aphelion.block.entity.custom.VacuumArcFurnaceControllerEntity;
|
||||
import net.xevianlight.aphelion.util.AphelionBlockStateProperties;
|
||||
import net.xevianlight.aphelion.util.IMultiblockController;
|
||||
import net.xevianlight.aphelion.util.MultiblockHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -44,7 +46,7 @@ public class ArcFurnaceCasingBlock extends BaseEntityBlock {
|
||||
public static Properties getProperties() {
|
||||
return Properties
|
||||
.of()
|
||||
.sound(SoundType.ANVIL)
|
||||
.sound(SoundType.NETHERITE_BLOCK)
|
||||
.destroyTime(2f)
|
||||
.explosionResistance(10f)
|
||||
.requiresCorrectToolForDrops();
|
||||
@@ -66,6 +68,12 @@ public class ArcFurnaceCasingBlock extends BaseEntityBlock {
|
||||
// return new EAFPartEntity(blockPos, blockState);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
|
||||
super.onPlace(state, level, pos, oldState, movedByPiston);
|
||||
if (!level.isClientSide()) pingNearbyController(level, pos);
|
||||
}
|
||||
|
||||
private void pingNearbyController(Level level, BlockPos pos) {
|
||||
int r = 5;
|
||||
BlockPos.MutableBlockPos mp = new BlockPos.MutableBlockPos();
|
||||
@@ -75,39 +83,17 @@ public class ArcFurnaceCasingBlock extends BaseEntityBlock {
|
||||
for (int dz=-r; dz<=r; dz++) {
|
||||
mp.set(pos.getX()+dx, pos.getY()+dy, pos.getZ()+dz);
|
||||
BlockEntity be = level.getBlockEntity(mp);
|
||||
if (be instanceof VacuumArcFurnaceControllerEntity vaf) {
|
||||
if (level.getBlockState(vaf.getBlockPos()).getBlock() instanceof VacuumArcFurnaceController) {
|
||||
MultiblockHelper.tryForm(level, vaf.getBlockState(), vaf.getBlockPos(), VacuumArcFurnaceControllerEntity.SHAPE, AphelionBlockStateProperties.FORMED);
|
||||
}
|
||||
if (be instanceof IMultiblockController controller) {
|
||||
controller.markDirty();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult result) {
|
||||
if (state.getValue(AphelionBlockStateProperties.FORMED)) {
|
||||
if (!level.isClientSide && player instanceof ServerPlayer serverPlayer && level.getBlockEntity(pos) instanceof EAFPartEntity eafPartEntity) {
|
||||
if (eafPartEntity.getControllerPos() != null)
|
||||
if (level.getBlockEntity(eafPartEntity.getControllerPos()) instanceof VacuumArcFurnaceControllerEntity)
|
||||
serverPlayer.openMenu(new SimpleMenuProvider((VacuumArcFurnaceControllerEntity) level.getBlockEntity(eafPartEntity.getControllerPos()), Component.literal("Vacuum Arc Furnace")), eafPartEntity.getControllerPos());
|
||||
}
|
||||
return InteractionResult.sidedSuccess(level.isClientSide);
|
||||
}
|
||||
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
|
||||
super.onPlace(state, level, pos, oldState, movedByPiston);
|
||||
if (!level.isClientSide()) pingNearbyController(level, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
|
||||
if (!level.isClientSide() && state.getBlock() != newState.getBlock()) {
|
||||
if (!level.isClientSide() && state.getBlock() != newState.getBlock())
|
||||
pingNearbyController(level, pos);
|
||||
}
|
||||
super.onRemove(state, level, pos, newState, movedByPiston);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user