Skip to content

Commit

Permalink
Fix not extending BasicBlockJS and the particle texture now uses the …
Browse files Browse the repository at this point in the history
…side texture if no other texture is set.
  • Loading branch information
ChiefArug committed Aug 25, 2022
1 parent fc54cef commit 89f45c1
Showing 1 changed file with 32 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.block.Block;
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.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.Fluids;
import org.jetbrains.annotations.NotNull;

public class HorizontalDirectionalBlockBuilder extends BlockBuilder {
Expand All @@ -36,7 +38,7 @@ protected void generateBlockModelJsons(AssetJsonGenerator gen) {

mg.texture("side", side);
mg.texture("front", getTextureOrDefault("front", newID("block/", "_front").toString()));
mg.texture("particle", textures.get("particle").getAsString());
mg.texture("particle", getTextureOrDefault("particle", side));
mg.texture("top", getTextureOrDefault("top", side));

if (textures.has("bottom")) {
Expand Down Expand Up @@ -66,15 +68,34 @@ private String getTextureOrDefault(String name, String defaultTexture) {

@Override
public Block createObject() {
return new HorizontalDirectionalBlock(createProperties()) {
@Override
protected void createBlockStateDefinition(@NotNull StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING);
}
@Override
public BlockState getStateForPlacement(@NotNull BlockPlaceContext arg) {
return this.defaultBlockState().setValue(FACING, arg.getHorizontalDirection().getOpposite());
return new HorizontalDirectionalBlockJS(this);
}

public static class HorizontalDirectionalBlockJS extends BasicBlockJS {

public static DirectionProperty FACING = BlockStateProperties.HORIZONTAL_FACING;

public HorizontalDirectionalBlockJS(BlockBuilder p) {
super(p);
}

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

@Override
public BlockState getStateForPlacement(@NotNull BlockPlaceContext context) {
var state = defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());

if (blockBuilder.waterlogged) {
state = state.setValue(BlockStateProperties.WATERLOGGED, context.getLevel().getFluidState(context.getClickedPos()).getType() == Fluids.WATER);
}
};

return state;

}

}
}

0 comments on commit 89f45c1

Please sign in to comment.