mirror of
https://github.com/XevianLight/Aphelion.git
synced 2026-05-11 01:50:56 +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);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,9 +25,11 @@ import net.minecraft.world.level.block.state.properties.BooleanProperty;
|
||||
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
import net.xevianlight.aphelion.block.entity.custom.ElectricArcFurnaceEntity;
|
||||
import net.xevianlight.aphelion.block.entity.custom.VacuumArcFurnaceControllerEntity;
|
||||
import net.xevianlight.aphelion.core.init.ModBlockEntities;
|
||||
import net.xevianlight.aphelion.util.AphelionBlockStateProperties;
|
||||
import net.xevianlight.aphelion.util.IMultiblockController;
|
||||
import net.xevianlight.aphelion.util.MultiblockHelper;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -43,6 +45,8 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
|
||||
public VacuumArcFurnaceController(Properties properties) {
|
||||
super(properties);
|
||||
this.registerDefaultState(this.getStateDefinition().any()
|
||||
.setValue(FACING, Direction.NORTH)
|
||||
.setValue(LIT, false)
|
||||
.setValue(FORMED, false));
|
||||
}
|
||||
|
||||
@@ -61,7 +65,7 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
|
||||
public static Properties getProperties() {
|
||||
return Properties
|
||||
.of()
|
||||
.sound(SoundType.METAL)
|
||||
.sound(SoundType.NETHERITE_BLOCK)
|
||||
.destroyTime(2f)
|
||||
.explosionResistance(10f)
|
||||
.requiresCorrectToolForDrops();
|
||||
@@ -73,7 +77,6 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
|
||||
|
||||
@Override
|
||||
public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult result) {
|
||||
|
||||
if (!level.isClientSide && player instanceof ServerPlayer serverPlayer && level.getBlockEntity(pos) instanceof VacuumArcFurnaceControllerEntity vacuumArcFurnaceEntity) {
|
||||
if (vacuumArcFurnaceEntity.isFormed())
|
||||
serverPlayer.openMenu(new SimpleMenuProvider(vacuumArcFurnaceEntity, Component.literal("Vacuum Arc Furnace")), pos);
|
||||
@@ -110,8 +113,8 @@ public class VacuumArcFurnaceController extends BaseEntityBlock {
|
||||
super.onPlace(state, level, pos, oldState, movedByPiston);
|
||||
if (!level.isClientSide() && oldState.getBlock() != state.getBlock()) {
|
||||
BlockEntity blockEntity= level.getBlockEntity(pos);
|
||||
if (blockEntity instanceof VacuumArcFurnaceControllerEntity vacuumArcFurnaceEntity) {
|
||||
MultiblockHelper.tryForm(level, state, pos, vacuumArcFurnaceEntity.SHAPE, AphelionBlockStateProperties.FORMED);
|
||||
if (blockEntity instanceof IMultiblockController mbController) {
|
||||
mbController.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
package net.xevianlight.aphelion.block.dummy;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.ItemInteractionResult;
|
||||
import net.minecraft.world.SimpleMenuProvider;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.inventory.MenuConstructor;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
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.Blocks;
|
||||
import net.minecraft.world.level.block.RenderShape;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.xevianlight.aphelion.util.IMultiblockController;
|
||||
import net.xevianlight.aphelion.util.IMultiblockPart;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BaseMultiblockDummyBlock extends BaseEntityBlock {
|
||||
|
||||
public static final MapCodec<BaseMultiblockDummyBlock> CODEC = simpleCodec(BaseMultiblockDummyBlock::new);
|
||||
|
||||
public BaseMultiblockDummyBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected MapCodec<? extends BaseEntityBlock> codec() {
|
||||
return CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Item.Properties getItemProperties() {
|
||||
return new Item.Properties();
|
||||
}
|
||||
|
||||
public static Properties getProperties() {
|
||||
return Properties
|
||||
.of()
|
||||
.sound(SoundType.NETHERITE_BLOCK)
|
||||
.destroyTime(2f)
|
||||
.explosionResistance(10f)
|
||||
.requiresCorrectToolForDrops();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected RenderShape getRenderShape(BlockState state) {
|
||||
return RenderShape.INVISIBLE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getLightBlock(BlockState state, BlockGetter level, BlockPos pos) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean propagatesSkylightDown(BlockState state, BlockGetter level, BlockPos pos) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private void pingNearbyController(Level level, BlockPos pos) {
|
||||
int r = 5;
|
||||
BlockPos.MutableBlockPos mp = new BlockPos.MutableBlockPos();
|
||||
|
||||
for (int dx=-r; dx<=r; dx++)
|
||||
for (int dy=-r; dy<=r; dy++)
|
||||
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 IMultiblockController controller) {
|
||||
controller.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult result) {
|
||||
// if (!level.isClientSide && player instanceof ServerPlayer serverPlayer) {
|
||||
// if (level.getBlockEntity(pos) instanceof IMultiblockPart multiblockPartEntity) {
|
||||
//// if (multiblockPartEntity.getControllerPos() != null) {
|
||||
// if (level.getBlockEntity(multiblockPartEntity.getControllerPos()) instanceof IMultiblockController controller)
|
||||
// serverPlayer.openMenu(new SimpleMenuProvider((MenuConstructor) level.getBlockEntity(multiblockPartEntity.getControllerPos()), Component.literal(controller.getMenuTitle())), multiblockPartEntity.getControllerPos());
|
||||
//// } else {
|
||||
//// if (level.getBlockEntity(pos) instanceof IMultiblockPart mbp) {
|
||||
//// level.setBlock(pos, mbp.getMimicing(), UPDATE_ALL);
|
||||
//// } else {
|
||||
//// level.setBlock(pos, Blocks.AIR.defaultBlockState(), UPDATE_ALL);
|
||||
//// }
|
||||
//// }
|
||||
// return InteractionResult.sidedSuccess(level.isClientSide);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return InteractionResult.FAIL;
|
||||
// }
|
||||
|
||||
|
||||
@Override
|
||||
public InteractionResult useWithoutItem(BlockState state, Level level, BlockPos pos, Player player, BlockHitResult result) {
|
||||
|
||||
if (!level.isClientSide && player instanceof ServerPlayer serverPlayer) {
|
||||
if (level.getBlockEntity(pos) instanceof IMultiblockPart mbPartEntity) {
|
||||
if (mbPartEntity.getControllerPos() != null) {
|
||||
if (level.getBlockEntity(mbPartEntity.getControllerPos()) instanceof IMultiblockController controller) {
|
||||
serverPlayer.openMenu(new SimpleMenuProvider((MenuConstructor) level.getBlockEntity(mbPartEntity.getControllerPos()), Component.literal(controller.getMenuTitle())), mbPartEntity.getControllerPos());
|
||||
return InteractionResult.sidedSuccess(level.isClientSide);
|
||||
}
|
||||
} else {
|
||||
if (level.getBlockEntity(pos) instanceof IMultiblockPart mbp) {
|
||||
level.setBlock(pos, mbp.getMimicing(), UPDATE_ALL);
|
||||
} else {
|
||||
level.setBlock(pos, Blocks.AIR.defaultBlockState(), UPDATE_ALL);
|
||||
}
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
return InteractionResult.FAIL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemInteractionResult useItemOn(ItemStack stack, BlockState state, Level level, BlockPos pos,
|
||||
Player player, InteractionHand hand, BlockHitResult hit) {
|
||||
// Always handle dummy interaction, even with an item in hand
|
||||
if (!level.isClientSide && player instanceof ServerPlayer serverPlayer
|
||||
&& level.getBlockEntity(pos) instanceof IMultiblockPart part) {
|
||||
|
||||
if (part.getControllerPos() != null) {
|
||||
BlockEntity cbe = level.getBlockEntity(part.getControllerPos());
|
||||
if (cbe instanceof IMultiblockController controller) {
|
||||
serverPlayer.openMenu(
|
||||
new SimpleMenuProvider((MenuConstructor) cbe, Component.literal(controller.getMenuTitle())),
|
||||
part.getControllerPos()
|
||||
);
|
||||
}
|
||||
} else {
|
||||
level.setBlock(pos, part.getMimicing() != null ? part.getMimicing() : Blocks.AIR.defaultBlockState(), UPDATE_ALL);
|
||||
}
|
||||
|
||||
return ItemInteractionResult.CONSUME; // <- prevents item use/placement
|
||||
}
|
||||
|
||||
return ItemInteractionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPlace(BlockState state, Level level, BlockPos pos, BlockState oldState, boolean movedByPiston) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean movedByPiston) {
|
||||
if (!level.isClientSide() && state.getBlock() != newState.getBlock()) {
|
||||
if (level.getBlockEntity(pos) instanceof IMultiblockPart mbPart)
|
||||
mbPart.onDummyBroken();
|
||||
}
|
||||
// super.onRemove(state, level, pos, newState, movedByPiston);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package net.xevianlight.aphelion.block.dummy;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.xevianlight.aphelion.block.dummy.entity.VAFMultiblockDummyBlockEntity;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class VAFMultiblockDummyBlock extends BaseMultiblockDummyBlock {
|
||||
public VAFMultiblockDummyBlock(Properties properties) {
|
||||
super(properties);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
|
||||
return new VAFMultiblockDummyBlockEntity(blockPos, blockState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
package net.xevianlight.aphelion.block.dummy.entity;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.NbtUtils;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.energy.IEnergyStorage;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
import net.neoforged.neoforge.items.ItemStackHandler;
|
||||
import net.xevianlight.aphelion.Aphelion;
|
||||
import net.xevianlight.aphelion.block.entity.energy.ModEnergyStorage;
|
||||
import net.xevianlight.aphelion.core.init.ModBlockEntities;
|
||||
import net.xevianlight.aphelion.util.IMultiblockController;
|
||||
import net.xevianlight.aphelion.util.IMultiblockPart;
|
||||
import net.xevianlight.aphelion.util.SidedSlotHandler;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class BaseMultiblockDummyBlockEntity extends BlockEntity implements IMultiblockPart {
|
||||
@Nullable private BlockPos controllerPos;
|
||||
private BlockState mimicing = Blocks.AIR.defaultBlockState();
|
||||
|
||||
@Nullable
|
||||
private ItemStackHandler getControllerInventory() {
|
||||
if (level == null) return null;
|
||||
|
||||
BlockPos cPos = getControllerPos();
|
||||
if (cPos == null) return null;
|
||||
|
||||
BlockEntity be = level.getBlockEntity(cPos);
|
||||
if (be instanceof IMultiblockController controller) {
|
||||
return controller.getInventory();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IItemHandler getItemHandler(@Nullable Direction direction) {
|
||||
ItemStackHandler inv = getControllerInventory();
|
||||
if (inv == null) return new ItemStackHandler(0); // or null, depending on your needs
|
||||
|
||||
// IMPORTANT: your indices are almost certainly 0..3, not 1..4
|
||||
return new SidedSlotHandler(inv, new int[]{0,1,2,3}, true, true);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ModEnergyStorage getControllerEnergy() {
|
||||
if (level == null) return null;
|
||||
|
||||
BlockPos cPos = getControllerPos();
|
||||
if (cPos == null) return null;
|
||||
|
||||
BlockEntity be = level.getBlockEntity(cPos);
|
||||
if (be instanceof IMultiblockController controller) {
|
||||
return controller.getEnergy();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public IEnergyStorage getEnergyStorage(@Nullable Direction direction) {
|
||||
ModEnergyStorage nrg = getControllerEnergy();
|
||||
if (nrg == null) return new ModEnergyStorage(0, 0) {
|
||||
@Override
|
||||
public void onEnergyChanged() {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
return nrg;
|
||||
}
|
||||
|
||||
// public IEnergyStorage getEnergyStorage(@Nullable Direction direction) {
|
||||
// if (direction == null)
|
||||
// return isFormed() ? ENERGY_STORAGE : NULL_ENERGY_STORAGE;
|
||||
// return isFormed() ? ENERGY_STORAGE : null;
|
||||
// }
|
||||
|
||||
public BaseMultiblockDummyBlockEntity(BlockEntityType<?> type, BlockPos pos, BlockState blockState) {
|
||||
super(type, pos, blockState);
|
||||
}
|
||||
|
||||
public void setControllerPos(@Nullable BlockPos pos) {
|
||||
controllerPos = pos;
|
||||
setChanged();
|
||||
if (level != null) {
|
||||
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 3);
|
||||
invalidateCapabilities();
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable BlockPos getControllerPos() {
|
||||
return controllerPos;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDummyBroken() {
|
||||
if (level == null || level.isClientSide) return;
|
||||
|
||||
if (controllerPos == null) {
|
||||
level.setBlock(getBlockPos(), getMimicing(), Block.UPDATE_ALL);
|
||||
return;
|
||||
}
|
||||
|
||||
BlockEntity be = level.getBlockEntity(controllerPos);
|
||||
if (be instanceof IMultiblockController controller) {
|
||||
controller.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.saveAdditional(tag, registries);
|
||||
if (controllerPos != null) tag.putLong("controller", controllerPos.asLong());
|
||||
tag.put("mimic", NbtUtils.writeBlockState(mimicing));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadAdditional(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
super.loadAdditional(tag, registries);
|
||||
controllerPos = tag.contains("controller") ? BlockPos.of(tag.getLong("controller")) : null;
|
||||
if (tag.contains("mimic")) {
|
||||
// Depending on your version, this line may need the registry lookup variant.
|
||||
setMimicing(NbtUtils.readBlockState(registries.lookupOrThrow(net.minecraft.core.registries.Registries.BLOCK), tag.getCompound("mimic")));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDataPacket(net.minecraft.network.Connection net,
|
||||
ClientboundBlockEntityDataPacket pkt,
|
||||
HolderLookup.Provider registries) {
|
||||
|
||||
CompoundTag tag = pkt.getTag();
|
||||
if (tag != null) {
|
||||
loadAdditional(tag, registries);
|
||||
}
|
||||
|
||||
// Force rerender on client
|
||||
if (level != null) {
|
||||
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 3);
|
||||
requestModelDataUpdate(); // if you rely on model data
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientboundBlockEntityDataPacket getUpdatePacket() {
|
||||
return ClientboundBlockEntityDataPacket.create(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getUpdateTag(HolderLookup.Provider registries) {
|
||||
CompoundTag tag = new CompoundTag();
|
||||
saveAdditional(tag, registries);
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleUpdateTag(CompoundTag tag, HolderLookup.Provider registries) {
|
||||
loadAdditional(tag, registries);
|
||||
|
||||
// CLIENT: force rerender
|
||||
if (level != null) {
|
||||
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), Block.UPDATE_ALL);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getMimicing() {
|
||||
return mimicing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMimicing(BlockState newState) {
|
||||
mimicing = newState;
|
||||
setChanged();
|
||||
if (level != null) {
|
||||
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), 3);
|
||||
requestModelDataUpdate(); // only if you use model data
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package net.xevianlight.aphelion.block.dummy.entity;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.xevianlight.aphelion.core.init.ModBlockEntities;
|
||||
|
||||
public class VAFMultiblockDummyBlockEntity extends BaseMultiblockDummyBlockEntity {
|
||||
public VAFMultiblockDummyBlockEntity(BlockPos pos, BlockState blockState) {
|
||||
super(ModBlockEntities.VAF_MULTIBLOCK_DUMMY_ENTITY.get(), pos, blockState);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package net.xevianlight.aphelion.block.dummy.renderer;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.LightTexture;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.RenderType;
|
||||
import net.minecraft.client.renderer.block.BlockRenderDispatcher;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.LightLayer;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.neoforged.neoforge.client.model.data.ModelData;
|
||||
import net.xevianlight.aphelion.block.dummy.entity.BaseMultiblockDummyBlockEntity;
|
||||
import net.xevianlight.aphelion.block.entity.custom.EAFPartEntity;
|
||||
|
||||
public class MultiblockDummyRenderer implements BlockEntityRenderer<BaseMultiblockDummyBlockEntity> {
|
||||
|
||||
public MultiblockDummyRenderer(BlockEntityRendererProvider.Context context) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render(BaseMultiblockDummyBlockEntity be, float partialTick, PoseStack poseStack,
|
||||
MultiBufferSource buffer, int packedLight, int packedOverlay) {
|
||||
|
||||
Level level = be.getLevel();
|
||||
if (level == null) return;
|
||||
|
||||
BlockState mimic = be.getMimicing(); // <-- use stored state
|
||||
if (mimic == null) return; // or default to AIR/stone
|
||||
|
||||
BlockRenderDispatcher brd = Minecraft.getInstance().getBlockRenderer();
|
||||
|
||||
for (RenderType rt : brd.getBlockModel(mimic).getRenderTypes(mimic, level.random, ModelData.EMPTY)) {
|
||||
brd.renderBatched(
|
||||
mimic,
|
||||
be.getBlockPos(),
|
||||
level,
|
||||
poseStack,
|
||||
buffer.getBuffer(rt),
|
||||
false,
|
||||
level.random,
|
||||
ModelData.EMPTY,
|
||||
rt
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,13 @@ package net.xevianlight.aphelion.block.entity.custom;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.entity.BlockEntityType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.xevianlight.aphelion.Aphelion;
|
||||
import net.xevianlight.aphelion.core.init.ModBlockEntities;
|
||||
import net.xevianlight.aphelion.util.IMultiblockController;
|
||||
import net.xevianlight.aphelion.util.IMultiblockPart;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -22,6 +25,21 @@ public class EAFPartEntity extends BlockEntity implements IMultiblockPart {
|
||||
setChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getMimicing() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMimicing(BlockState newState) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDummyBroken() {
|
||||
Aphelion.LOGGER.error("I SHOULDNT BE CALLED!!!");
|
||||
}
|
||||
|
||||
public @Nullable BlockPos getControllerPos() {
|
||||
return controllerPos;
|
||||
}
|
||||
|
||||
@@ -61,6 +61,13 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
public static final int OUTPUT_SLOT = 2;
|
||||
public static final int ENERGY_SLOT = 3;
|
||||
|
||||
private boolean dirty = false;
|
||||
|
||||
@Override
|
||||
public String getMenuTitle() {
|
||||
return "Vacuum Arc Furnace";
|
||||
}
|
||||
|
||||
public VacuumArcFurnaceControllerEntity(BlockPos pos, BlockState blockState) {
|
||||
super(ModBlockEntities.VACUUM_ARC_FURNACE_ENTITY.get(), pos, blockState);
|
||||
this.data = new ContainerData() {
|
||||
@@ -109,6 +116,14 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
|
||||
public void tick(Level level, BlockPos pos, BlockState blockState) {
|
||||
|
||||
if (dirty) {
|
||||
dirty = false;
|
||||
BlockState current = level.getBlockState(pos);
|
||||
MultiblockHelper.tryForm(level, current, pos, SHAPE, AphelionBlockStateProperties.FORMED);
|
||||
}
|
||||
|
||||
BlockState newBlockState = level.getBlockState(pos);
|
||||
|
||||
if (!blockState.getValue(AphelionBlockStateProperties.FORMED))
|
||||
return;
|
||||
|
||||
@@ -120,8 +135,8 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
// Recipe detected! We have enough energy to process
|
||||
progress++;
|
||||
useEnergy();
|
||||
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, true));
|
||||
setChanged(level, pos, blockState);
|
||||
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, true));
|
||||
setChanged(level, pos, newBlockState);
|
||||
|
||||
if (hasCraftingFinished()) {
|
||||
outputBlastingResult(INPUT_SLOT, OUTPUT_SLOT);
|
||||
@@ -129,14 +144,14 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
}
|
||||
} else if (hasFurnaceRecipe(INPUT_SLOT) && !hasEnoughEnergyToCraft(MACHINE_ENERGY_COST)) {
|
||||
// Recipe detected but we ran out of power
|
||||
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, false));
|
||||
setChanged(level, pos, blockState);
|
||||
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, false));
|
||||
setChanged(level, pos, newBlockState);
|
||||
progress = progress > 0 ? progress - 1 : 0;
|
||||
} else {
|
||||
// Invalid recipe
|
||||
resetProgress();
|
||||
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, false));
|
||||
setChanged(level, pos, blockState);
|
||||
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, false));
|
||||
setChanged(level, pos, newBlockState);
|
||||
}
|
||||
} else {
|
||||
// Secondary slot is NOT empty, try alloying recipes
|
||||
@@ -145,8 +160,8 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
// Alloy recipe detected! We have enough energy to process
|
||||
progress++;
|
||||
useEnergy();
|
||||
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, true));
|
||||
setChanged(level, pos, blockState);
|
||||
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, true));
|
||||
setChanged(level, pos, newBlockState);
|
||||
|
||||
if (hasCraftingFinished()) {
|
||||
outputAlloyingResult(INPUT_SLOT, SECONDARY_INPUT_SLOT, OUTPUT_SLOT);
|
||||
@@ -154,15 +169,15 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
}
|
||||
} else {
|
||||
// Recipe detected but we ran out of power
|
||||
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, false));
|
||||
setChanged(level, pos, blockState);
|
||||
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, false));
|
||||
setChanged(level, pos, newBlockState);
|
||||
progress = progress > 0 ? progress - 1 : 0;
|
||||
}
|
||||
} else {
|
||||
// Invalid recipe
|
||||
resetProgress();
|
||||
level.setBlockAndUpdate(pos, blockState.setValue(ElectricArcFurnace.LIT, false));
|
||||
setChanged(level, pos, blockState);
|
||||
level.setBlockAndUpdate(pos, newBlockState.setValue(ElectricArcFurnace.LIT, false));
|
||||
setChanged(level, pos, newBlockState);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -328,6 +343,11 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
return isFormed() ? fullHandler : emptyJeiHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModEnergyStorage getEnergy() {
|
||||
return ENERGY_STORAGE;
|
||||
}
|
||||
|
||||
public IEnergyStorage getEnergyStorage(@Nullable Direction direction) {
|
||||
if (direction == null)
|
||||
return isFormed() ? ENERGY_STORAGE : NULL_ENERGY_STORAGE;
|
||||
@@ -351,6 +371,7 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStackHandler getInventory() {
|
||||
return inventory;
|
||||
}
|
||||
@@ -416,15 +437,20 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiblockHelper.ShapePart[] getMultiblockShape() {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
public static final MultiblockHelper.ShapePart[] SHAPE = new MultiblockHelper.ShapePart[] {
|
||||
|
||||
//Layer -1
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,-1,0), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,-1,0), s -> s.is(ModBlocks.BLOCK_STEEL)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,-1,1), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,-1,2), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,-1,0), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,-1,2), s -> s.is(ModBlocks.BLOCK_STEEL)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,-1,0), s -> s.is(ModBlocks.BLOCK_STEEL)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,-1,1), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,-1,2), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,-1,2), s -> s.is(ModBlocks.BLOCK_STEEL)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(0,-1,0), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(0,-1,1), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(0,-1,2), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
@@ -441,12 +467,12 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
|
||||
//Layer 1
|
||||
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,1,0), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,1,0), s -> s.is(ModBlocks.BLOCK_STEEL)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,1,1), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,1,2), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,1,0), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(1,1,2), s -> s.is(ModBlocks.BLOCK_STEEL)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,1,0), s -> s.is(ModBlocks.BLOCK_STEEL)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,1,1), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,1,2), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(-1,1,2), s -> s.is(ModBlocks.BLOCK_STEEL)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(0,1,0), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(0,1,1), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
new MultiblockHelper.ShapePart(new BlockPos(0,1,2), s -> s.is(ModBlocks.ARC_FURNACE_CASING_BLOCK)),
|
||||
@@ -493,15 +519,12 @@ public class VacuumArcFurnaceControllerEntity extends BlockEntity implements Men
|
||||
this.formed = formed;
|
||||
invalidateCapabilities();
|
||||
if (!formed) {
|
||||
drops();
|
||||
// drops();
|
||||
}
|
||||
}
|
||||
|
||||
private void setFormedState(boolean value) {
|
||||
BlockState state = getBlockState();
|
||||
if (state.hasProperty(ElectricArcFurnace.FORMED) && state.getValue(ElectricArcFurnace.FORMED) != value) {
|
||||
level.setBlock(worldPosition, state.setValue(ElectricArcFurnace.FORMED, value), 3);
|
||||
}
|
||||
@Override
|
||||
public void markDirty() {
|
||||
dirty = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user