Skip to content

Commit

Permalink
why is the rendering code so bad
Browse files Browse the repository at this point in the history
Signed-off-by: Octol1ttle <[email protected]>
  • Loading branch information
Octol1ttle committed Jul 31, 2024
1 parent 7cc3b96 commit 429cf28
Show file tree
Hide file tree
Showing 86 changed files with 577 additions and 552 deletions.
2 changes: 1 addition & 1 deletion src/main/java/net/splatcraft/forge/blocks/CrateBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public CrateBlock(boolean isSunken)

public static List<ItemStack> generateLoot(Level level, CrateTileEntity crate, BlockState state, float luckValue)
{
if (level == null || level.isClientSide)
if (level == null || level.isClientSide())
return Collections.emptyList();

BlockPos pos = crate.getBlockPos();
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/net/splatcraft/forge/blocks/InkVatBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
Expand Down Expand Up @@ -61,7 +66,7 @@ public BlockState getStateForPlacement(BlockPlaceContext context)
@Override
public @NotNull InteractionResult use(@NotNull BlockState state, Level levelIn, @NotNull BlockPos pos, @NotNull Player player, @NotNull InteractionHand handIn, @NotNull BlockHitResult hit)
{
if (levelIn.isClientSide)
if (levelIn.isClientSide())
{
return InteractionResult.SUCCESS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
{
te.setItem(0, player.getItemInHand(hand).copy());
player.getItemInHand(hand).setCount(0);
return InteractionResult.sidedSuccess(level.isClientSide);
return InteractionResult.sidedSuccess(level.isClientSide());
}
else if(!te.isEmpty())
{
ItemStack remote = te.removeItemNoUpdate(0);
if(!player.addItem(remote))
CommonUtils.spawnItem(level, pos.above(), remote);
return InteractionResult.sidedSuccess(level.isClientSide);
return InteractionResult.sidedSuccess(level.isClientSide());
}
}

Expand Down
67 changes: 34 additions & 33 deletions src/main/java/net/splatcraft/forge/blocks/SpawnPadBlock.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.splatcraft.forge.blocks;

import java.util.Optional;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.EntityType;
Expand All @@ -12,7 +13,11 @@
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
Expand All @@ -21,7 +26,7 @@
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.level.material.PushReaction;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.HitResult;
Expand All @@ -36,10 +41,10 @@
import net.splatcraft.forge.tileentities.InkColorTileEntity;
import net.splatcraft.forge.tileentities.SpawnPadTileEntity;
import net.splatcraft.forge.util.ColorUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

@SuppressWarnings("deprecation")
public class SpawnPadBlock extends Block implements IColoredBlock, SimpleWaterloggedBlock, EntityBlock
{
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
Expand All @@ -51,26 +56,26 @@ public class SpawnPadBlock extends Block implements IColoredBlock, SimpleWaterlo

public SpawnPadBlock()
{
super(Properties.of(Material.METAL).strength(2.0f).requiresCorrectToolForDrops());
super(Properties.of().mapColor(MapColor.METAL).strength(2.0f).requiresCorrectToolForDrops());
this.registerDefaultState(this.getStateDefinition().any().setValue(WATERLOGGED, false).setValue(DIRECTION, Direction.NORTH));

SplatcraftBlocks.inkColoredBlocks.add(this);
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state)
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state)
{
return SplatcraftTileEntities.spawnPadTileEntity.get().create(pos, state);
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter levelIn, BlockPos pos, CollisionContext context)
public @NotNull VoxelShape getShape(@NotNull BlockState state, @NotNull BlockGetter levelIn, @NotNull BlockPos pos, @NotNull CollisionContext context)
{
return SHAPE;
}

@Override
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean p_60519_)
public void onRemove(@NotNull BlockState state, Level level, @NotNull BlockPos pos, @NotNull BlockState newState, boolean p_60519_)
{
if(level.getBlockEntity(pos) instanceof SpawnPadTileEntity spawnPad)
for (Stage stage : Stage.getStagesForPosition(level, new Vec3(pos.getX(), pos.getY(), pos.getZ())))
Expand Down Expand Up @@ -98,7 +103,7 @@ public ItemStack getCloneItemStack(BlockState state, HitResult target, BlockGett

@Nullable
@Override
public BlockState getStateForPlacement(BlockPlaceContext context)
public BlockState getStateForPlacement(@NotNull BlockPlaceContext context)
{
for(Direction dir : Direction.values()) {
if (dir.get2DDataValue() < 0)
Expand All @@ -118,13 +123,13 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
}

@Override
public FluidState getFluidState(BlockState state)
public @NotNull FluidState getFluidState(BlockState state)
{
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}

@Override
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor levelIn, BlockPos currentPos, BlockPos facingPos)
public @NotNull BlockState updateShape(BlockState stateIn, @NotNull Direction facing, @NotNull BlockState facingState, @NotNull LevelAccessor levelIn, @NotNull BlockPos currentPos, @NotNull BlockPos facingPos)
{
if (stateIn.getValue(WATERLOGGED))
{
Expand All @@ -141,29 +146,30 @@ public PushReaction getPistonPushReaction(BlockState state)
}

@Override
public ItemStack getCloneItemStack(BlockGetter reader, BlockPos pos, BlockState state)
public @NotNull ItemStack getCloneItemStack(@NotNull BlockGetter reader, @NotNull BlockPos pos, @NotNull BlockState state)
{
ItemStack stack = super.getCloneItemStack(reader, pos, state);

if (reader.getBlockEntity(pos) instanceof InkColorTileEntity)
ColorUtils.setColorLocked(ColorUtils.setInkColor(stack, ColorUtils.getInkColor(reader.getBlockEntity(pos))), true);
if (reader.getBlockEntity(pos) instanceof InkColorTileEntity te) {
ColorUtils.setColorLocked(ColorUtils.setInkColor(stack, ColorUtils.getInkColor(te)), true);
}

return stack;
}

@Override
public boolean isPathfindable(BlockState p_196266_1_, BlockGetter p_196266_2_, BlockPos p_196266_3_, PathComputationType p_196266_4_) {
public boolean isPathfindable(@NotNull BlockState p_196266_1_, @NotNull BlockGetter p_196266_2_, @NotNull BlockPos p_196266_3_, @NotNull PathComputationType p_196266_4_) {
return false;
}

@Override
public boolean isPossibleToRespawnInThis()
public boolean isPossibleToRespawnInThis(@NotNull BlockState pState)
{
return true;
}

@Override
public void setPlacedBy(Level level, BlockPos pos, BlockState state, @Nullable LivingEntity entity, ItemStack stack)
public void setPlacedBy(@NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState state, @Nullable LivingEntity entity, ItemStack stack)
{
if (stack.getTag() != null && level.getBlockEntity(pos) instanceof SpawnPadTileEntity spawnPad)
{
Expand Down Expand Up @@ -216,14 +222,9 @@ public boolean canDamage()
@Override
public int getColor(Level level, BlockPos pos)
{
if (level.getBlockEntity(pos) instanceof InkColorTileEntity)
{
InkColorTileEntity tileEntity = (InkColorTileEntity) level.getBlockEntity(pos);
if (tileEntity != null)
{
return tileEntity.getColor();
}
}
if (level.getBlockEntity(pos) instanceof InkColorTileEntity tileEntity) {
return tileEntity.getColor();
}
return -1;
}

Expand Down Expand Up @@ -270,7 +271,7 @@ public Aux(SpawnPadBlock parent)


@Override
public VoxelShape getShape(BlockState state, BlockGetter reader, BlockPos pos, CollisionContext context)
public @NotNull VoxelShape getShape(BlockState state, @NotNull BlockGetter reader, @NotNull BlockPos pos, @NotNull CollisionContext context)
{
int i = state.getValue(DIRECTION).get2DDataValue()*2 + (state.getValue(IS_CORNER) ? 1 : 0);

Expand Down Expand Up @@ -307,13 +308,13 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
}

@Override
public FluidState getFluidState(BlockState state)
public @NotNull FluidState getFluidState(BlockState state)
{
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}

@Override
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor levelIn, BlockPos currentPos, BlockPos facingPos)
public @NotNull BlockState updateShape(@NotNull BlockState stateIn, @NotNull Direction facing, @NotNull BlockState facingState, LevelAccessor levelIn, @NotNull BlockPos currentPos, @NotNull BlockPos facingPos)
{
if(levelIn.getBlockState(getParentPos(stateIn, currentPos)).getBlock() != parent)
return Blocks.AIR.defaultBlockState();
Expand All @@ -328,7 +329,7 @@ public BlockState updateShape(BlockState stateIn, Direction facing, BlockState f


@Override
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean bool)
public void onRemove(@NotNull BlockState state, Level level, @NotNull BlockPos pos, @NotNull BlockState newState, boolean bool)
{
BlockPos parentPos = getParentPos(state, pos);
if(level.getBlockState(parentPos).getBlock() == parent)
Expand Down Expand Up @@ -370,7 +371,7 @@ public boolean remoteInkClear(Level level, BlockPos pos)
}

@Override
public boolean isPathfindable(BlockState p_196266_1_, BlockGetter p_196266_2_, BlockPos p_196266_3_, PathComputationType p_196266_4_) {
public boolean isPathfindable(@NotNull BlockState p_196266_1_, @NotNull BlockGetter p_196266_2_, @NotNull BlockPos p_196266_3_, @NotNull PathComputationType p_196266_4_) {
return false;
}

Expand All @@ -382,15 +383,15 @@ public Optional<Vec3> getRespawnPosition(BlockState state, EntityType<?> type, L
}

@Override
public ItemStack getCloneItemStack(BlockGetter level, BlockPos pos, BlockState state)
public @NotNull ItemStack getCloneItemStack(@NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull BlockState state)
{
BlockPos parentPos = getParentPos(state, pos);
return parent.getCloneItemStack(level, parentPos, level.getBlockState(parentPos));
}

@Override
public RenderShape getRenderShape(BlockState state) {
public @NotNull RenderShape getRenderShape(@NotNull BlockState state) {
return RenderShape.INVISIBLE;
}
}
}
}
36 changes: 20 additions & 16 deletions src/main/java/net/splatcraft/forge/blocks/SplatSwitchBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MapColor;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.splatcraft.forge.registries.SplatcraftBlocks;
Expand All @@ -28,8 +28,10 @@
import net.splatcraft.forge.tileentities.InkColorTileEntity;
import net.splatcraft.forge.util.BlockInkedResult;
import net.splatcraft.forge.util.InkBlockUtils;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("deprecation")
public class SplatSwitchBlock extends Block implements IColoredBlock, SimpleWaterloggedBlock, EntityBlock
{
private static final VoxelShape[] SHAPES = new VoxelShape[]
Expand All @@ -48,7 +50,7 @@ public class SplatSwitchBlock extends Block implements IColoredBlock, SimpleWate

public SplatSwitchBlock()
{
super((Properties.of(Material.METAL).requiresCorrectToolForDrops().strength(5.0F).sound(SoundType.METAL).noOcclusion()));
super((Properties.of().mapColor(MapColor.METAL).requiresCorrectToolForDrops().strength(5.0F).sound(SoundType.METAL).noOcclusion()));
registerDefaultState(defaultBlockState().setValue(FACING, Direction.UP).setValue(POWERED, false));

SplatcraftBlocks.inkColoredBlocks.add(this);
Expand All @@ -60,7 +62,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockSt
}

@Override
public VoxelShape getShape(BlockState state, BlockGetter level, BlockPos pos, CollisionContext context) {
public @NotNull VoxelShape getShape(BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull CollisionContext context) {
return SHAPES[state.getValue(FACING).ordinal()];
}

Expand All @@ -70,35 +72,38 @@ public boolean canConnectRedstone(BlockState state, BlockGetter level, BlockPos
}

@Override
public boolean isSignalSource(BlockState state) {
public boolean isSignalSource(@NotNull BlockState state) {
return true;
}

@Override
public int getSignal(BlockState state, BlockGetter level, BlockPos pos, Direction face) {
public int getSignal(BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull Direction face) {
return state.getValue(POWERED) ? 15 : 0;
}

@Override
public int getDirectSignal(BlockState state, BlockGetter level, BlockPos pos, Direction face) {
public int getDirectSignal(BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull Direction face) {
return state.getValue(POWERED) ? 15 : 0;
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context)
public BlockState getStateForPlacement(@NotNull BlockPlaceContext context)
{
BlockState state = super.getStateForPlacement(context).setValue(FACING, context.getClickedFace());
return state.setValue(WATERLOGGED, context.getLevel().getFluidState(context.getClickedPos()).getType() == Fluids.WATER);
BlockState state = super.getStateForPlacement(context);
if (state == null) {
return null;
}
return state.setValue(FACING, context.getClickedFace()).setValue(WATERLOGGED, context.getLevel().getFluidState(context.getClickedPos()).getType() == Fluids.WATER);
}

@Override
public FluidState getFluidState(BlockState state)
public @NotNull FluidState getFluidState(BlockState state)
{
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}

@Override
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor levelIn, BlockPos currentPos, BlockPos facingPos)
public @NotNull BlockState updateShape(@NotNull BlockState stateIn, @NotNull Direction facing, @NotNull BlockState facingState, @NotNull LevelAccessor levelIn, @NotNull BlockPos currentPos, @NotNull BlockPos facingPos)
{
if(InkedBlock.isTouchingLiquid(levelIn, currentPos) && levelIn instanceof Level)
{
Expand All @@ -112,7 +117,7 @@ public BlockState updateShape(BlockState stateIn, Direction facing, BlockState f
}

@Override
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving)
public void onRemove(BlockState state, @NotNull Level level, @NotNull BlockPos pos, @NotNull BlockState newState, boolean isMoving)
{
if(state.getValue(POWERED))
updateNeighbors(state, level, pos);
Expand Down Expand Up @@ -148,8 +153,7 @@ public boolean remoteColorChange(Level level, BlockPos pos, int newColor) {
public int getColor(Level level, BlockPos pos)
{
BlockState state = level.getBlockState(pos);
return state.getValue(POWERED) && level.getBlockEntity(pos) instanceof InkColorTileEntity ?
((InkColorTileEntity) level.getBlockEntity(pos)).getColor() : -1;
return state.getValue(POWERED) && level.getBlockEntity(pos) instanceof InkColorTileEntity te ? te.getColor() : -1;
}

@Override
Expand Down Expand Up @@ -185,7 +189,7 @@ private void playSound(LevelAccessor level, BlockPos currentPos, BlockState stat

@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos pos, BlockState state) {
public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState state) {
return SplatcraftTileEntities.colorTileEntity.get().create(pos, state);
}
}
}
Loading

0 comments on commit 429cf28

Please sign in to comment.