Terrain and Path block model fix

This commit is contained in:
Aleksey 2021-05-28 14:15:55 +03:00
parent e0b45ee833
commit d2d9c8d2eb
4 changed files with 29 additions and 17 deletions

View file

@ -33,10 +33,14 @@ import ru.bclib.client.models.PatternsHelper;
public abstract class BasePathBlock extends BaseBlockNotFull {
private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16);
private Block baseBlock;
public BasePathBlock(Block source) {
super(FabricBlockSettings.copyOf(source).isValidSpawn((state, world, pos, type) -> { return false; }));
this.baseBlock = Blocks.DIRT;
if (source instanceof BaseTerrainBlock) {
BaseTerrainBlock terrain = (BaseTerrainBlock) source;
this.baseBlock = terrain.getBaseBlock();
terrain.setPathBlock(this);
}
}
@ -66,13 +70,12 @@ public abstract class BasePathBlock extends BaseBlockNotFull {
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String name = resourceLocation.getPath();
Block bottomBlock = getBottomBlock();
ResourceLocation bottomId = Registry.BLOCK.getKey(bottomBlock);
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
String name = blockId.getPath();
ResourceLocation bottomId = Registry.BLOCK.getKey(baseBlock);
String bottom = bottomId.getNamespace() + ":block/" + bottomId.getPath();
Map<String, String> textures = Maps.newHashMap();
textures.put("%modid%", resourceLocation.getNamespace());
textures.put("%modid%", blockId.getNamespace());
textures.put("%top%", name + "_top");
textures.put("%side%", name.replace("_path", "") + "_side");
textures.put("%bottom%", bottom);
@ -86,6 +89,4 @@ public abstract class BasePathBlock extends BaseBlockNotFull {
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createRandomTopModel(modelId);
}
protected abstract Block getBottomBlock();
}

View file

@ -6,6 +6,7 @@ import java.util.Map;
import java.util.Optional;
import java.util.Random;
import net.minecraft.core.Registry;
import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Maps;
@ -44,16 +45,23 @@ import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.sound.BlockSounds;
public class BaseTerrainBlock extends BaseBlock {
private final Block baseBlock;
private Block pathBlock;
public BaseTerrainBlock(Block baseBlock, MaterialColor color) {
super(FabricBlockSettings.copyOf(baseBlock).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
this.baseBlock = baseBlock;
}
public void setPathBlock(Block roadBlock) {
this.pathBlock = roadBlock;
}
public Block getBaseBlock() {
return baseBlock;
}
@Override
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
if (pathBlock != null && player.getMainHandItem().getItem().is(FabricToolTags.SHOVELS)) {
@ -106,12 +114,15 @@ public class BaseTerrainBlock extends BaseBlock {
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String name = resourceLocation.getPath();
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation baseId = Registry.BLOCK.getKey(baseBlock);
String modId = blockId.getNamespace();
String path = blockId.getPath();
String bottom = baseId.getNamespace() + ":block/" + baseId.getPath();
Map<String, String> textures = Maps.newHashMap();
textures.put("%top%", "betterend:block/" + name + "_top");
textures.put("%side%", "betterend:block/" + name + "_side");
textures.put("%bottom%", "minecraft:block/end_stone");
textures.put("%top%", modId + ":block/" + path + "_top");
textures.put("%side%", modId + ":block/" + path + "_side");
textures.put("%bottom%", bottom);
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TOP_SIDE_BOTTOM, textures);
return ModelsHelper.fromPattern(pattern);
}

View file

@ -109,11 +109,11 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String path = resourceLocation.getPath();
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
String path = blockId.getPath();
Optional<String> pattern;
if (isMiddle(blockState)) {
ResourceLocation topId = new ResourceLocation(resourceLocation.getNamespace(), path + "_top");
ResourceLocation topId = new ResourceLocation(blockId.getNamespace(), path + "_top");
pattern = PatternsHelper.createBlockSimple(topId);
} else {
Map<String, String> textures = Maps.newHashMap();