-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
1,102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
common/src/main/java/dev/imabad/theatrical/blockentities/light/MovingWashBlockEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
common/src/main/java/dev/imabad/theatrical/blocks/light/MovingWashBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.