Changing models loading (WIP)

This commit is contained in:
Aleksey 2021-05-22 23:22:02 +03:00
parent 9f98e6f3f8
commit 2c546e0038
8 changed files with 315 additions and 221 deletions

View file

@ -30,7 +30,7 @@ public class BlockProperties {
public static final IntegerProperty SIZE = IntegerProperty.create("size", 0, 7); public static final IntegerProperty SIZE = IntegerProperty.create("size", 0, 7);
public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3); public static final IntegerProperty AGE = IntegerProperty.create("age", 0, 3);
public static enum TripleShape implements StringRepresentable { public enum TripleShape implements StringRepresentable {
TOP("top", 0), TOP("top", 0),
MIDDLE("middle", 1), MIDDLE("middle", 1),
BOTTOM("bottom", 2); BOTTOM("bottom", 2);
@ -62,7 +62,7 @@ public class BlockProperties {
} }
} }
public static enum PedestalState implements StringRepresentable { public enum PedestalState implements StringRepresentable {
PEDESTAL_TOP("pedestal_top"), PEDESTAL_TOP("pedestal_top"),
COLUMN_TOP("column_top"), COLUMN_TOP("column_top"),
BOTTOM("bottom"), BOTTOM("bottom"),
@ -87,7 +87,7 @@ public class BlockProperties {
} }
} }
public static enum HydraluxShape implements StringRepresentable { public enum HydraluxShape implements StringRepresentable {
FLOWER_BIG_BOTTOM("flower_big_bottom", true), FLOWER_BIG_BOTTOM("flower_big_bottom", true),
FLOWER_BIG_TOP("flower_big_top", true), FLOWER_BIG_TOP("flower_big_top", true),
FLOWER_SMALL_BOTTOM("flower_small_bottom", true), FLOWER_SMALL_BOTTOM("flower_small_bottom", true),
@ -118,7 +118,7 @@ public class BlockProperties {
} }
} }
public static enum PentaShape implements StringRepresentable { public enum PentaShape implements StringRepresentable {
BOTTOM("bottom"), BOTTOM("bottom"),
PRE_BOTTOM("pre_bottom"), PRE_BOTTOM("pre_bottom"),
MIDDLE("middle"), MIDDLE("middle"),
@ -142,7 +142,7 @@ public class BlockProperties {
} }
} }
public static enum LumecornShape implements StringRepresentable { public enum LumecornShape implements StringRepresentable {
LIGHT_TOP("light_top", 15), LIGHT_TOP("light_top", 15),
LIGHT_TOP_MIDDLE("light_top_middle", 15), LIGHT_TOP_MIDDLE("light_top_middle", 15),
LIGHT_MIDDLE("light_middle", 15), LIGHT_MIDDLE("light_middle", 15),
@ -174,7 +174,7 @@ public class BlockProperties {
} }
} }
public static enum CactusBottom implements StringRepresentable { public enum CactusBottom implements StringRepresentable {
EMPTY("empty"), EMPTY("empty"),
SAND("sand"), SAND("sand"),
MOSS("moss"); MOSS("moss");

View file

@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import ru.betterend.blocks.basis.EndTerrainBlock;
import ru.betterend.registry.EndParticles; import ru.betterend.registry.EndParticles;
public class ShadowGrassBlock extends EndTerrainBlock { public class ShadowGrassBlock extends EndTerrainBlock {

View file

@ -1,66 +1,90 @@
package ru.betterend.blocks; package ru.betterend.blocks.basis;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.BlockPos; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.Registry; import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.world.item.ItemStack; import net.minecraft.core.BlockPos;
import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.core.Registry;
import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.blocks.basis.BlockBaseNotFull; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.betterend.client.models.Patterns; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
public class EndPathBlock extends BlockBaseNotFull { import org.jetbrains.annotations.Nullable;
private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16); import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public EndPathBlock(Block source) {
super(FabricBlockSettings.copyOf(source).isValidSpawn((state, world, pos, type) -> { return false; })); public class EndPathBlock extends BlockBaseNotFull {
if (source instanceof EndTerrainBlock) { private static final VoxelShape SHAPE = Block.box(0, 0, 0, 16, 15, 16);
EndTerrainBlock terrain = (EndTerrainBlock) source;
terrain.setPathBlock(this); public EndPathBlock(Block source) {
} super(FabricBlockSettings.copyOf(source).isValidSpawn((state, world, pos, type) -> { return false; }));
} if (source instanceof EndTerrainBlock) {
EndTerrainBlock terrain = (EndTerrainBlock) source;
@Override terrain.setPathBlock(this);
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { }
ItemStack tool = builder.getParameter(LootContextParams.TOOL); }
if (tool != null && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Collections.singletonList(new ItemStack(this)); @Override
} public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(Blocks.END_STONE)); ItemStack tool = builder.getParameter(LootContextParams.TOOL);
} if (tool != null && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
return Collections.singletonList(new ItemStack(this));
@Override }
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return Collections.singletonList(new ItemStack(Blocks.END_STONE));
return SHAPE; }
}
@Override
@Override public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
public VoxelShape getCollisionShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { return SHAPE;
return SHAPE; }
}
@Override
@Override public VoxelShape getCollisionShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
public Optional<String> getModelString(String block) { return SHAPE;
String name = Registry.BLOCK.getKey(this).getPath(); }
Map<String, String> map = Maps.newHashMap();
map.put("%top%", name + "_top"); @Override
map.put("%side%", name.replace("_path", "") + "_side"); public Optional<String> getModelString(String block) {
return Patterns.createJson(Patterns.BLOCK_PATH, map); String name = Registry.BLOCK.getKey(this).getPath();
} Map<String, String> map = Maps.newHashMap();
map.put("%top%", name + "_top");
} map.put("%side%", name.replace("_path", "") + "_side");
return Patterns.createJson(Patterns.BLOCK_PATH, map);
}
@Override
public BlockModel getModel(ResourceLocation blockId) {
return getBlockModel(blockId, defaultBlockState());
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String name = resourceLocation.getPath();
Map<String, String> textures = Maps.newHashMap();
textures.put("%top%", name + "_top");
textures.put("%side%", name.replace("_path", "") + "_side");
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_PATH, textures);
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(), "block/" + resourceLocation.getPath());
return ModelsHelper.createRandomTopModel(modelId);
}
}

