Terrain and Path block model fix
This commit is contained in:
parent
e0b45ee833
commit
d2d9c8d2eb
4 changed files with 29 additions and 17 deletions
|
@ -8,7 +8,7 @@ yarn_mappings=6
|
||||||
loader_version=0.11.3
|
loader_version=0.11.3
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 0.1.10
|
mod_version = 0.1.11
|
||||||
maven_group = ru.bclib
|
maven_group = ru.bclib
|
||||||
archives_base_name = bclib
|
archives_base_name = bclib
|
||||||
|
|
||||||
|
|
|
@ -33,10 +33,14 @@ import ru.bclib.client.models.PatternsHelper;
|
||||||
public abstract class BasePathBlock extends BaseBlockNotFull {
|
public abstract class BasePathBlock extends BaseBlockNotFull {
|
||||||
private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16);
|
private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16);
|
||||||
|
|
||||||
|
private Block baseBlock;
|
||||||
|
|
||||||
public BasePathBlock(Block source) {
|
public BasePathBlock(Block source) {
|
||||||
super(FabricBlockSettings.copyOf(source).isValidSpawn((state, world, pos, type) -> { return false; }));
|
super(FabricBlockSettings.copyOf(source).isValidSpawn((state, world, pos, type) -> { return false; }));
|
||||||
|
this.baseBlock = Blocks.DIRT;
|
||||||
if (source instanceof BaseTerrainBlock) {
|
if (source instanceof BaseTerrainBlock) {
|
||||||
BaseTerrainBlock terrain = (BaseTerrainBlock) source;
|
BaseTerrainBlock terrain = (BaseTerrainBlock) source;
|
||||||
|
this.baseBlock = terrain.getBaseBlock();
|
||||||
terrain.setPathBlock(this);
|
terrain.setPathBlock(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,13 +70,12 @@ public abstract class BasePathBlock extends BaseBlockNotFull {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String name = resourceLocation.getPath();
|
String name = blockId.getPath();
|
||||||
Block bottomBlock = getBottomBlock();
|
ResourceLocation bottomId = Registry.BLOCK.getKey(baseBlock);
|
||||||
ResourceLocation bottomId = Registry.BLOCK.getKey(bottomBlock);
|
|
||||||
String bottom = bottomId.getNamespace() + ":block/" + bottomId.getPath();
|
String bottom = bottomId.getNamespace() + ":block/" + bottomId.getPath();
|
||||||
Map<String, String> textures = Maps.newHashMap();
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
textures.put("%modid%", resourceLocation.getNamespace());
|
textures.put("%modid%", blockId.getNamespace());
|
||||||
textures.put("%top%", name + "_top");
|
textures.put("%top%", name + "_top");
|
||||||
textures.put("%side%", name.replace("_path", "") + "_side");
|
textures.put("%side%", name.replace("_path", "") + "_side");
|
||||||
textures.put("%bottom%", bottom);
|
textures.put("%bottom%", bottom);
|
||||||
|
@ -86,6 +89,4 @@ public abstract class BasePathBlock extends BaseBlockNotFull {
|
||||||
registerBlockModel(stateId, modelId, blockState, modelCache);
|
registerBlockModel(stateId, modelId, blockState, modelCache);
|
||||||
return ModelsHelper.createRandomTopModel(modelId);
|
return ModelsHelper.createRandomTopModel(modelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Block getBottomBlock();
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import net.minecraft.core.Registry;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
@ -44,16 +45,23 @@ import ru.bclib.client.models.PatternsHelper;
|
||||||
import ru.bclib.client.sound.BlockSounds;
|
import ru.bclib.client.sound.BlockSounds;
|
||||||
|
|
||||||
public class BaseTerrainBlock extends BaseBlock {
|
public class BaseTerrainBlock extends BaseBlock {
|
||||||
|
|
||||||
|
private final Block baseBlock;
|
||||||
private Block pathBlock;
|
private Block pathBlock;
|
||||||
|
|
||||||
public BaseTerrainBlock(Block baseBlock, MaterialColor color) {
|
public BaseTerrainBlock(Block baseBlock, MaterialColor color) {
|
||||||
super(FabricBlockSettings.copyOf(baseBlock).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
|
super(FabricBlockSettings.copyOf(baseBlock).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
|
||||||
|
this.baseBlock = baseBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPathBlock(Block roadBlock) {
|
public void setPathBlock(Block roadBlock) {
|
||||||
this.pathBlock = roadBlock;
|
this.pathBlock = roadBlock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Block getBaseBlock() {
|
||||||
|
return baseBlock;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
|
||||||
if (pathBlock != null && player.getMainHandItem().getItem().is(FabricToolTags.SHOVELS)) {
|
if (pathBlock != null && player.getMainHandItem().getItem().is(FabricToolTags.SHOVELS)) {
|
||||||
|
@ -106,12 +114,15 @@ public class BaseTerrainBlock extends BaseBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String name = resourceLocation.getPath();
|
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();
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
textures.put("%top%", "betterend:block/" + name + "_top");
|
textures.put("%top%", modId + ":block/" + path + "_top");
|
||||||
textures.put("%side%", "betterend:block/" + name + "_side");
|
textures.put("%side%", modId + ":block/" + path + "_side");
|
||||||
textures.put("%bottom%", "minecraft:block/end_stone");
|
textures.put("%bottom%", bottom);
|
||||||
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TOP_SIDE_BOTTOM, textures);
|
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TOP_SIDE_BOTTOM, textures);
|
||||||
return ModelsHelper.fromPattern(pattern);
|
return ModelsHelper.fromPattern(pattern);
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,11 +109,11 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String path = resourceLocation.getPath();
|
String path = blockId.getPath();
|
||||||
Optional<String> pattern;
|
Optional<String> pattern;
|
||||||
if (isMiddle(blockState)) {
|
if (isMiddle(blockState)) {
|
||||||
ResourceLocation topId = new ResourceLocation(resourceLocation.getNamespace(), path + "_top");
|
ResourceLocation topId = new ResourceLocation(blockId.getNamespace(), path + "_top");
|
||||||
pattern = PatternsHelper.createBlockSimple(topId);
|
pattern = PatternsHelper.createBlockSimple(topId);
|
||||||
} else {
|
} else {
|
||||||
Map<String, String> textures = Maps.newHashMap();
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue