[BUG] Fix Advanced Candle block states.

This commit is contained in:
2023-04-02 17:05:43 +02:00
parent e7953754f0
commit 0860f01720

View File

@@ -1,7 +1,5 @@
package me.hypherionmc.hyperlighting.common.blocks;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import me.hypherionmc.craterlib.api.inventory.CraterCreativeModeTab;
import me.hypherionmc.craterlib.api.rendering.DyableBlock;
import me.hypherionmc.craterlib.common.item.BlockItemDyable;
@@ -33,10 +31,8 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.AttachFace;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.EnumProperty;
@@ -48,33 +44,24 @@ import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
public class AdvancedCandleBlock extends HorizontalDirectionalBlock implements DyableBlock, LightableBlock {
public class AdvancedCandleBlock extends Block implements DyableBlock, LightableBlock {
//region Properties
public static final BooleanProperty LIT = BlockStateProperties.LIT;
public static final EnumProperty<DyeColor> COLOR = EnumProperty.create("color", DyeColor.class);
public static final EnumProperty<AttachFace> ATTACH_FACE = EnumProperty.create("face", AttachFace.class, AttachFace.FLOOR, AttachFace.WALL);
//endregion
//region Bounding Boxes
private static final Map<Direction, VoxelShape> SHAPES = Maps.newEnumMap(
ImmutableMap.of(
Direction.NORTH, Block.box(5.5D, 2.0D, 11.0D, 10.5D, 12.0D, 16.0D),
Direction.SOUTH, Block.box(5.5D, 2.0D, 0.0D, 10.5D, 12.0D, 5.0D),
Direction.WEST, Block.box(11.0D, 2.0D, 5.5D, 16.0D, 12.0D, 10.5D),
Direction.EAST, Block.box(0.0D, 2.0D, 5.5D, 5.0D, 12.0D, 10.5D),
Direction.UP, Block.box(6.0D, 0.0D, 6.0D, 10.0D, 10.0D, 10.0D)
)
);
VoxelShape BOUNDING_BOX = Block.box(4, 0, 4, 11, 10, 11);
//endregion
private DyeColor color;
public AdvancedCandleBlock(String name, DyeColor color, CraterCreativeModeTab tab) {
super(Properties.of(Material.WOOD).noCollission().instabreak().lightLevel(BlockStateUtils.createLightLevelFromLitBlockState(15)));
this.registerDefaultState(this.defaultBlockState().setValue(FACING, Direction.NORTH).setValue(LIT, CommonRegistration.config.candleConfig.litByDefault).setValue(COLOR, color));
this.registerDefaultState(this.defaultBlockState().setValue(LIT, CommonRegistration.config.candleConfig.litByDefault).setValue(COLOR, color));
this.color = color;
CreativeTabRegistry.setCreativeTab(tab, HLItems.register(name, () -> new BlockItemDyable(this, new Item.Properties())));
@@ -82,28 +69,18 @@ public class AdvancedCandleBlock extends HorizontalDirectionalBlock implements D
@Override
public VoxelShape getShape(BlockState blockState, BlockGetter level, BlockPos pos, CollisionContext context) {
return switch (blockState.getValue(ATTACH_FACE)) {
case FLOOR -> SHAPES.get(Direction.UP);
case WALL -> SHAPES.get(blockState.getValue(FACING));
case CEILING -> null;
};
return BOUNDING_BOX;
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(LIT, ATTACH_FACE, FACING, COLOR);
builder.add(LIT, COLOR);
super.createBlockStateDefinition(builder);
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction direction = context.getClickedFace();
BlockState state = this.defaultBlockState();
if (direction == Direction.UP) {
state = state.setValue(ATTACH_FACE, AttachFace.FLOOR);
} else {
state = state.setValue(ATTACH_FACE, AttachFace.WALL).setValue(FACING, direction);
}
return state.setValue(LIT, CommonRegistration.config.candleConfig.litByDefault);
}
@@ -190,21 +167,11 @@ public class AdvancedCandleBlock extends HorizontalDirectionalBlock implements D
if (stateIn.getValue(LIT)) {
DyeColor color = stateIn.getValue(COLOR);
if (stateIn.getValue(ATTACH_FACE) == AttachFace.FLOOR) {
double d0 = (double) pos.getX() + 0.5D;
double d1 = (double) pos.getY() + 0.7D;
double d2 = (double) pos.getZ() + 0.5D;
double d0 = (double) pos.getX() + 0.48D;
double d1 = (double) pos.getY() + 0.79D;
double d2 = (double) pos.getZ() + 0.45D;
levelIn.addParticle(ParticleTypes.SMOKE, d0, d1, d2, 0.0D, 0.0D, 0.0D);
levelIn.addParticle(FlameParticles.getParticleByColor(color).get(), d0, d1, d2, 0D, 0D, 0D);
} else {
Direction direction = stateIn.getValue(FACING);
double d0 = (double) pos.getX() + 0.5D;
double d1 = (double) pos.getY() + 0.7D;
double d2 = (double) pos.getZ() + 0.5D;
Direction direction1 = direction.getOpposite();
levelIn.addParticle(ParticleTypes.SMOKE, d0 + 0.37D * (double) direction1.getStepX(), d1 + 0.15D, d2 + 0.37D * (double) direction1.getStepZ(), 0.0D, 0.0D, 0.0D);
levelIn.addParticle(FlameParticles.getParticleByColor(color).get(), d0 + 0.37D * (double) direction1.getStepX(), d1 + 0.15D, d2 + 0.37D * (double) direction1.getStepZ(), 0D, 0D, 0D);
}
}
}