Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package de.dafuqs.spectrum.blocks.structure;

import com.mojang.serialization.*;
import de.dafuqs.spectrum.blocks.redstone.*;
import net.minecraft.core.*;
import net.minecraft.server.level.*;
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.entity.*;
import net.minecraft.world.level.block.state.*;
import net.minecraft.world.level.block.state.properties.*;

public class PreservationSensorBlock extends BaseEntityBlock {

public static final MapCodec<PreservationSensorBlock> CODEC = simpleCodec(PreservationSensorBlock::new);

public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty POWERED = BlockStateProperties.POWERED;

public PreservationSensorBlock(Properties settings) {
super(settings);
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(POWERED, false));
}

@Override
public MapCodec<? extends PreservationSensorBlock> codec() {
return CODEC;
}

@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.MODEL;
}

@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
return new PreservationSensorBlockEntity(pos, state);
}

@Override
public void neighborChanged(BlockState state, Level world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
var isPowered = world.hasNeighborSignal(pos) || world.hasNeighborSignal(pos.above());
boolean wasPowered = state.getValue(POWERED);

if (isPowered && !wasPowered) {
if (!world.isClientSide()) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity instanceof PreservationSensorBlockEntity sensorBlockEntity) {
sensorBlockEntity.activateController();
}
}
world.setBlock(pos, state.setValue(POWERED, true), Block.UPDATE_CLIENTS);
} else if (!isPowered && wasPowered) {
world.setBlock(pos, state.setValue(POWERED, false), Block.UPDATE_CLIENTS);
}
}

@Override
public BlockState rotate(BlockState state, Rotation rotation) {
return state.setValue(FACING, rotation.rotate(state.getValue(FACING)));
}