View file

@ -1,103 +1,130 @@
package ru.betterend.blocks; package ru.betterend.blocks.basis;
import java.util.*; import java.util.*;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockPos; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.Direction; import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel; import net.minecraft.core.Direction;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.core.Registry;
import net.minecraft.sounds.SoundEvents; import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundSource; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionResult; import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.player.Player; import net.minecraft.sounds.SoundSource;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.InteractionHand;
import net.minecraft.world.item.enchantment.EnchantmentHelper; import net.minecraft.world.InteractionResult;
import net.minecraft.world.item.enchantment.Enchantments; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.LevelReader; import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.block.Block; import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SnowLayerBlock; import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.lighting.LayerLightEngine; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.block.SnowLayerBlock;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.lighting.LayerLightEngine;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.level.material.MaterialColor;
import ru.betterend.blocks.basis.BlockBase; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.client.models.Patterns; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.BlockHitResult;
public class EndTerrainBlock extends BlockBase { import org.jetbrains.annotations.Nullable;
private Block pathBlock; import ru.betterend.blocks.BlockSounds;
import ru.betterend.blocks.basis.BlockBase;
public EndTerrainBlock(MaterialColor color) { import ru.betterend.client.models.ModelsHelper;
super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks()); import ru.betterend.client.models.Patterns;
}
public class EndTerrainBlock extends BlockBase {
public void setPathBlock(Block roadBlock) { private Block pathBlock;
this.pathBlock = roadBlock;
} public EndTerrainBlock(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.END_STONE).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
@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)) { public void setPathBlock(Block roadBlock) {
world.playSound(player, pos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F); this.pathBlock = roadBlock;
if (!world.isClientSide) { }
world.setBlockAndUpdate(pos, pathBlock.defaultBlockState());
if (!player.isCreative()) { @Override
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player); public InteractionResult use(BlockState state, Level world, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
} if (pathBlock != null && player.getMainHandItem().getItem().is(FabricToolTags.SHOVELS)) {
} world.playSound(player, pos, SoundEvents.SHOVEL_FLATTEN, SoundSource.BLOCKS, 1.0F, 1.0F);
return InteractionResult.SUCCESS; if (!world.isClientSide) {
} world.setBlockAndUpdate(pos, pathBlock.defaultBlockState());
return InteractionResult.FAIL; if (!player.isCreative()) {
} player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
}
@Override }
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { return InteractionResult.SUCCESS;
ItemStack tool = builder.getParameter(LootContextParams.TOOL); }
if (tool != null && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) { return InteractionResult.FAIL;
return Collections.singletonList(new ItemStack(this)); }
}
return Collections.singletonList(new ItemStack(Blocks.END_STONE)); @Override
} public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
@Override if (tool != null && EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) { return Collections.singletonList(new ItemStack(this));
if (random.nextInt(16) == 0 && !canStay(state, world, pos)) { }
world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); return Collections.singletonList(new ItemStack(Blocks.END_STONE));
} }
}
@Override
public boolean canStay(BlockState state, LevelReader worldView, BlockPos pos) { public void randomTick(BlockState state, ServerLevel world, BlockPos pos, Random random) {
BlockPos blockPos = pos.above(); if (random.nextInt(16) == 0 && !canStay(state, world, pos)) {
BlockState blockState = worldView.getBlockState(blockPos); world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState());
if (blockState.is(Blocks.SNOW) && (Integer) blockState.getValue(SnowLayerBlock.LAYERS) == 1) { }
return true; }
}
else if (blockState.getFluidState().getAmount() == 8) { public boolean canStay(BlockState state, LevelReader worldView, BlockPos pos) {
return false; BlockPos blockPos = pos.above();
} BlockState blockState = worldView.getBlockState(blockPos);
else { if (blockState.is(Blocks.SNOW) && (Integer) blockState.getValue(SnowLayerBlock.LAYERS) == 1) {
int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos)); return true;
return i < 5; }
} else if (blockState.getFluidState().getAmount() == 8) {
} return false;
}
@Override else {
public Optional<String> getModelString(String block) { int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos));
String name = Registry.BLOCK.getKey(this).getPath(); return i < 5;
Map<String, String> map = Maps.newHashMap(); }
map.put("%top%", "betterend:block/" + name + "_top"); }
map.put("%side%", "betterend:block/" + name + "_side");
map.put("%bottom%", "minecraft:block/end_stone"); @Override
return Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, map); public Optional<String> getModelString(String block) {
} String name = Registry.BLOCK.getKey(this).getPath();
Map<String, String> map = Maps.newHashMap();
} map.put("%top%", "betterend:block/" + name + "_top");
map.put("%side%", "betterend:block/" + name + "_side");
map.put("%bottom%", "minecraft:block/end_stone");
return Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, map);
}
@Override
public BlockModel getModel(ResourceLocation blockId) {
return getBlockModel(blockId, defaultBlockState());
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String name = resourceLocation.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");
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_PATH, textures);
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(), "block/" + resourceLocation.getPath());
return ModelsHelper.createRandomTopModel(modelId);
}
}

