Skip to content

Commit

Permalink
new moving head
Browse files Browse the repository at this point in the history
  • Loading branch information
dumann089 authored and Rushmead committed Feb 10, 2025
1 parent d180440 commit d3621f5
Show file tree
Hide file tree
Showing 14 changed files with 1,102 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import dev.imabad.theatrical.blockentities.light.BaseLightBlockEntity;
import dev.imabad.theatrical.blockentities.light.FresnelBlockEntity;
import dev.imabad.theatrical.blocks.light.MovingLightBlock;
import dev.imabad.theatrical.blocks.light.MovingWashBlock;
import dev.imabad.theatrical.client.LazyRenderers;
import dev.imabad.theatrical.client.blockentities.BasicLightingConsoleRenderer;
import dev.imabad.theatrical.client.blockentities.FresnelRenderer;
import dev.imabad.theatrical.client.blockentities.LEDPanelRenderer;
import dev.imabad.theatrical.client.blockentities.MovingLightRenderer;
import dev.imabad.theatrical.client.blockentities.MovingWashRenderer;
import dev.imabad.theatrical.client.dmx.ArtNetManager;
import dev.imabad.theatrical.client.dmx.ArtNetToNetworkClientData;
import dev.imabad.theatrical.client.dmx.TheatricalArtNetClient;
Expand Down Expand Up @@ -57,6 +59,7 @@ public class TheatricalClient {
private static ArtNetManager artNetManager;
public static void init() {
BlockEntityRendererRegistry.register(BlockEntities.MOVING_LIGHT.get(), MovingLightRenderer::new);
BlockEntityRendererRegistry.register(BlockEntities.MOVING_WASH.get(), MovingWashRenderer::new);
BlockEntityRendererRegistry.register(BlockEntities.LED_FRESNEL.get(), FresnelRenderer::new);
BlockEntityRendererRegistry.register(BlockEntities.LED_PANEL.get(), LEDPanelRenderer::new);
BlockEntityRendererRegistry.register(BlockEntities.BASIC_LIGHTING_DESK.get(), BasicLightingConsoleRenderer::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.imabad.theatrical.blockentities.light.FresnelBlockEntity;
import dev.imabad.theatrical.blockentities.light.LEDPanelBlockEntity;
import dev.imabad.theatrical.blockentities.light.MovingLightBlockEntity;
import dev.imabad.theatrical.blockentities.light.MovingWashBlockEntity;
import dev.imabad.theatrical.blocks.Blocks;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand All @@ -22,4 +23,5 @@ public class BlockEntities {
public static final RegistrySupplier<BlockEntityType<RedstoneInterfaceBlockEntity>> REDSTONE_INTERFACE = BLOCK_ENTITIES.register("redstone_interface", () -> BlockEntityType.Builder.of(RedstoneInterfaceBlockEntity::new, Blocks.REDSTONE_INTERFACE.get()).build(null));
public static final RegistrySupplier<BlockEntityType<LEDPanelBlockEntity>> LED_PANEL = BLOCK_ENTITIES.register("led_panel", () -> BlockEntityType.Builder.of(LEDPanelBlockEntity::new, Blocks.LED_PANEL.get()).build(null));
public static final RegistrySupplier<BlockEntityType<BasicLightingDeskBlockEntity>> BASIC_LIGHTING_DESK = BLOCK_ENTITIES.register("basic_lighting_desk", () -> BlockEntityType.Builder.of(BasicLightingDeskBlockEntity::new, Blocks.BASIC_LIGHTING_DESK.get()).build(null));
public static final RegistrySupplier<BlockEntityType<MovingWashBlockEntity>> MOVING_WASH = BLOCK_ENTITIES.register("moving_wash", () -> BlockEntityType.Builder.of(MovingWashBlockEntity::new, Blocks.MOVING_WASH_BLOCK.get()).build(null));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package dev.imabad.theatrical.blockentities.light;

import dev.imabad.theatrical.api.Fixture;
import dev.imabad.theatrical.blockentities.BlockEntities;
import dev.imabad.theatrical.blocks.light.MovingWashBlock;
import dev.imabad.theatrical.fixtures.Fixtures;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;

import java.util.Arrays;

public class MovingWashBlockEntity extends BaseDMXConsumerLightBlockEntity {
public MovingWashBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState) {
super(blockEntityType, blockPos, blockState);
setChannelCount(7);
}

public MovingWashBlockEntity(BlockPos pos, BlockState state) {
this(BlockEntities.MOVING_WASH.get(), pos, state);
}
@Override
public Fixture getFixture() {
return Fixtures.MOVING_WASH.get();
}

@Override
public void consume(byte[] dmxValues) {
int start = this.getChannelStart() > 0 ? this.getChannelStart() - 1 : 0;
byte[] ourValues = Arrays.copyOfRange(dmxValues, start,
start+ this.getChannelCount());
if(ourValues.length < 7){
return;
}
if(this.storePrev()){
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
}
intensity = convertByteToInt(ourValues[0]);
red = convertByteToInt(ourValues[1]);
green = convertByteToInt(ourValues[2]);
blue = convertByteToInt(ourValues[3]);
focus = convertByteToInt(ourValues[4]);
pan = (int) ((convertByteToInt(ourValues[5]) * 360) / 255f) - 180;
tilt = (int) ((convertByteToInt(ourValues[6]) * 270) / 255F) - 225;
level.sendBlockUpdated(getBlockPos(), getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
setChanged();
}

@Override
public int getDeviceTypeId() {
return 0x01;
}

@Override
public String getModelName() {
return "Moving Wash";
}

@Override
public ResourceLocation getFixtureId() {
return Fixtures.MOVING_WASH.getId();
}

@Override
public int getActivePersonality() {
return 0;
}

public int convertByteToInt(byte val) {
return Byte.toUnsignedInt(val);
}
@Override
public boolean isUpsideDown() {
return getBlockState().getValue(MovingWashBlock.HANGING) && getBlockState().getValue(MovingWashBlock.HANG_DIRECTION) == Direction.UP;
}

@Override
public int getBasePan() {
return 0;
}
}
2 changes: 2 additions & 0 deletions common/src/main/java/dev/imabad/theatrical/blocks/Blocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import dev.imabad.theatrical.blocks.light.FresnelBlock;
import dev.imabad.theatrical.blocks.light.LEDPanelBlock;
import dev.imabad.theatrical.blocks.light.MovingLightBlock;
import dev.imabad.theatrical.blocks.light.MovingWashBlock;
import dev.imabad.theatrical.blocks.rigging.TankTrapBlock;
import dev.imabad.theatrical.blocks.rigging.TrussBlock;
import net.minecraft.core.BlockPos;
Expand All @@ -23,6 +24,7 @@ public class Blocks {

public static final DeferredRegister<Block> BLOCKS = TheatricalRegistry.get(Registries.BLOCK);
public static final RegistrySupplier<Block> MOVING_LIGHT_BLOCK = BLOCKS.register("moving_light", MovingLightBlock::new);
public static final RegistrySupplier<Block> MOVING_WASH_BLOCK = BLOCKS.register("moving_wash", MovingWashBlock::new);
public static final RegistrySupplier<Block> PIPE_BLOCK = BLOCKS.register("pipe", dev.imabad.theatrical.blocks.rigging.PipeBlock::new);
public static final RegistrySupplier<Block> ART_NET_INTERFACE = BLOCKS.register("artnet_interface", ArtNetInterfaceBlock::new);
public static final RegistrySupplier<Block> LED_FRESNEL = BLOCKS.register("led_fresnel", FresnelBlock::new);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package dev.imabad.theatrical.blocks.light;

import dev.imabad.theatrical.TheatricalClient;
import dev.imabad.theatrical.TheatricalScreen;
import dev.imabad.theatrical.blockentities.BlockEntities;
import dev.imabad.theatrical.blockentities.light.MovingWashBlockEntity;
import dev.imabad.theatrical.blocks.Blocks;
import dev.imabad.theatrical.net.OpenScreen;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.EntityCollisionContext;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;

public class MovingWashBlock extends BaseLightBlock{


public MovingWashBlock() {
super(Properties.of()
.requiresCorrectToolForDrops()
.strength(3, 3)
.noOcclusion()
.isValidSpawn(Blocks::neverAllowSpawn)
.mapColor(MapColor.METAL)
.sound(SoundType.METAL)
.pushReaction(PushReaction.DESTROY));
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new MovingWashBlockEntity(blockPos, blockState);
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder);
}

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext blockPlaceContext) {
return super.getStateForPlacement(blockPlaceContext).setValue(HANGING,
blockPlaceContext.getClickedFace() == Direction.DOWN ||
isHanging(blockPlaceContext.getLevel(), blockPlaceContext.getClickedPos()));
}

@Override
public boolean canSurvive(BlockState blockState, LevelReader levelReader, BlockPos blockPos) {
if(blockState.getValue(HANGING)){
return isHanging(levelReader, blockPos);
}
return !levelReader.getBlockState(blockPos.below()).isAir();
}

@Override
public Direction getLightFacing(Direction hangDirection, Player placingPlayer) {
if(hangDirection == Direction.UP){
return placingPlayer.getDirection();
}
Direction playerFacing = placingPlayer.getDirection();
return playerFacing.getOpposite();
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState state, BlockEntityType<T> blockEntityType) {
return blockEntityType == BlockEntities.MOVING_WASH.get() ? MovingWashBlockEntity::tick : null;
}

@Override
public VoxelShape getVisualShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
if(context instanceof EntityCollisionContext entityCollisionContext && entityCollisionContext.getEntity() == null){
return Shapes.empty();
}
return super.getVisualShape(state, level, pos, context);
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if(super.use(state, level, pos, player, hand, hit) == InteractionResult.PASS) {
if (level.isClientSide) {
if (player.isCrouching()) {
if (TheatricalClient.DEBUG_BLOCKS.contains(pos)) {
TheatricalClient.DEBUG_BLOCKS.remove(pos);
} else {
TheatricalClient.DEBUG_BLOCKS.add(pos);
}
return InteractionResult.SUCCESS;
}
} else {
new OpenScreen(pos, TheatricalScreen.GENERIC_DMX).sendTo((ServerPlayer) player);
}
}
return InteractionResult.SUCCESS;
}

@Override
public void destroy(LevelAccessor level, BlockPos pos, BlockState state) {
if(level.isClientSide()) {
TheatricalClient.DEBUG_BLOCKS.remove(pos);
}
super.destroy(level, pos, state);
}
}
Loading

0 comments on commit d3621f5

Please sign in to comment.