@Override
public BlockState mirror(BlockState state, Mirror mirror) {
return state.rotate(mirror.getRotation(state.getValue(FACING)));
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, POWERED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package de.dafuqs.spectrum.blocks.structure;

import de.dafuqs.spectrum.helpers.*;
import de.dafuqs.spectrum.registries.*;
import net.minecraft.core.*;
import net.minecraft.nbt.*;
import net.minecraft.server.level.*;
import net.minecraft.world.level.block.entity.*;
import net.minecraft.world.level.block.state.*;

public class PreservationSensorBlockEntity extends BlockEntity {

protected Vec3i controllerOffset = Vec3i.ZERO;

public PreservationSensorBlockEntity(BlockPos pos, BlockState state) {
super(SpectrumBlockEntities.PRESERVATION_SENSOR.get(), pos, state);
}

@Override
public void loadAdditional(CompoundTag nbt, HolderLookup.Provider registryLookup) {
super.loadAdditional(nbt, registryLookup);
this.controllerOffset = null;
if (nbt.contains("ControllerOffset", Tag.TAG_INT_ARRAY)) {
int[] offset = nbt.getIntArray("ControllerOffset");
this.controllerOffset = new Vec3i(offset[0], offset[1], offset[2]);
}
}

@Override
public void saveAdditional(CompoundTag nbt, HolderLookup.Provider registryLookup) {
super.saveAdditional(nbt, registryLookup);
if (this.controllerOffset != null) {
nbt.putIntArray("ControllerOffset", new int[]{this.controllerOffset.getX(), this.controllerOffset.getY(), this.controllerOffset.getZ()});
}
}

@Override
public boolean onlyOpCanSetNbt() {
return true;
}

public void activateController() {
if (level instanceof ServerLevel && controllerOffset != null) {
BlockEntity blockEntity = level.getBlockEntity(Support.directionalOffset(this.worldPosition, this.controllerOffset, level.getBlockState(this.worldPosition).getValue(PreservationSensorBlock.FACING)));
if (blockEntity instanceof PreservationControllerBlockEntity controller) {
controller.openExit();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class SpectrumBlockEntities {

public static DeferredHolder<BlockEntityType<?>, BlockEntityType<PreservationControllerBlockEntity>> PRESERVATION_CONTROLLER = register("preservation_controller", PreservationControllerBlockEntity::new, SpectrumBlocks.PRESERVATION_CONTROLLER);
public static DeferredHolder<BlockEntityType<?>, BlockEntityType<PreservationRoundelBlockEntity>> PRESERVATION_ROUNDEL = register("preservation_roundel", PreservationRoundelBlockEntity::new, SpectrumBlocks.PRESERVATION_ROUNDEL);
public static DeferredHolder<BlockEntityType<?>, BlockEntityType<PreservationSensorBlockEntity>> PRESERVATION_SENSOR = register("preservation_sensor", PreservationSensorBlockEntity::new, SpectrumBlocks.PRESERVATION_SENSOR);
public static DeferredHolder<BlockEntityType<?>, BlockEntityType<PreservationBlockDetectorBlockEntity>> PRESERVATION_BLOCK_DETECTOR = register("preservation_block_detector", PreservationBlockDetectorBlockEntity::new, SpectrumBlocks.PRESERVATION_BLOCK_DETECTOR);
public static DeferredHolder<BlockEntityType<?>, BlockEntityType<DeepLightBlockEntity>> DEEP_LIGHT = register("deep_light", DeepLightBlockEntity::new, SpectrumBlocks.DEEP_LIGHT_CHISELED_PRESERVATION_STONE);
public static DeferredHolder<BlockEntityType<?>, BlockEntityType<PlayerTrackerBlockEntity>> PLAYER_TRACKING = register("player_tracking", PlayerTrackerBlockEntity::new, SpectrumBlocks.MANXI, SpectrumBlocks.PRESERVATION_ITEM_BOWL);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,7 @@ private static BlockBehaviour.Properties preservationBlock() {
public static final DeferredBlock<Block> PRESERVATION_GLASS = register(simple(blockWithItem("preservation_glass", () -> new TransparentBlock(preservationBlock().sound(SoundType.GLASS).noOcclusion().isRedstoneConductor(SpectrumBlocks::never).isSuffocating(SpectrumBlocks::never).isViewBlocking(SpectrumBlocks::never)))));
public static final DeferredBlock<Block> TINTED_PRESERVATION_GLASS = register(simple(blockWithItem("tinted_preservation_glass", () -> new TintedGlassBlock(BlockBehaviour.Properties.ofFullCopy(PRESERVATION_GLASS.get()).pushReaction(PushReaction.NORMAL)))));
public static final DeferredBlock<Block> PRESERVATION_ROUNDEL = register(singleton(blockWithItem("preservation_roundel", () -> new PreservationRoundelBlock(preservationBlock().noOcclusion().forceSolidOn())), SpectrumTexturedModelProviders.ROUNDEL));
public static final DeferredBlock<Block> PRESERVATION_SENSOR = register(simple(blockWithItem("preservation_sensor", () -> new PreservationSensorBlock(preservationBlock()))));
public static final DeferredBlock<PreservationBlockDetectorBlock> PRESERVATION_BLOCK_DETECTOR = register(blockWithItem("preservation_block_detector", () -> new PreservationBlockDetectorBlock(preservationBlock())).withBlockModel((ctx, block) -> MultiVariantGenerator.multiVariant(block, SpectrumModelHelper.createModelVariant(SpectrumTexturedModelProviders.complexOrientable(b -> b, "_side", b -> b, "_top", b -> PRESERVATION_STONE.get(), "_top_generic", b -> b, "_front", b -> b, "_back", b -> b, "_side").create(block, ctx.modelOutput))).with(SpectrumModelHelper.createNorthDefaultFacingVariantMap())));

private static BlockBehaviour.Properties shootingStar() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1532,6 +1532,7 @@ public static void registerSubTabs() {
entries.accept(SpectrumBlocks.PRESERVATION_GLASS);
entries.accept(SpectrumBlocks.TINTED_PRESERVATION_GLASS);
entries.accept(SpectrumBlocks.PRESERVATION_ROUNDEL);
entries.accept(SpectrumBlocks.PRESERVATION_SENSOR);
entries.accept(SpectrumBlocks.PRESERVATION_BLOCK_DETECTOR);
entries.accept(SpectrumBlocks.DIKE_GATE_FOUNTAIN);
entries.accept(SpectrumBlocks.DIKE_GATE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"variants": {
"powered=false": {
"model": "spectrum:block/preservation_sensor"
},
"powered=true": {
"model": "spectrum:block/preservation_sensor_on"
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/spectrum/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1720,6 +1720,7 @@
"block.spectrum.preservation_controller": "Preservation Controller",
"block.spectrum.preservation_glass": "Preservation Glass",
"block.spectrum.preservation_roundel": "Preservation Roundel",
"block.spectrum.preservation_sensor": "Preservation Sensor",
"block.spectrum.preservation_slab": "Preservation Slab",
"block.spectrum.preservation_stairs": "Preservation Stairs",
"block.spectrum.preservation_stone": "Preservation Stone",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "spectrum:block/preservation_sensor"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "spectrum:block/preservation_sensor_on"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "spectrum:block/preservation_sensor"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -1200,6 +1200,7 @@
"spectrum:preservation_glass",
"spectrum:tinted_preservation_glass",
"spectrum:preservation_roundel",
"spectrum:preservation_sensor",
"spectrum:preservation_block_detector",
"spectrum:blue_pigment",
"spectrum:tender_pickaxe",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"spectrum:preservation_chest",
"spectrum:dike_gate_fountain",
"spectrum:preservation_roundel",
"spectrum:preservation_sensor",
"spectrum:preservation_block_detector",
"spectrum:preservation_item_bowl",
"spectrum:black_chiseled_preservation_stone",
Expand Down
Loading