View file

@ -1,14 +1,23 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Random; import java.util.Random;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.mojang.math.Transformation;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.MultiVariant;
import net.minecraft.client.renderer.block.model.Variant;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResult;
@ -23,9 +32,10 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty; import net.minecraft.world.level.block.state.properties.EnumProperty;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties;
import ru.betterend.blocks.BlockProperties.TripleShape; import ru.betterend.blocks.BlockProperties.TripleShape;
import ru.betterend.blocks.EndTerrainBlock; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns; import ru.betterend.client.models.Patterns;
public class TripleTerrainBlock extends EndTerrainBlock { public class TripleTerrainBlock extends EndTerrainBlock {
@ -47,19 +57,6 @@ public class TripleTerrainBlock extends EndTerrainBlock {
TripleShape shape = dir == Direction.UP ? TripleShape.BOTTOM : dir == Direction.DOWN ? TripleShape.TOP : TripleShape.MIDDLE; TripleShape shape = dir == Direction.UP ? TripleShape.BOTTOM : dir == Direction.DOWN ? TripleShape.TOP : TripleShape.MIDDLE;
return this.defaultBlockState().setValue(SHAPE, shape); return this.defaultBlockState().setValue(SHAPE, shape);
} }
@Override
public Optional<String> getModelString(String block) {
String name = Registry.BLOCK.getKey(this).getPath();
if (block.endsWith("_middle")) {
return Patterns.createJson(Patterns.BLOCK_BASE, name + "_top", name + "_top");
}
Map<String, String> map = Maps.newHashMap();
map.put("%top%", "betterend:block/" + name + "_top");
map.put("%side%", "betterend:block/" + name + "_side");
map.put("%bottom%", "minecraft:block/end_stone");
return Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, map);
}
@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) {
@ -75,9 +72,7 @@ public class TripleTerrainBlock extends EndTerrainBlock {
TripleShape shape = state.getValue(SHAPE); TripleShape shape = state.getValue(SHAPE);
if (shape == TripleShape.BOTTOM) { if (shape == TripleShape.BOTTOM) {
super.randomTick(state, world, pos, random); super.randomTick(state, world, pos, random);
return; } else if (random.nextInt(16) == 0) {
}
else if (random.nextInt(16) == 0) {
boolean bottom = canStayBottom(world, pos); boolean bottom = canStayBottom(world, pos);
if (shape == TripleShape.TOP) { if (shape == TripleShape.TOP) {
if (!bottom) { if (!bottom) {
@ -88,11 +83,9 @@ public class TripleTerrainBlock extends EndTerrainBlock {
boolean top = canStay(state, world, pos) || isMiddle(world.getBlockState(pos.above())); boolean top = canStay(state, world, pos) || isMiddle(world.getBlockState(pos.above()));
if (!top && !bottom) { if (!top && !bottom) {
world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState()); world.setBlockAndUpdate(pos, Blocks.END_STONE.defaultBlockState());
} } else if (top && !bottom) {
else if (top && !bottom) {
world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.BOTTOM)); world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.BOTTOM));
} } else if (!top) {
else if (!top && bottom) {
world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.TOP)); world.setBlockAndUpdate(pos, state.setValue(SHAPE, TripleShape.TOP));
} }
} }
@ -104,16 +97,72 @@ public class TripleTerrainBlock extends EndTerrainBlock {
BlockState blockState = world.getBlockState(blockPos); BlockState blockState = world.getBlockState(blockPos);
if (isMiddle(blockState)) { if (isMiddle(blockState)) {
return true; return true;
} } else if (blockState.getFluidState().getAmount() == 8) {
else if (blockState.getFluidState().getAmount() == 8) {
return false; return false;
} } else {
else {
return !blockState.isFaceSturdy(world, blockPos, Direction.UP); return !blockState.isFaceSturdy(world, blockPos, Direction.UP);
} }
} }
protected boolean isMiddle(BlockState state) { @Override
return state.is(this) && state.getValue(SHAPE) == TripleShape.MIDDLE; public Optional<String> getModelString(String block) {
String name = Registry.BLOCK.getKey(this).getPath();
if (block.endsWith("_middle")) {
return Patterns.createJson(Patterns.BLOCK_BASE, name + "_top", name + "_top");
}
Map<String, String> map = Maps.newHashMap();
map.put("%top%", "betterend:block/" + name + "_top");
map.put("%side%", "betterend:block/" + name + "_side");
map.put("%bottom%", "minecraft:block/end_stone");
return Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, map);
}
@Override
public BlockModel getModel(ResourceLocation blockId) {
return getBlockModel(blockId, defaultBlockState());
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String name = resourceLocation.getPath();
Optional<String> pattern;
if (isMiddle(blockState)) {
pattern = Patterns.createBlockSimple(name + "_top");
} else {
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");
pattern = Patterns.createJson(Patterns.BLOCK_TOP_SIDE_BOTTOM, textures);
}
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
boolean isMiddle = isMiddle(blockState);
String middle = isMiddle ? "_middle" : "";
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath() + middle);
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
if (isMiddle) {
List<Variant> variants = Lists.newArrayList();
for (BlockModelRotation rotation : BlockModelRotation.values()) {
variants.add(new Variant(modelId, rotation.getRotation(), false, 1));
}
return new MultiVariant(variants);
} else if (blockState.getValue(SHAPE) == TripleShape.TOP) {
return new MultiVariant(Lists.newArrayList(
new Variant(modelId, BlockModelRotation.X180_Y0.getRotation(), false, 1),
new Variant(modelId, BlockModelRotation.X180_Y90.getRotation(), false, 1),
new Variant(modelId, BlockModelRotation.X180_Y180.getRotation(), false, 1),
new Variant(modelId, BlockModelRotation.X180_Y270.getRotation(), false, 1)
));
}
return ModelsHelper.createRandomTopModel(modelId);
}
protected boolean isMiddle(BlockState blockState) {
return blockState.is(this) && blockState.getValue(SHAPE) == TripleShape.MIDDLE;
} }
} }

View file

@ -69,6 +69,15 @@ public class ModelsHelper {
return createMultiVariant(resourceLocation, rotation.getRotation(), false); return createMultiVariant(resourceLocation, rotation.getRotation(), false);
} }
public static MultiVariant createRandomTopModel(ResourceLocation resourceLocation) {
return new MultiVariant(Lists.newArrayList(
new Variant(resourceLocation, Transformation.identity(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y90.getRotation(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y180.getRotation(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y270.getRotation(), false, 1)
));
}
public static class MultiPartBuilder { public static class MultiPartBuilder {
private final static MultiPartBuilder BUILDER = new MultiPartBuilder(); private final static MultiPartBuilder BUILDER = new MultiPartBuilder();

View file

@ -11,23 +11,7 @@ import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.blocks.*; import ru.betterend.blocks.*;
import ru.betterend.blocks.basis.EndAnvilBlock; import ru.betterend.blocks.basis.*;
import ru.betterend.blocks.basis.EndCropBlock;
import ru.betterend.blocks.basis.EndFurnaceBlock;
import ru.betterend.blocks.basis.EndLeavesBlock;
import ru.betterend.blocks.basis.EndOreBlock;
import ru.betterend.blocks.basis.EndPillarBlock;
import ru.betterend.blocks.basis.EndSlabBlock;
import ru.betterend.blocks.basis.EndStairsBlock;
import ru.betterend.blocks.basis.EndUnderwaterWallPlantBlock;
import ru.betterend.blocks.basis.EndWallPlantBlock;
import ru.betterend.blocks.basis.FurBlock;
import ru.betterend.blocks.basis.SimpleLeavesBlock;
import ru.betterend.blocks.basis.StalactiteBlock;
import ru.betterend.blocks.basis.StoneLanternBlock;
import ru.betterend.blocks.basis.TripleTerrainBlock;
import ru.betterend.blocks.basis.VineBlock;
import ru.betterend.blocks.basis.WallMushroomBlock;
import ru.betterend.blocks.complex.ColoredMaterial; import ru.betterend.blocks.complex.ColoredMaterial;
import ru.betterend.blocks.complex.CrystalSubblocksMaterial; import ru.betterend.blocks.complex.CrystalSubblocksMaterial;
import ru.betterend.blocks.complex.MetalMaterial; import ru.betterend.blocks.complex.MetalMaterial;

View file

@ -27,7 +27,7 @@ import net.minecraft.world.level.block.LeavesBlock;
import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration; import net.minecraft.world.level.levelgen.surfacebuilders.SurfaceBuilderConfiguration;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.blocks.EndTerrainBlock; import ru.betterend.blocks.basis.EndTerrainBlock;
import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.basis.PedestalBlock;
import ru.betterend.blocks.basis.SimpleLeavesBlock; import ru.betterend.blocks.basis.SimpleLeavesBlock;
import ru.betterend.blocks.basis.VineBlock; import ru.betterend.blocks.basis.VineBlock;