Merge branch 'experimental'

This commit is contained in:
Aleksey 2021-05-24 15:17:36 +03:00
commit df71f23d35
118 changed files with 2135 additions and 2898 deletions

View file

@ -9,7 +9,7 @@ import ru.betterend.api.BetterEndPlugin;
import ru.betterend.config.Configs; import ru.betterend.config.Configs;
import ru.betterend.effects.EndEnchantments; import ru.betterend.effects.EndEnchantments;
import ru.betterend.effects.EndPotions; import ru.betterend.effects.EndPotions;
import ru.betterend.events.PlayerAdvancementsEvents; import ru.betterend.events.PlayerAdvancementsCallback;
import ru.betterend.integration.Integrations; import ru.betterend.integration.Integrations;
import ru.betterend.item.GuideBookItem; import ru.betterend.item.GuideBookItem;
import ru.betterend.recipe.AlloyingRecipes; import ru.betterend.recipe.AlloyingRecipes;
@ -78,7 +78,7 @@ public class BetterEnd implements ModInitializer {
Configs.saveConfigs(); Configs.saveConfigs();
if (hasGuideBook()) { if (hasGuideBook()) {
PlayerAdvancementsEvents.PLAYER_ADVENCEMENT_COMPLETE.register((player, advancement, criterionName) -> { PlayerAdvancementsCallback.PLAYER_ADVANCEMENT_COMPLETE.register((player, advancement, criterionName) -> {
ResourceLocation advId = new ResourceLocation("minecraft:end/enter_end_gateway"); ResourceLocation advId = new ResourceLocation("minecraft:end/enter_end_gateway");
if (advId.equals(advancement.getId())) { if (advId.equals(advancement.getId())) {
player.addItem(new ItemStack(GuideBookItem.GUIDE_BOOK)); player.addItem(new ItemStack(GuideBookItem.GUIDE_BOOK));
@ -102,6 +102,10 @@ public class BetterEnd implements ModInitializer {
public static String getStringId(String id) { public static String getStringId(String id) {
return String.format("%s:%s", MOD_ID, id); return String.format("%s:%s", MOD_ID, id);
} }
public static boolean isModId(ResourceLocation id) {
return id.getNamespace().equals(MOD_ID);
}
public static boolean isDevEnvironment() { public static boolean isDevEnvironment() {
return FabricLoader.getInstance().isDevelopmentEnvironment(); return FabricLoader.getInstance().isDevelopmentEnvironment();

View file

@ -1,35 +1,57 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import com.google.common.collect.Maps;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.basis.EndAnvilBlock; import ru.betterend.blocks.basis.EndAnvilBlock;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
import ru.betterend.item.material.EndToolMaterial; import ru.betterend.item.material.EndToolMaterial;
import ru.betterend.patterns.Patterns;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import java.util.Map;
import java.util.Optional;
public class AeterniumAnvil extends EndAnvilBlock { public class AeterniumAnvil extends EndAnvilBlock {
private static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION_LONG; private static final IntegerProperty DESTRUCTION_LONG = BlockProperties.DESTRUCTION_LONG;
public AeterniumAnvil() { public AeterniumAnvil() {
super(EndBlocks.AETERNIUM_BLOCK.defaultMaterialColor(), EndToolMaterial.AETERNIUM.getLevel()); super(EndBlocks.AETERNIUM_BLOCK.defaultMaterialColor(), EndToolMaterial.AETERNIUM.getLevel());
} }
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(DESTRUCTION);
builder.add(FACING);
}
@Override @Override
public IntegerProperty getDestructionProperty() { public IntegerProperty getDestructionProperty() {
return DESTRUCTION; return DESTRUCTION_LONG;
} }
@Override @Override
public ResourceLocation statePatternId() { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
return Patterns.STATE_ANVIL_LONG; String name = blockId.getPath();
int damage = getDamageState(blockState);
Map<String, String> textures = Maps.newHashMap();
textures.put("%anvil%", name);
textures.put("%top%", name + "_top_" + damage);
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_ANVIL, textures);
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
int damage = getDamageState(blockState);
String modId = stateId.getNamespace();
String modelId = "block/" + stateId.getPath() + "_top_" + damage;
ResourceLocation modelLocation = new ResourceLocation(modId, modelId);
registerBlockModel(stateId, modelLocation, blockState, modelCache);
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING), false, false);
}
private int getDamageState(BlockState blockState) {
IntegerProperty destructionProperty = getDestructionProperty();
int damage = blockState.getValue(destructionProperty);
return damage < 3 ? 0 : damage < 6 ? 1 : 2;
} }
} }

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

@ -1,12 +1,13 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.io.Reader;
import java.util.Map; import java.util.Map;
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.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -18,13 +19,15 @@ import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.basis.EndLanternBlock; import ru.betterend.blocks.basis.EndLanternBlock;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class BulbVineLanternBlock extends EndLanternBlock implements IRenderTypeable, BlockPatterned { public class BulbVineLanternBlock extends EndLanternBlock implements IRenderTypeable, BlockModelProvider {
private static final VoxelShape SHAPE_CEIL = Block.box(4, 4, 4, 12, 16, 12); private static final VoxelShape SHAPE_CEIL = Block.box(4, 4, 4, 12, 16, 12);
private static final VoxelShape SHAPE_FLOOR = Block.box(4, 0, 4, 12, 12, 12); private static final VoxelShape SHAPE_FLOOR = Block.box(4, 0, 4, 12, 12, 12);
@ -52,25 +55,16 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @Override
public String getStatesPattern(Reader data) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); Map<String, String> textures = Maps.newHashMap();
return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); textures.put("%glow%", getGlowTexture());
} textures.put("%metal%", getMetalTexture(resourceLocation));
Optional<String> pattern = blockState.getValue(IS_FLOOR) ?
@Override Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_FLOOR, textures) :
public String getModelPattern(String block) { Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_CEIL, textures);
ResourceLocation blockId = Registry.BLOCK.getKey(this); return ModelsHelper.fromPattern(pattern);
Map<String, String> map = Maps.newHashMap();
map.put("%glow%", getGlowTexture());
map.put("%metal%", getMetalTexture(blockId));
if (block.contains("item") || block.contains("ceil")) {
return Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_CEIL, map);
}
else {
return Patterns.createJson(Patterns.BLOCK_BULB_LANTERN_FLOOR, map);
}
} }
protected String getMetalTexture(ResourceLocation blockId) { protected String getMetalTexture(ResourceLocation blockId) {
@ -82,9 +76,5 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType
protected String getGlowTexture() { protected String getGlowTexture() {
return "bulb_vine_lantern_bulb"; return "bulb_vine_lantern_bulb";
} }
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_BULB_LANTERN;
}
} }

View file

@ -14,16 +14,12 @@ public class BulbVineLanternColoredBlock extends BulbVineLanternBlock implements
@Override @Override
public BlockColor getProvider() { public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> { return (state, world, pos, tintIndex) -> getColor();
return getColor();
};
} }
@Override @Override
public ItemColor getItemProvider() { public ItemColor getItemProvider() {
return (stack, tintIndex) -> { return (stack, tintIndex) -> getColor();
return getColor();
};
} }
private int getColor() { private int getColor() {

View file

@ -1,11 +1,15 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.io.Reader;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.Map;
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.client.renderer.block.model.BlockModel;
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;
@ -16,13 +20,15 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.Shapes; import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.basis.AttachedBlock; import ru.betterend.blocks.basis.AttachedBlock;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class ChandelierBlock extends AttachedBlock implements IRenderTypeable, BlockPatterned { public class ChandelierBlock extends AttachedBlock implements IRenderTypeable, BlockModelProvider {
private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class); private static final EnumMap<Direction, VoxelShape> BOUNDING_SHAPES = Maps.newEnumMap(Direction.class);
public ChandelierBlock(Block source) { public ChandelierBlock(Block source) {
@ -38,35 +44,55 @@ public class ChandelierBlock extends AttachedBlock implements IRenderTypeable, B
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return BOUNDING_SHAPES.get(state.getValue(FACING)); return BOUNDING_SHAPES.get(state.getValue(FACING));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation blockId) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); return ModelsHelper.createItemModel(blockId.getPath());
return Patterns.createJson(data, blockId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); Optional<String> pattern;
if (block.contains("item")) { switch (blockState.getValue(FACING)) {
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/" + blockId.getPath()); case UP:
} pattern = Patterns.createJson(Patterns.BLOCK_CHANDELIER_FLOOR, resourceLocation.getPath());
else if (block.contains("ceil")) { break;
return Patterns.createJson(Patterns.BLOCK_CHANDELIER_CEIL, blockId.getPath()); case DOWN:
} pattern = Patterns.createJson(Patterns.BLOCK_CHANDELIER_CEIL, resourceLocation.getPath());
else if (block.contains("wall")) { break;
return Patterns.createJson(Patterns.BLOCK_CHANDELIER_WALL, blockId.getPath()); default:
} pattern = Patterns.createJson(Patterns.BLOCK_CHANDELIER_WALL, resourceLocation.getPath());
else {
return Patterns.createJson(Patterns.BLOCK_CHANDELIER_FLOOR, blockId.getPath());
} }
return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_CHANDELIER; String state = "_wall";
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
switch (blockState.getValue(FACING)) {
case UP:
state = "_floor";
break;
case DOWN:
state = "_ceil";
break;
case EAST:
rotation = BlockModelRotation.X0_Y270;
break;
case NORTH:
rotation = BlockModelRotation.X0_Y180;
break;
case WEST:
rotation = BlockModelRotation.X0_Y90;
break;
}
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + state);
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
} }
static { static {
BOUNDING_SHAPES.put(Direction.UP, Block.box(5, 0, 5, 11, 13, 11)); BOUNDING_SHAPES.put(Direction.UP, Block.box(5, 0, 5, 11, 13, 11));
BOUNDING_SHAPES.put(Direction.DOWN, Block.box(5, 3, 5, 11, 16, 11)); BOUNDING_SHAPES.put(Direction.DOWN, Block.box(5, 3, 5, 11, 16, 11));

View file

@ -1,10 +1,11 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Random; import java.util.Random;
import net.minecraft.client.renderer.block.model.BlockModel;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
@ -25,12 +26,13 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class EmeraldIceBlock extends HalfTransparentBlock implements IRenderTypeable, BlockPatterned { public class EmeraldIceBlock extends HalfTransparentBlock implements IRenderTypeable, BlockModelProvider {
public EmeraldIceBlock() { public EmeraldIceBlock() {
super(FabricBlockSettings.copyOf(Blocks.ICE)); super(FabricBlockSettings.copyOf(Blocks.ICE));
} }
@ -85,21 +87,9 @@ public class EmeraldIceBlock extends HalfTransparentBlock implements IRenderType
return Collections.emptyList(); return Collections.emptyList();
} }
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
String block = Registry.BLOCK.getKey(this).getPath(); return getBlockModel(resourceLocation, defaultBlockState());
return Patterns.createJson(data, block, block);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
} }
} }

View file

@ -8,19 +8,18 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.basis.PedestalBlock;
import ru.betterend.patterns.Patterns;
public class EndPedestal extends PedestalBlock { public class EndPedestal extends PedestalBlock {
public EndPedestal(Block parent) { public EndPedestal(Block parent) {
super(parent); super(parent);
} }
@Override @Override
public String getModelPattern(String block) { protected Map<String, String> createTexturesMap() {
ResourceLocation blockId = Registry.BLOCK.getKey(parent); ResourceLocation blockId = Registry.BLOCK.getKey(parent);
String name = blockId.getPath(); String name = blockId.getPath();
Map<String, String> textures = new HashMap<String, String>() { return new HashMap<String, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
{ {
put("%mod%", BetterEnd.MOD_ID ); put("%mod%", BetterEnd.MOD_ID );
@ -30,17 +29,5 @@ public class EndPedestal extends PedestalBlock {
put("%bottom%", name + "_polished"); put("%bottom%", name + "_polished");
} }
}; };
if (block.contains("column_top")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_COLUMN_TOP, textures);
} else if (block.contains("column")) {
return Patterns.createJson(Patterns.BLOKC_PEDESTAL_COLUMN, textures);
} else if (block.contains("top")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_TOP, textures);
} else if (block.contains("bottom")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_BOTTOM, textures);
} else if (block.contains("pillar")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_PILLAR, textures);
}
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
} }
} }

View file

@ -1,13 +1,17 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.io.Reader; import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor; import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IColorProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.util.BlocksHelper; import ru.betterend.util.BlocksHelper;
public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements IColorProvider { public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements IColorProvider {
@ -28,21 +32,11 @@ public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements ICo
return BlocksHelper.getBlockColor(this); return BlocksHelper.getBlockColor(this);
}; };
} }
@Override @Override
public String getStatesPattern(Reader data) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String path = "betterend:block/block_petal_colored"; String path = "betterend:block/block_petal_colored";
return Patterns.createJson(data, path, path); Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_PETAL_COLORED, path, path);
} return ModelsHelper.fromPattern(pattern);
@Override
public String getModelPattern(String block) {
String path = "betterend:block/block_petal_colored";
return Patterns.createJson(Patterns.BLOCK_PETAL_COLORED, path, path);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_DIRECT;
} }
} }

View file

@ -1,14 +1,14 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.io.Reader;
import java.util.List; import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor; import net.minecraft.client.color.item.ItemColor;
import net.minecraft.core.Registry; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
@ -21,15 +21,17 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IColorProvider;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class JellyshroomCapBlock extends SlimeBlock implements IRenderTypeable, BlockPatterned, IColorProvider { public class JellyshroomCapBlock extends SlimeBlock implements IRenderTypeable, BlockModelProvider, IColorProvider {
public static final IntegerProperty COLOR = BlockProperties.COLOR; public static final IntegerProperty COLOR = BlockProperties.COLOR;
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0); private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0);
private final Vec3i colorStart; private final Vec3i colorStart;
@ -65,23 +67,18 @@ public class JellyshroomCapBlock extends SlimeBlock implements IRenderTypeable,
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Lists.newArrayList(new ItemStack(this)); return Lists.newArrayList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
String block = Registry.BLOCK.getKey(this).getPath(); return getBlockModel(resourceLocation, defaultBlockState());
return Patterns.createJson(data, block, block);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
return Patterns.createJson(Patterns.BLOCK_COLORED, "jellyshroom_cap"); Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_COLORED, "jellyshroom_cap");
return ModelsHelper.fromPattern(pattern);
} }
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
}
@Override @Override
public BlockColor getProvider() { public BlockColor getProvider() {
return (state, world, pos, tintIndex) -> { return (state, world, pos, tintIndex) -> {

View file

@ -7,19 +7,18 @@ import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import ru.betterend.blocks.basis.PedestalBlock; import ru.betterend.blocks.basis.PedestalBlock;
import ru.betterend.patterns.Patterns;
public class PedestalVanilla extends PedestalBlock { public class PedestalVanilla extends PedestalBlock {
public PedestalVanilla(Block parent) { public PedestalVanilla(Block parent) {
super(parent); super(parent);
} }
@Override @Override
public String getModelPattern(String block) { protected Map<String, String> createTexturesMap() {
ResourceLocation blockId = Registry.BLOCK.getKey(parent); ResourceLocation blockId = Registry.BLOCK.getKey(parent);
String name = blockId.getPath().replace("_block", ""); String name = blockId.getPath().replace("_block", "");
Map<String, String> textures = new HashMap<String, String>() { return new HashMap<String, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
{ {
put("%mod%", blockId.getNamespace() ); put("%mod%", blockId.getNamespace() );
@ -29,17 +28,5 @@ public class PedestalVanilla extends PedestalBlock {
put("%bottom%", "polished_" + name); put("%bottom%", "polished_" + name);
} }
}; };
if (block.contains("column_top")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_COLUMN_TOP, textures);
} else if (block.contains("column")) {
return Patterns.createJson(Patterns.BLOKC_PEDESTAL_COLUMN, textures);
} else if (block.contains("top")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_TOP, textures);
} else if (block.contains("bottom")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_BOTTOM, textures);
} else if (block.contains("pillar")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_PILLAR, textures);
}
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
} }
} }

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,14 +1,15 @@
package ru.betterend.blocks; package ru.betterend.blocks;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
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;
@ -26,12 +27,12 @@ import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.noise.OpenSimplexNoise; import ru.betterend.noise.OpenSimplexNoise;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class UmbrellaTreeMembraneBlock extends SlimeBlock implements IRenderTypeable, BlockPatterned { public class UmbrellaTreeMembraneBlock extends SlimeBlock implements IRenderTypeable, BlockModelProvider {
public static final IntegerProperty COLOR = BlockProperties.COLOR; public static final IntegerProperty COLOR = BlockProperties.COLOR;
private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0); private static final OpenSimplexNoise NOISE = new OpenSimplexNoise(0);
@ -66,23 +67,6 @@ public class UmbrellaTreeMembraneBlock extends SlimeBlock implements IRenderType
return MHelper.RANDOM.nextInt(4) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.UMBRELLA_TREE_SAPLING)) : Collections.emptyList(); return MHelper.RANDOM.nextInt(4) == 0 ? Lists.newArrayList(new ItemStack(EndBlocks.UMBRELLA_TREE_SAPLING)) : Collections.emptyList();
} }
} }
@Override
public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, block, block);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
}
@Override @Override
public boolean propagatesSkylightDown(BlockState state, BlockGetter world, BlockPos pos) { public boolean propagatesSkylightDown(BlockState state, BlockGetter world, BlockPos pos) {
@ -98,4 +82,9 @@ public class UmbrellaTreeMembraneBlock extends SlimeBlock implements IRenderType
return false; return false;
} }
} }
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return getBlockModel(resourceLocation, defaultBlockState());
}
} }

View file

@ -1,28 +1,22 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader; import java.util.Optional;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class BarkBlock extends EndPillarBlock { public class BarkBlock extends EndPillarBlock {
public BarkBlock(Properties settings) { public BarkBlock(Properties settings) {
super(settings); super(settings);
} }
@Override @Override
public String getModelPattern(String block) { protected Optional<String> createBlockPattern(ResourceLocation blockId) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, getName(blockId), blockId.getPath()); return Patterns.createJson(Patterns.BLOCK_BASE, getName(blockId), blockId.getPath());
} }
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(data, getName(blockId), blockId.getPath());
}
private String getName(ResourceLocation blockId) { private String getName(ResourceLocation blockId) {
String name = blockId.getPath(); String name = blockId.getPath();
return name.replace("_bark", "_log_side"); return name.replace("_bark", "_log_side");

View file

@ -1,42 +1,31 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader; import java.util.Collections;
import java.util.Collections; import java.util.List;
import java.util.List; import java.util.Optional;
import net.minecraft.core.Registry; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.core.Registry;
import net.minecraft.world.item.ItemStack; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.block.state.BlockState;
import ru.betterend.patterns.BlockPatterned; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.Patterns;
public class BlockBase extends Block implements BlockPatterned {
public BlockBase(Properties settings) { public class BlockBase extends Block implements BlockModelProvider {
super(settings); public BlockBase(Properties settings) {
} super(settings);
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { @Override
return Collections.singletonList(new ItemStack(this)); public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
} return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) { @Override
String block = Registry.BLOCK.getKey(this).getPath(); public BlockModel getItemModel(ResourceLocation blockId) {
return Patterns.createJson(data, block, block); return getBlockModel(blockId, defaultBlockState());
} }
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
}
}

View file

@ -1,13 +1,15 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
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 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.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -19,11 +21,13 @@ import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty; import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndAnvilBlock extends AnvilBlock implements BlockPatterned { public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
private static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION; private static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION;
protected final int level; protected final int level;
@ -35,7 +39,7 @@ public class EndAnvilBlock extends AnvilBlock implements BlockPatterned {
@Override @Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
super.createBlockStateDefinition(builder); super.createBlockStateDefinition(builder);
builder.add(DESTRUCTION); builder.add(getDestructionProperty());
} }
public IntegerProperty getDestructionProperty() { public IntegerProperty getDestructionProperty() {
@ -53,21 +57,6 @@ public class EndAnvilBlock extends AnvilBlock implements BlockPatterned {
stack.getOrCreateTag().putInt("level", level); stack.getOrCreateTag().putInt("level", level);
return Collections.singletonList(stack); return Collections.singletonList(stack);
} }
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(data, blockId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
Map<String, String> map = Maps.newHashMap();
map.put("%anvil%", blockId.getPath());
map.put("%top%", getTop(blockId, block));
return Patterns.createJson(Patterns.BLOCK_ANVIL, map);
}
protected String getTop(ResourceLocation blockId, String block) { protected String getTop(ResourceLocation blockId, String block) {
if (block.contains("item")) { if (block.contains("item")) {
@ -76,9 +65,32 @@ public class EndAnvilBlock extends AnvilBlock implements BlockPatterned {
char last = block.charAt(block.length() - 1); char last = block.charAt(block.length() - 1);
return blockId.getPath() + "_top_" + last; return blockId.getPath() + "_top_" + last;
} }
@Override @Override
public ResourceLocation statePatternId() { public BlockModel getItemModel(ResourceLocation blockId) {
return Patterns.STATE_ANVIL; return getBlockModel(blockId, defaultBlockState());
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
IntegerProperty destructionProperty = getDestructionProperty();
int destruction = blockState.getValue(destructionProperty);
String name = blockId.getPath();
Map<String, String> textures = Maps.newHashMap();
textures.put("%anvil%", name);
textures.put("%top%", name + "_top_" + destruction);
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_ANVIL, textures);
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
IntegerProperty destructionProperty = getDestructionProperty();
int destruction = blockState.getValue(destructionProperty);
String modId = stateId.getNamespace();
String modelId = "block/" + stateId.getPath() + "_top_" + destruction;
ResourceLocation modelLocation = new ResourceLocation(modId, modelId);
registerBlockModel(stateId, modelLocation, blockState, modelCache);
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING), false, false);
} }
} }

View file

@ -1,11 +1,16 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Random; import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
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.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
@ -25,12 +30,14 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.BlockHitResult; import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.entities.EBarrelBlockEntity; import ru.betterend.blocks.entities.EBarrelBlockEntity;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndBlockEntities; import ru.betterend.registry.EndBlockEntities;
public class EndBarrelBlock extends BarrelBlock implements BlockPatterned { public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
public EndBarrelBlock(Block source) { public EndBarrelBlock(Block source) {
super(FabricBlockSettings.copyOf(source).noOcclusion()); super(FabricBlockSettings.copyOf(source).noOcclusion());
} }
@ -87,24 +94,39 @@ public class EndBarrelBlock extends BarrelBlock implements BlockPatterned {
} }
} }
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation blockId) {
String block = Registry.BLOCK.getKey(this).getPath(); return getBlockModel(blockId, defaultBlockState());
return Patterns.createJson(data, block, block);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
String texture = Registry.BLOCK.getKey(this).getPath(); String texture = blockId.getPath();
if (block.contains("open")) { Optional<String> pattern;
return Patterns.createJson(Patterns.BLOCK_BARREL_OPEN, texture, texture); if (blockState.getValue(OPEN)) {
pattern = Patterns.createJson(Patterns.BLOCK_BARREL_OPEN, texture, texture);
} else {
pattern = Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture);
} }
return Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture); return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_BARREL; String open = blockState.getValue(OPEN) ? "_open" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + open);
registerBlockModel(stateId, modelId, blockState, modelCache);
Direction facing = blockState.getValue(FACING);
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
switch (facing) {
case NORTH: rotation = BlockModelRotation.X90_Y0; break;
case EAST: rotation = BlockModelRotation.X90_Y90; break;
case SOUTH: rotation = BlockModelRotation.X90_Y180; break;
case WEST: rotation = BlockModelRotation.X90_Y270; break;
case DOWN: rotation = BlockModelRotation.X180_Y0; break;
}
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
} }
} }

View file

@ -1,10 +1,11 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -15,7 +16,9 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.betterend.patterns.Patterns; import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndBookshelfBlock extends BlockBase { public class EndBookshelfBlock extends BlockBase {
public EndBookshelfBlock(Block source) { public EndBookshelfBlock(Block source) {
@ -33,24 +36,14 @@ public class EndBookshelfBlock extends BlockBase {
} }
return Collections.singletonList(new ItemStack(Items.BOOK, 3)); return Collections.singletonList(new ItemStack(Items.BOOK, 3));
} }
@Override @Override
public ResourceLocation statePatternId() { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
return Patterns.STATE_SIMPLE; Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_BOOKSHELF,
getName(blockId), blockId.getPath());
return ModelsHelper.fromPattern(pattern);
} }
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BOOKSHELF, getName(blockId), blockId.getPath());
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(data, getName(blockId), blockId.getPath());
}
private String getName(ResourceLocation blockId) { private String getName(ResourceLocation blockId) {
String name = blockId.getPath(); String name = blockId.getPath();
return name.replace("_bookshelf", ""); return name.replace("_bookshelf", "");

View file

@ -0,0 +1,77 @@
package ru.betterend.blocks.basis;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ButtonBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.AttachFace;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public abstract class EndButtonBlock extends ButtonBlock implements BlockModelProvider {
private final Block parent;
protected EndButtonBlock(Block parent, Properties properties, boolean sensitive) {
super(sensitive, properties);
this.parent = parent;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public BlockModel getItemModel(ResourceLocation blockId) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_BUTTON, parentId.getPath(), blockId.getPath());
return ModelsHelper.fromPattern(pattern);
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = blockState.getValue(POWERED) ?
Patterns.createJson(Patterns.BLOCK_BUTTON_PRESSED, parentId.getPath(), blockId.getPath()) :
Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String powered = blockState.getValue(POWERED) ? "_powered" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + powered);
registerBlockModel(stateId, modelId, blockState, modelCache);
AttachFace face = blockState.getValue(FACE);
boolean isCeiling = face == AttachFace.CEILING;
int x = 0, y = 0;
switch (face) {
case CEILING: x = 180; break;
case WALL: x = 90; break;
}
switch (blockState.getValue(FACING)) {
case NORTH: if (isCeiling) { y = 180; } break;
case EAST: y = isCeiling ? 270 : 90; break;
case SOUTH: if(!isCeiling) { y = 180; } break;
case WEST: y = isCeiling ? 90 : 270; break;
}
BlockModelRotation rotation = BlockModelRotation.by(x, y);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), face == AttachFace.WALL);
}
}

View file

@ -1,10 +1,14 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -13,12 +17,14 @@ import net.minecraft.world.level.block.ChainBlock;
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 net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class EndChainBlock extends ChainBlock implements BlockPatterned, IRenderTypeable { public class EndChainBlock extends ChainBlock implements BlockModelProvider, IRenderTypeable {
public EndChainBlock(MaterialColor color) { public EndChainBlock(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.CHAIN).materialColor(color)); super(FabricBlockSettings.copyOf(Blocks.CHAIN).materialColor(color));
} }
@ -27,27 +33,28 @@ public class EndChainBlock extends ChainBlock implements BlockPatterned, IRender
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation blockId) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); return ModelsHelper.createItemModel(blockId.getPath());
return Patterns.createJson(data, blockId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); String name = blockId.getPath();
if (block.contains("item")) { Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CHAIN, name, name);
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/" + blockId.getPath()); return ModelsHelper.fromPattern(pattern);
}
return Patterns.createJson(Patterns.BLOCK_CHAIN, blockId.getPath(), blockId.getPath());
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_CHAIN; Direction.Axis axis = blockState.getValue(AXIS);
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath());
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createRotatedModel(modelId, axis);
} }
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;

View file

@ -1,9 +1,10 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.List; import java.util.List;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -13,17 +14,17 @@ import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndBlockEntities; import ru.betterend.registry.EndBlockEntities;
public class EndChestBlock extends ChestBlock implements BlockPatterned { public class EndChestBlock extends ChestBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
public EndChestBlock(Block source) { public EndChestBlock(Block source) {
super(FabricBlockSettings.copyOf(source).noOcclusion(), () -> { super(FabricBlockSettings.copyOf(source).noOcclusion(), () -> EndBlockEntities.CHEST);
return EndBlockEntities.CHEST;
});
this.parent = source; this.parent = source;
} }
@ -40,26 +41,16 @@ public class EndChestBlock extends ChestBlock implements BlockPatterned {
drop.add(new ItemStack(this.asItem())); drop.add(new ItemStack(this.asItem()));
return drop; return drop;
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation blockId) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); Optional<String> pattern = Patterns.createJson(Patterns.ITEM_CHEST, blockId.getPath());
ResourceLocation parentId = Registry.BLOCK.getKey(parent); return ModelsHelper.fromPattern(pattern);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String path) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (path.contains("item")) { return ModelsHelper.createBlockEmpty(parentId);
return Patterns.createJson(Patterns.ITEM_CHEST, blockId.getPath());
}
return Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
} }
} }

View file

@ -1,10 +1,13 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -12,10 +15,13 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.ComposterBlock; import net.minecraft.world.level.block.ComposterBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.ModelsHelper.MultiPartBuilder;
import ru.betterend.client.models.Patterns;
public class EndComposterBlock extends ComposterBlock implements BlockPatterned { public class EndComposterBlock extends ComposterBlock implements BlockModelProvider {
public EndComposterBlock(Block source) { public EndComposterBlock(Block source) {
super(FabricBlockSettings.copyOf(source)); super(FabricBlockSettings.copyOf(source));
} }
@ -24,22 +30,37 @@ public class EndComposterBlock extends ComposterBlock implements BlockPatterned
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this.asItem())); return Collections.singletonList(new ItemStack(this.asItem()));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
String blockId = Registry.BLOCK.getKey(this).getPath(); return getBlockModel(resourceLocation, defaultBlockState());
return Patterns.createJson(data, blockId, blockId);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_COMPOSTER, blockId.getPath());
String blockName = blockId.getPath(); return ModelsHelper.fromPattern(pattern);
return Patterns.createJson(Patterns.BLOCK_COMPOSTER, blockName);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_COMPOSTER; ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath());
registerBlockModel(stateId, modelId, blockState, modelCache);
MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition);
LEVEL.getPossibleValues().forEach(level -> {
if (level > 0) {
ResourceLocation contentId;
if (level > 7) {
contentId = new ResourceLocation("block/composter_contents_ready");
} else {
contentId = new ResourceLocation("block/composter_contents" + level);
}
builder.part(contentId).setCondition(state -> state.getValue(LEVEL).equals(level)).add();
}
});
builder.part(modelId).add();
return builder.build();
} }
} }

View file

@ -1,11 +1,12 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -13,10 +14,12 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.CraftingTableBlock; import net.minecraft.world.level.block.CraftingTableBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndCraftingTableBlock extends CraftingTableBlock implements BlockPatterned { public class EndCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider {
public EndCraftingTableBlock(Block source) { public EndCraftingTableBlock(Block source) {
super(FabricBlockSettings.copyOf(source)); super(FabricBlockSettings.copyOf(source));
} }
@ -25,18 +28,16 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockPa
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this.asItem())); return Collections.singletonList(new ItemStack(this.asItem()));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
String blockId = Registry.BLOCK.getKey(this).getPath(); return getBlockModel(resourceLocation, defaultBlockState());
return Patterns.createJson(data, blockId, blockId);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
String blockName = blockId.getPath(); String blockName = blockId.getPath();
return Patterns.createJson(Patterns.BLOCK_SIDED, new HashMap<String, String>() { Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_SIDED, new HashMap<String, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
{ {
put("%particle%", blockName + "_front"); put("%particle%", blockName + "_front");
@ -48,10 +49,6 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockPa
put("%east%", blockName + "_side"); put("%east%", blockName + "_side");
} }
}); });
} return ModelsHelper.fromPattern(pattern);
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
} }
} }

View file

@ -1,24 +1,33 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Direction;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.DoorBlock; import net.minecraft.world.level.block.DoorBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.DoorHingeSide;
import net.minecraft.world.level.block.state.properties.DoubleBlockHalf; import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockPatterned { public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockModelProvider {
public EndDoorBlock(Block source) { public EndDoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion()); super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion());
} }
@ -35,33 +44,121 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockPat
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @Override
public String getStatesPattern(Reader data) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String blockId = Registry.BLOCK.getKey(this).getPath(); String blockName = resourceLocation.getPath();
return Patterns.createJson(data, blockId, blockId); DoorType doorType = getDoorType(blockState);
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM, blockName, blockName);
switch (doorType) {
case TOP_HINGE: {
pattern = Patterns.createJson(Patterns.BLOCK_DOOR_TOP_HINGE, blockName, blockName);
break;
}
case BOTTOM_HINGE: {
pattern = Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM_HINGE, blockName, blockName);
break;
}
case TOP: {
pattern = Patterns.createJson(Patterns.BLOCK_DOOR_TOP, blockName, blockName);
break;
}
}
return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public String getModelPattern(String block) { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String blockId = Registry.BLOCK.getKey(this).getPath(); Direction facing = blockState.getValue(FACING);
if (block.contains("item")) { DoorType doorType = getDoorType(blockState);
return Patterns.createJson(Patterns.ITEM_GENERATED, block); boolean open = blockState.getValue(OPEN);
boolean hinge = doorType.isHinge();
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
switch (facing) {
case EAST: {
if (hinge && open) {
rotation = BlockModelRotation.X0_Y90;
} else if (open) {
rotation = BlockModelRotation.X0_Y270;
}
break;
}
case SOUTH: {
if (!hinge && !open || hinge && !open) {
rotation = BlockModelRotation.X0_Y90;
} else if (hinge) {
rotation = BlockModelRotation.X0_Y180;
}
break;
}
case WEST: {
if (!hinge && !open || hinge && !open) {
rotation = BlockModelRotation.X0_Y180;
} else if (hinge) {
rotation = BlockModelRotation.X0_Y270;
} else {
rotation = BlockModelRotation.X0_Y90;
}
break;
}
case NORTH: {
if (!hinge && !open || hinge && !open) {
rotation = BlockModelRotation.X0_Y270;
} else if (!hinge) {
rotation = BlockModelRotation.X0_Y180;
}
break;
}
} }
if (block.contains("top_hinge")) { ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
return Patterns.createJson(Patterns.BLOCK_DOOR_TOP_HINGE, blockId, blockId); "block/" + stateId.getPath() + "_" + doorType);
} registerBlockModel(stateId, modelId, blockState, modelCache);
if (block.contains("bottom_hinge")) { return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
return Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM_HINGE, blockId, blockId);
}
if (block.contains("top")) {
return Patterns.createJson(Patterns.BLOCK_DOOR_TOP, blockId, blockId);
}
return Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM, blockId, blockId);
} }
@Override protected DoorType getDoorType(BlockState blockState) {
public ResourceLocation statePatternId() { boolean isHinge = isHinge(blockState.getValue(HINGE), blockState.getValue(OPEN));
return Patterns.STATE_DOOR; switch (blockState.getValue(HALF)) {
case UPPER: {
return isHinge ? DoorType.TOP_HINGE : DoorType.TOP;
}
case LOWER: {
return isHinge ? DoorType.BOTTOM_HINGE : DoorType.BOTTOM;
}
}
return DoorType.BOTTOM;
}
private boolean isHinge(DoorHingeSide hingeSide, boolean open) {
boolean isHinge = hingeSide == DoorHingeSide.RIGHT;
return isHinge && !open || !isHinge && open;
}
protected enum DoorType implements StringRepresentable {
BOTTOM_HINGE("bottom_hinge"),
TOP_HINGE("top_hinge"),
BOTTOM("bottom"),
TOP("top");
private final String name;
DoorType(String name) {
this.name = name;
}
public boolean isHinge() {
return this == BOTTOM_HINGE ||
this == TOP_HINGE;
}
@Override
public String toString() {
return getSerializedName();
}
@Override
public String getSerializedName() {
return name;
}
} }
} }

View file

@ -1,10 +1,9 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -12,10 +11,18 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceBlock; import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.ModelsHelper.MultiPartBuilder;
import ru.betterend.client.models.Patterns;
public class EndFenceBlock extends FenceBlock implements BlockPatterned { import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
public EndFenceBlock(Block source) { public EndFenceBlock(Block source) {
@ -27,29 +34,47 @@ public class EndFenceBlock extends FenceBlock implements BlockPatterned {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation blockId) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); Optional<String> pattern = Patterns.createJson(Patterns.ITEM_FENCE, parentId.getPath(), blockId.getPath());
return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (block.contains("item")) { String path = blockId.getPath();
return Patterns.createJson(Patterns.ITEM_FENCE, parentId.getPath(), blockId.getPath()); Optional<String> pattern = Optional.empty();
if (path.endsWith("_post")) {
pattern = Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath());
} }
if (block.contains("side")) { if (path.endsWith("_side")) {
return Patterns.createJson(Patterns.BLOCK_FENCE_SIDE, parentId.getPath(), blockId.getPath()); pattern = Patterns.createJson(Patterns.BLOCK_FENCE_SIDE, parentId.getPath(), blockId.getPath());
} }
return Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath()); return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_FENCE; ResourceLocation postId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_post");
ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_side");
registerBlockModel(postId, postId, blockState, modelCache);
registerBlockModel(sideId, sideId, blockState, modelCache);
MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition);
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST))
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH))
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST))
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(postId).add();
return builder.build();
} }
} }

View file

@ -1,13 +1,15 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
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.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
@ -23,17 +25,17 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.entities.EFurnaceBlockEntity; import ru.betterend.blocks.entities.EFurnaceBlockEntity;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class EndFurnaceBlock extends FurnaceBlock implements BlockPatterned, IRenderTypeable { public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider, IRenderTypeable {
public EndFurnaceBlock(Block source) { public EndFurnaceBlock(Block source) {
super(FabricBlockSettings.copyOf(source).luminance((state) -> { super(FabricBlockSettings.copyOf(source).luminance(state -> state.getValue(LIT) ? 13 : 0));
return state.getValue(LIT) ? 13 : 0;
}));
} }
@Override @Override
@ -49,33 +51,37 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockPatterned, IRe
player.awardStat(Stats.INTERACT_WITH_FURNACE); player.awardStat(Stats.INTERACT_WITH_FURNACE);
} }
} }
@Override @Override
public String getStatesPattern(Reader data) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); String blockName = blockId.getPath();
return Patterns.createJson(data, blockId.getPath(), blockId.getPath()); Map<String, String> textures = Maps.newHashMap();
} textures.put("%top%", blockName + "_top");
textures.put("%side%", blockName + "_side");
@Override Optional<String> pattern;
public String getModelPattern(String block) { if (blockState.getValue(LIT)) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); textures.put("%front%", blockName + "_front_on");
Map<String, String> map = Maps.newHashMap(); textures.put("%glow%", blockName + "_glow");
map.put("%top%", blockId.getPath() + "_top"); pattern = Patterns.createJson(Patterns.BLOCK_FURNACE_LIT, textures);
map.put("%side%", blockId.getPath() + "_side"); } else {
if (block.contains("_on")) { textures.put("%front%", blockName + "_front");
map.put("%front%", blockId.getPath() + "_front_on"); pattern = Patterns.createJson(Patterns.BLOCK_FURNACE, textures);
map.put("%glow%", blockId.getPath() + "_glow");
return Patterns.createJson(Patterns.BLOCK_FURNACE_GLOW, map);
}
else {
map.put("%front%", blockId.getPath() + "_front");
return Patterns.createJson(Patterns.BLOCK_FURNACE, map);
} }
return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public ResourceLocation statePatternId() { public BlockModel getItemModel(ResourceLocation resourceLocation) {
return Patterns.STATE_FURNACE; return getBlockModel(resourceLocation, defaultBlockState());
}
@Override
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String lit = blockState.getValue(LIT) ? "_lit" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + lit);
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), false, true);
} }
@Override @Override

View file

@ -1,10 +1,13 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -12,10 +15,12 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.FenceGateBlock; import net.minecraft.world.level.block.FenceGateBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndGateBlock extends FenceGateBlock implements BlockPatterned { public class EndGateBlock extends FenceGateBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
public EndGateBlock(Block source) { public EndGateBlock(Block source) {
@ -27,33 +32,36 @@ public class EndGateBlock extends FenceGateBlock implements BlockPatterned {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); return getBlockModel(resourceLocation, defaultBlockState());
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); boolean inWall = blockState.getValue(IN_WALL);
boolean isOpen = blockState.getValue(OPEN);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (block.contains("wall")) { Optional<String> pattern;
if (block.contains("open")) { if (inWall) {
return Patterns.createJson(Patterns.BLOCK_GATE_OPEN_WALL, parentId.getPath(), blockId.getPath()); pattern = isOpen ? Patterns.createJson(Patterns.BLOCK_GATE_OPEN_WALL, parentId.getPath(), blockId.getPath()) :
} else { Patterns.createJson(Patterns.BLOCK_GATE_CLOSED_WALL, parentId.getPath(), blockId.getPath());
return Patterns.createJson(Patterns.BLOCK_GATE_CLOSED_WALL, parentId.getPath(), blockId.getPath()); } else {
} pattern = isOpen ? Patterns.createJson(Patterns.BLOCK_GATE_OPEN, parentId.getPath(), blockId.getPath()) :
Patterns.createJson(Patterns.BLOCK_GATE_CLOSED, parentId.getPath(), blockId.getPath());
} }
if (block.contains("open")) { return ModelsHelper.fromPattern(pattern);
return Patterns.createJson(Patterns.BLOCK_GATE_OPEN, parentId.getPath(), blockId.getPath());
}
return Patterns.createJson(Patterns.BLOCK_GATE_CLOSED, parentId.getPath(), blockId.getPath());
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_GATE; boolean inWall = blockState.getValue(IN_WALL);
boolean isOpen = blockState.getValue(OPEN);
String state = "" + (inWall ? "_wall" : "") + (isOpen ? "_open" : "_closed");
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + state);
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), true, false);
} }
} }

View file

@ -1,8 +1,11 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader; import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
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;
@ -25,13 +28,15 @@ import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.util.BlocksHelper; import ru.betterend.util.BlocksHelper;
public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable, BlockPatterned { public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable, BlockModelProvider {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
protected static final VoxelShape EAST_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D); protected static final VoxelShape EAST_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D);
@ -136,24 +141,22 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable,
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation blockId) {
String blockId = Registry.BLOCK.getKey(this).getPath(); return ModelsHelper.createBlockItem(blockId);
return Patterns.createJson(data, blockId, blockId);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_LADDER, blockId.getPath());
if (block.contains("item")) { return ModelsHelper.fromPattern(pattern);
return Patterns.createJson(Patterns.ITEM_BLOCK, blockId.getPath());
}
return Patterns.createJson(Patterns.BLOCK_LADDER, blockId.getPath());
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_LADDER; ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath());
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING), false, true);
} }
} }

View file

@ -1,8 +1,10 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
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.resources.ResourceLocation;
import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor; import net.minecraft.world.level.LevelAccessor;
@ -19,6 +21,9 @@ import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties;
import ru.betterend.client.models.ModelsHelper;
import java.util.Map;
public class EndLanternBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer { public class EndLanternBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer {
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR; public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
@ -116,4 +121,13 @@ public class EndLanternBlock extends BlockBaseNotFull implements SimpleWaterlogg
public FluidState getFluidState(BlockState state) { public FluidState getFluidState(BlockState state) {
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState(); return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : Fluids.EMPTY.defaultFluidState();
} }
@Override
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String floor = blockState.getValue(IS_FLOOR) ? "_floor" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + floor);
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createBlockSimple(modelId);
}
} }

View file

@ -1,13 +1,14 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
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.client.renderer.block.model.BlockModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -22,11 +23,11 @@ import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class EndLeavesBlock extends LeavesBlock implements BlockPatterned, IRenderTypeable { public class EndLeavesBlock extends LeavesBlock implements BlockModelProvider, IRenderTypeable {
private final Block sapling; private final Block sapling;
public EndLeavesBlock(Block sapling, MaterialColor color) { public EndLeavesBlock(Block sapling, MaterialColor color) {
@ -52,24 +53,7 @@ public class EndLeavesBlock extends LeavesBlock implements BlockPatterned, IRend
.isViewBlocking((state, world, pos) -> false)); .isViewBlocking((state, world, pos) -> false));
this.sapling = sapling; this.sapling = sapling;
} }
@Override
public String getStatesPattern(Reader data) {
String blockId = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, blockId, blockId);
}
@Override
public String getModelPattern(String block) {
String blockId = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(Patterns.BLOCK_BASE, blockId, blockId);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
}
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
@ -90,4 +74,9 @@ public class EndLeavesBlock extends LeavesBlock implements BlockPatterned, IRend
} }
return MHelper.RANDOM.nextInt(16) == 0 ? Lists.newArrayList(new ItemStack(sapling)) : Lists.newArrayList(); return MHelper.RANDOM.nextInt(16) == 0 ? Lists.newArrayList(new ItemStack(sapling)) : Lists.newArrayList();
} }
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return getBlockModel(resourceLocation, defaultBlockState());
}
} }

View file

@ -1,12 +1,16 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
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.resources.ResourceLocation;
@ -15,12 +19,14 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.IronBarsBlock; import net.minecraft.world.level.block.IronBarsBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class EndMetalPaneBlock extends IronBarsBlock implements BlockPatterned, IRenderTypeable { public class EndMetalPaneBlock extends IronBarsBlock implements BlockModelProvider, IRenderTypeable {
public EndMetalPaneBlock(Block source) { public EndMetalPaneBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion()); super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion());
} }
@ -29,15 +35,8 @@ public class EndMetalPaneBlock extends IronBarsBlock implements BlockPatterned,
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override public Optional<String> getModelString(String block) {
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(data, blockId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); ResourceLocation blockId = Registry.BLOCK.getKey(this);
if (block.contains("item")) { if (block.contains("item")) {
return Patterns.createJson(Patterns.ITEM_BLOCK, blockId.getPath()); return Patterns.createJson(Patterns.ITEM_BLOCK, blockId.getPath());
@ -49,7 +48,50 @@ public class EndMetalPaneBlock extends IronBarsBlock implements BlockPatterned,
return Patterns.createJson(Patterns.BLOCK_BARS_SIDE, blockId.getPath(), blockId.getPath()); return Patterns.createJson(Patterns.BLOCK_BARS_SIDE, blockId.getPath(), blockId.getPath());
} }
} }
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createBlockItem(resourceLocation);
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation thisId = Registry.BLOCK.getKey(this);
String path = blockId.getPath();
Optional<String> pattern = Optional.empty();
if (path.endsWith("_post")) {
pattern = Patterns.createJson(Patterns.BLOCK_BARS_POST, thisId.getPath(), thisId.getPath());
}
if (path.endsWith("_side")) {
pattern = Patterns.createJson(Patterns.BLOCK_BARS_SIDE, thisId.getPath(), thisId.getPath());
}
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation postId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_post");
ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_side");
registerBlockModel(postId, postId, blockState, modelCache);
registerBlockModel(sideId, sideId, blockState, modelCache);
ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition);
builder.part(postId).setCondition(state ->
!state.getValue(NORTH) && !state.getValue(EAST) &&
!state.getValue(SOUTH) && !state.getValue(WEST)).add();
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST))
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH))
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST))
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
return builder.build();
}
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public boolean skipRendering(BlockState state, BlockState stateFrom, Direction direction) { public boolean skipRendering(BlockState state, BlockState stateFrom, Direction direction) {
if (direction.getAxis().isVertical() && stateFrom.getBlock().is(this) && !stateFrom.equals(state)) { if (direction.getAxis().isVertical() && stateFrom.getBlock().is(this) && !stateFrom.equals(state)) {
@ -57,12 +99,7 @@ public class EndMetalPaneBlock extends IronBarsBlock implements BlockPatterned,
} }
return super.skipRendering(state, stateFrom, direction); return super.skipRendering(state, stateFrom, direction);
} }
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_BARS;
}
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;

View file

@ -1,52 +0,0 @@
package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WeightedPressurePlateBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned;
import ru.betterend.patterns.Patterns;
public class EndMetalPlateBlock extends WeightedPressurePlateBlock implements BlockPatterned {
private final Block parent;
public EndMetalPlateBlock(Block source) {
super(15, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().requiresCorrectToolForDrops().strength(0.5F));
this.parent = source;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (block.contains("down")) {
return Patterns.createJson(Patterns.BLOCK_PLATE_DOWN, parentId.getPath(), blockId.getPath());
}
return Patterns.createJson(Patterns.BLOCK_PLATE_UP, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_PLATE;
}
}

View file

@ -1,12 +1,11 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Random; import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
@ -20,17 +19,16 @@ import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams; import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class EndOreBlock extends OreBlock implements BlockPatterned { public class EndOreBlock extends OreBlock implements BlockModelProvider {
private final Item dropItem; private final Item dropItem;
private final int minCount; private final int minCount;
private final int maxCount; private final int maxCount;
private final int expirience; private final int experience;
public EndOreBlock(Item drop, int minCount, int maxCount, int expirience) { public EndOreBlock(Item drop, int minCount, int maxCount, int experience) {
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND) super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
.hardness(3F) .hardness(3F)
.resistance(9F) .resistance(9F)
@ -39,12 +37,12 @@ public class EndOreBlock extends OreBlock implements BlockPatterned {
this.dropItem = drop; this.dropItem = drop;
this.minCount = minCount; this.minCount = minCount;
this.maxCount = maxCount; this.maxCount = maxCount;
this.expirience = expirience; this.experience = experience;
} }
@Override @Override
protected int xpOnDrop(Random random) { protected int xpOnDrop(Random random) {
return this.expirience > 0 ? random.nextInt(expirience) + 1 : 0; return this.experience > 0 ? random.nextInt(experience) + 1 : 0;
} }
@Override @Override
@ -70,21 +68,9 @@ public class EndOreBlock extends OreBlock implements BlockPatterned {
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
String block = Registry.BLOCK.getKey(this).getPath(); return getBlockModel(resourceLocation, defaultBlockState());
return Patterns.createJson(data, block, block);
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
} }
} }

View file

@ -1,70 +1,82 @@
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 com.google.common.collect.Maps;
import com.google.common.collect.Maps;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.BlockPos; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry; import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation; 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.patterns.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 String getModelPattern(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 BlockModel getItemModel(ResourceLocation blockId) {
return Patterns.createJson(Patterns.BLOCK_PATH, map); return getBlockModel(blockId, defaultBlockState());
} }
@Override @Override
public ResourceLocation statePatternId() { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
return Patterns.STATE_ROTATED_TOP; 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 stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath());
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createRandomTopModel(modelId);
}
}

View file

@ -1,10 +1,13 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -12,10 +15,12 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RotatedPillarBlock; import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndPillarBlock extends RotatedPillarBlock implements BlockPatterned { public class EndPillarBlock extends RotatedPillarBlock implements BlockModelProvider {
public EndPillarBlock(Properties settings) { public EndPillarBlock(Properties settings) {
super(settings); super(settings);
} }
@ -28,21 +33,27 @@ public class EndPillarBlock extends RotatedPillarBlock implements BlockPatterned
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation blockId) {
String texture = Registry.BLOCK.getKey(this).getPath(); return getBlockModel(blockId, defaultBlockState());
return Patterns.createJson(data, texture, texture);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
String texture = Registry.BLOCK.getKey(this).getPath(); Optional<String> pattern = createBlockPattern(blockId);
return Patterns.createJson(Patterns.BLOCK_PILLAR, texture, texture); return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_PILLAR; ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath());
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createRotatedModel(modelId, blockState.getValue(AXIS));
}
protected Optional<String> createBlockPattern(ResourceLocation blockId) {
return Patterns.createBlockPillar(blockId.getPath());
} }
} }

View file

@ -1,10 +1,13 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -12,10 +15,12 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.PressurePlateBlock; import net.minecraft.world.level.block.PressurePlateBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndPlateBlock extends PressurePlateBlock implements BlockPatterned { public class EndPlateBlock extends PressurePlateBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
public EndPlateBlock(Sensitivity rule, Block source) { public EndPlateBlock(Sensitivity rule, Block source) {
@ -27,26 +32,30 @@ public class EndPlateBlock extends PressurePlateBlock implements BlockPatterned
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); return getBlockModel(resourceLocation, defaultBlockState());
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (block.contains("down")) { Optional<String> pattern;
return Patterns.createJson(Patterns.BLOCK_PLATE_DOWN, parentId.getPath(), blockId.getPath()); if (blockState.getValue(POWERED)) {
pattern = Patterns.createJson(Patterns.BLOCK_PLATE_DOWN, parentId.getPath(), resourceLocation.getPath());
} else {
pattern = Patterns.createJson(Patterns.BLOCK_PLATE_UP, parentId.getPath(), resourceLocation.getPath());
} }
return Patterns.createJson(Patterns.BLOCK_PLATE_UP, parentId.getPath(), blockId.getPath()); return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return this.stateDefinition.getProperty("facing") != null ? Patterns.STATE_PLATE_ROTATED : Patterns.STATE_PLATE; String state = blockState.getValue(POWERED) ? "_down" : "_up";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + state);
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createBlockSimple(modelId);
} }
} }

View file

@ -1,10 +1,11 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
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;
@ -38,13 +39,15 @@ import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.entities.ESignBlockEntity; import ru.betterend.blocks.entities.ESignBlockEntity;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.interfaces.ISpetialItem; import ru.betterend.interfaces.ISpetialItem;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.util.BlocksHelper; import ru.betterend.util.BlocksHelper;
public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialItem { public class EndSignBlock extends SignBlock implements BlockModelProvider, ISpetialItem {
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16; public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
public static final BooleanProperty FLOOR = BooleanProperty.create("floor"); public static final BooleanProperty FLOOR = BooleanProperty.create("floor");
private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] { private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] {
@ -79,14 +82,15 @@ public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialI
@Override @Override
public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) { public void setPlacedBy(Level world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
if (placer != null && placer instanceof Player) { if (placer instanceof Player) {
ESignBlockEntity sign = (ESignBlockEntity) world.getBlockEntity(pos); ESignBlockEntity sign = (ESignBlockEntity) world.getBlockEntity(pos);
if (!world.isClientSide) { if (sign != null) {
sign.setAllowedPlayerEditor((Player) placer); if (!world.isClientSide) {
((ServerPlayer) placer).connection.send(new ClientboundOpenSignEditorPacket(pos)); sign.setAllowedPlayerEditor((Player) placer);
} ((ServerPlayer) placer).connection.send(new ClientboundOpenSignEditorPacket(pos));
else { } else {
sign.setEditable(true); sign.setEditable(true);
}
} }
} }
} }
@ -128,8 +132,7 @@ public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialI
BlockPos blockPos = ctx.getClickedPos(); BlockPos blockPos = ctx.getClickedPos();
Direction[] directions = ctx.getNearestLookingDirections(); Direction[] directions = ctx.getNearestLookingDirections();
for (int i = 0; i < directions.length; ++i) { for (Direction direction : directions) {
Direction direction = directions[i];
if (direction.getAxis().isHorizontal()) { if (direction.getAxis().isHorizontal()) {
Direction dir = direction.getOpposite(); Direction dir = direction.getOpposite();
int rot = Mth.floor((180.0 + dir.toYRot() * 16.0 / 360.0) + 0.5 + 4) & 15; int rot = Mth.floor((180.0 + dir.toYRot() * 16.0 / 360.0) + 0.5 + 4) & 15;
@ -143,28 +146,13 @@ public class EndSignBlock extends SignBlock implements BlockPatterned, ISpetialI
return null; return null;
} }
@Override @Override
public String getStatesPattern(Reader data) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); return ModelsHelper.createBlockEmpty(parentId);
} }
@Override
public String getModelPattern(String path) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (path.contains("item")) {
return Patterns.createJson(Patterns.ITEM_GENERATED, path);
}
return Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
}
@Override @Override
public BlockState rotate(BlockState state, Rotation rotation) { public BlockState rotate(BlockState state, Rotation rotation) {
return (BlockState) state.setValue(ROTATION, rotation.rotate((Integer) state.getValue(ROTATION), 16)); return (BlockState) state.setValue(ROTATION, rotation.rotate((Integer) state.getValue(ROTATION), 16));

View file

@ -1,21 +1,28 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.SlabBlock; import net.minecraft.world.level.block.SlabBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndSlabBlock extends SlabBlock implements BlockPatterned { public class EndSlabBlock extends SlabBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
public EndSlabBlock(Block source) { public EndSlabBlock(Block source) {
@ -27,23 +34,28 @@ public class EndSlabBlock extends SlabBlock implements BlockPatterned {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); return getBlockModel(resourceLocation, defaultBlockState());
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath()); Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath());
return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_SLAB; SlabType type = blockState.getValue(TYPE);
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_" + type);
registerBlockModel(stateId, modelId, blockState, modelCache);
if (type == SlabType.TOP) {
return ModelsHelper.createMultiVariant(modelId, BlockModelRotation.X180_Y0.getRotation(), true);
}
return ModelsHelper.createBlockSimple(modelId);
} }
} }

View file

@ -1,21 +1,29 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.StairBlock; import net.minecraft.world.level.block.StairBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Half;
import net.minecraft.world.level.block.state.properties.StairsShape;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndStairsBlock extends StairBlock implements BlockPatterned { public class EndStairsBlock extends StairBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -28,29 +36,72 @@ public class EndStairsBlock extends StairBlock implements BlockPatterned {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); return getBlockModel(resourceLocation, defaultBlockState());
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (block.contains("inner")) { Optional<String> pattern = Optional.empty();
return Patterns.createJson(Patterns.BLOCK_STAIR_INNER, parentId.getPath(), blockId.getPath()); switch (blockState.getValue(SHAPE)) {
case STRAIGHT:
pattern = Patterns.createJson(Patterns.BLOCK_STAIR, parentId.getPath(), blockId.getPath());
break;
case INNER_LEFT:
case INNER_RIGHT:
pattern = Patterns.createJson(Patterns.BLOCK_STAIR_INNER, parentId.getPath(), blockId.getPath());
break;
case OUTER_LEFT:
case OUTER_RIGHT:
pattern = Patterns.createJson(Patterns.BLOCK_STAIR_OUTER, parentId.getPath(), blockId.getPath());
break;
} }
if (block.contains("outer")) { return ModelsHelper.fromPattern(pattern);
return Patterns.createJson(Patterns.BLOCK_STAIR_OUTER, parentId.getPath(), blockId.getPath());
}
return Patterns.createJson(Patterns.BLOCK_STAIR, parentId.getPath(), blockId.getPath());
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_STAIRS; String state = "";
StairsShape shape = blockState.getValue(SHAPE);
switch (shape) {
case INNER_LEFT:
case INNER_RIGHT:
state = "_inner"; break;
case OUTER_LEFT:
case OUTER_RIGHT:
state = "_outer"; break;
}
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + state);
registerBlockModel(stateId, modelId, blockState, modelCache);
boolean isTop = blockState.getValue(HALF) == Half.TOP;
boolean isLeft = shape == StairsShape.INNER_LEFT ||
shape == StairsShape.OUTER_LEFT;
boolean isRight = shape == StairsShape.INNER_RIGHT ||
shape == StairsShape.OUTER_RIGHT;
int y = 0;
int x = isTop ? 180 : 0;
switch (blockState.getValue(FACING)) {
case NORTH:
if (isTop && !isRight) y = 270;
else if (!isTop) y = isLeft ? 180 : 270;
break;
case EAST:
if (isTop && isRight) y = 90;
else if (!isTop && isLeft) y = 270;
break;
case SOUTH:
if (isTop) y = isRight ? 180 : 90;
else if (!isLeft) y = 90;
break;
case WEST:
y = (isTop && isRight) ? 270 : (!isTop && isLeft) ? 90 : 180;
break;
}
BlockModelRotation rotation = BlockModelRotation.by(x, y);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), true);
} }
} }

View file

@ -1,55 +1,33 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.StoneButtonBlock; import net.minecraft.world.level.block.StoneButtonBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.Patterns;
public class EndStoneButtonBlock extends EndButtonBlock {
public class EndStoneButtonBlock extends StoneButtonBlock implements BlockPatterned {
private final Block parent;
public EndStoneButtonBlock(Block source) { public EndStoneButtonBlock(Block source) {
super(FabricBlockSettings.copyOf(source).noOcclusion()); super(source, FabricBlockSettings.copyOf(source).noOcclusion(), false);
this.parent = source;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { protected SoundEvent getSound(boolean clicked) {
return Collections.singletonList(new ItemStack(this)); return clicked ? SoundEvents.STONE_BUTTON_CLICK_ON : SoundEvents.STONE_BUTTON_CLICK_OFF;
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (block.contains("item")) {
return Patterns.createJson(Patterns.ITEM_BUTTON, parentId.getPath(), blockId.getPath());
}
if (block.contains("pressed")) {
return Patterns.createJson(Patterns.BLOCK_BUTTON_PRESSED, parentId.getPath(), blockId.getPath());
}
return Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_BUTTON;
} }
} }

View file

@ -1,9 +1,9 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
public class EndStonelateBlock extends EndPlateBlock { public class EndStonePlateBlock extends EndPlateBlock {
public EndStonelateBlock(Block source) { public EndStonePlateBlock(Block source) {
super(Sensitivity.MOBS, source); super(Sensitivity.MOBS, source);
} }
} }

View file

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

View file

@ -1,24 +1,27 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader; import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.TrapDoorBlock; import net.minecraft.world.level.block.TrapDoorBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Half;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class EndTrapdoorBlock extends TrapDoorBlock implements IRenderTypeable, BlockPatterned { public class EndTrapdoorBlock extends TrapDoorBlock implements IRenderTypeable, BlockModelProvider {
public EndTrapdoorBlock(Block source) { public EndTrapdoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion()); super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion());
} }
@ -32,28 +35,48 @@ public class EndTrapdoorBlock extends TrapDoorBlock implements IRenderTypeable,
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {
return ERenderLayer.CUTOUT; return ERenderLayer.CUTOUT;
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
String block = Registry.BLOCK.getKey(this).getPath(); return getBlockModel(resourceLocation, defaultBlockState());
return Patterns.createJson(data, block, block);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); String name = resourceLocation.getPath();
String name = blockId.getPath(); Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_TRAPDOOR, new HashMap<String, String>() {
return Patterns.createJson(Patterns.BLOCK_TRAPDOOR, new HashMap<String, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
{ {
put("%block%", name); put("%block%", name);
put("%texture%", name.replace("trapdoor", "door_side")); put("%texture%", name.replace("trapdoor", "door_side"));
} }
}); });
return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_TRAPDOOR; ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath());
registerBlockModel(stateId, modelId, blockState, modelCache);
boolean isTop = blockState.getValue(HALF) == Half.TOP;
boolean isOpen = blockState.getValue(OPEN);
int y = 0;
int x = (isTop && isOpen) ? 270 : isTop ? 180 : isOpen ? 90 : 0;
switch (blockState.getValue(FACING)) {
case EAST:
y = (isTop && isOpen) ? 270 : 90;
break;
case NORTH:
if (isTop && isOpen) y = 180;
break;
case SOUTH:
y = (isTop && isOpen) ? 0 : 180;
break;
case WEST:
y = (isTop && isOpen) ? 90 : 270;
break;
}
BlockModelRotation rotation = BlockModelRotation.by(x, y);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
} }
} }

View file

@ -1,21 +1,28 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WallBlock; import net.minecraft.world.level.block.WallBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.WallSide;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import org.jetbrains.annotations.Nullable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndWallBlock extends WallBlock implements BlockPatterned { public class EndWallBlock extends WallBlock implements BlockModelProvider {
private final Block parent; private final Block parent;
@ -28,32 +35,60 @@ public class EndWallBlock extends WallBlock implements BlockPatterned {
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this)); return Collections.singletonList(new ItemStack(this));
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation blockId) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath()); Optional<String> pattern = Patterns.createJson(Patterns.ITEM_WALL, parentId.getPath(), blockId.getPath());
return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent); ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (block.contains("item")) { String path = blockId.getPath();
return Patterns.createJson(Patterns.ITEM_WALL, parentId.getPath(), blockId.getPath()); Optional<String> pattern = Optional.empty();
if (path.endsWith("_post")) {
pattern = Patterns.createJson(Patterns.BLOCK_WALL_POST, parentId.getPath(), blockId.getPath());
} }
if (block.contains("side_tall")) { if (path.endsWith("_side")) {
return Patterns.createJson(Patterns.BLOCK_WALL_SIDE_TALL, parentId.getPath(), blockId.getPath()); pattern = Patterns.createJson(Patterns.BLOCK_WALL_SIDE, parentId.getPath(), blockId.getPath());
} }
if (block.contains("side")) { if (path.endsWith("_side_tall")) {
return Patterns.createJson(Patterns.BLOCK_WALL_SIDE, parentId.getPath(), blockId.getPath()); pattern = Patterns.createJson(Patterns.BLOCK_WALL_SIDE_TALL, parentId.getPath(), blockId.getPath());
} }
return Patterns.createJson(Patterns.BLOCK_WALL_POST, parentId.getPath(), blockId.getPath()); return ModelsHelper.fromPattern(pattern);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_WALL; ResourceLocation postId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_post");
ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_side");
ResourceLocation sideTallId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_side_tall");
registerBlockModel(postId, postId, blockState, modelCache);
registerBlockModel(sideId, sideId, blockState, modelCache);
registerBlockModel(sideTallId, sideTallId, blockState, modelCache);
ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition);
builder.part(sideId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.LOW).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.LOW)
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.LOW)
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.LOW)
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.TALL).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.TALL)
.setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.TALL)
.setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.TALL)
.setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(postId).setCondition(state -> state.getValue(UP)).add();
return builder.build();
} }
} }

View file

@ -0,0 +1,61 @@
package ru.betterend.blocks.basis;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WeightedPressurePlateBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndWeightedPlateBlock extends WeightedPressurePlateBlock implements BlockModelProvider {
private final Block parent;
public EndWeightedPlateBlock(Block source) {
super(15, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().requiresCorrectToolForDrops().strength(0.5F));
this.parent = source;
}
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
return Collections.singletonList(new ItemStack(this));
}
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return getBlockModel(resourceLocation, defaultBlockState());
}
@Override
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern;
if (blockState.getValue(POWER) > 0) {
pattern = Patterns.createJson(Patterns.BLOCK_PLATE_DOWN, parentId.getPath(), resourceLocation.getPath());
} else {
pattern = Patterns.createJson(Patterns.BLOCK_PLATE_UP, parentId.getPath(), resourceLocation.getPath());
}
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
String state = blockState.getValue(POWER) > 0 ? "_down" : "_up";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + state);
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createBlockSimple(modelId);
}
}

View file

@ -1,55 +1,30 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.WoodButtonBlock; import net.minecraft.world.level.block.WoodButtonBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class EndWoodenButtonBlock extends EndButtonBlock {
public class EndWoodenButtonBlock extends WoodButtonBlock implements BlockPatterned {
private final Block parent;
public EndWoodenButtonBlock(Block source) { public EndWoodenButtonBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion()); super(source, FabricBlockSettings.copyOf(source).strength(0.5F, 0.5F).noOcclusion(), true);
this.parent = source;
} }
@Override @Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) { protected SoundEvent getSound(boolean clicked) {
return Collections.singletonList(new ItemStack(this)); return clicked ? SoundEvents.WOODEN_BUTTON_CLICK_ON : SoundEvents.WOODEN_BUTTON_CLICK_OFF;
}
@Override
public String getStatesPattern(Reader data) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
return Patterns.createJson(data, parentId.getPath(), blockId.getPath());
}
@Override
public String getModelPattern(String block) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
if (block.contains("item")) {
return Patterns.createJson(Patterns.ITEM_BUTTON, parentId.getPath(), blockId.getPath());
}
if (block.contains("pressed")) {
return Patterns.createJson(Patterns.BLOCK_BUTTON_PRESSED, parentId.getPath(), blockId.getPath());
}
return Patterns.createJson(Patterns.BLOCK_BUTTON, parentId.getPath(), blockId.getPath());
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_BUTTON;
} }
} }

View file

@ -1,14 +1,14 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional;
import java.util.Random; import java.util.Random;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
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.resources.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@ -26,13 +26,15 @@ import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.storage.loot.LootContext; import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.BlockPatterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndTags; import ru.betterend.registry.EndTags;
public abstract class FeatureSaplingBlock extends SaplingBlock implements IRenderTypeable, BlockPatterned { public abstract class FeatureSaplingBlock extends SaplingBlock implements IRenderTypeable, BlockModelProvider {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12); private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public FeatureSaplingBlock() { public FeatureSaplingBlock() {
@ -108,22 +110,13 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); return ModelsHelper.createBlockItem(resourceLocation);
return Patterns.createJson(data, blockId.getPath(), blockId.getPath());
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
if (block.contains("item")) { Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CROSS, resourceLocation.getPath());
block = block.split("/")[1]; return ModelsHelper.fromPattern(pattern);
return Patterns.createJson(Patterns.ITEM_BLOCK, block);
}
return Patterns.createJson(Patterns.BLOCK_CROSS, block);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SAPLING;
} }
} }

View file

@ -1,11 +1,13 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.awt.Point; import java.awt.Point;
import java.io.Reader;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Optional;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
@ -42,7 +44,8 @@ import ru.betterend.blocks.BlockProperties;
import ru.betterend.blocks.BlockProperties.PedestalState; import ru.betterend.blocks.BlockProperties.PedestalState;
import ru.betterend.blocks.InfusionPedestal; import ru.betterend.blocks.InfusionPedestal;
import ru.betterend.blocks.entities.PedestalBlockEntity; import ru.betterend.blocks.entities.PedestalBlockEntity;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndBlocks; import ru.betterend.registry.EndBlocks;
import ru.betterend.rituals.InfusionRitual; import ru.betterend.rituals.InfusionRitual;
@ -333,18 +336,55 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) { public int getAnalogOutputSignal(BlockState state, Level world, BlockPos pos) {
return state.getValue(HAS_ITEM) ? 15 : 0; return state.getValue(HAS_ITEM) ? 15 : 0;
} }
@Override @Override
public String getStatesPattern(Reader data) { public BlockModel getItemModel(ResourceLocation blockId) {
String texture = Registry.BLOCK.getKey(this).getPath(); return getBlockModel(blockId, defaultBlockState());
return Patterns.createJson(data, texture, texture);
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
Map<String, String> textures = createTexturesMap();
PedestalState state = blockState.getValue(STATE);
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
switch (state) {
case COLUMN_TOP: {
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_COLUMN_TOP, textures);
break;
}
case COLUMN: {
pattern = Patterns.createJson(Patterns.BLOKC_PEDESTAL_COLUMN, textures);
break;
}
case PEDESTAL_TOP: {
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_TOP, textures);
break;
}
case BOTTOM: {
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_BOTTOM, textures);
break;
}
case PILLAR: {
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_PILLAR, textures);
break;
}
}
return ModelsHelper.fromPattern(pattern);
}
@Override
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
PedestalState state = blockState.getValue(STATE);
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + "_" + state);
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createBlockSimple(modelId);
}
protected Map<String, String> createTexturesMap() {
ResourceLocation blockId = Registry.BLOCK.getKey(parent); ResourceLocation blockId = Registry.BLOCK.getKey(parent);
String name = blockId.getPath(); String name = blockId.getPath();
Map<String, String> textures = new HashMap<String, String>() { return new HashMap<String, String>() {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
{ {
put("%mod%", blockId.getNamespace() ); put("%mod%", blockId.getNamespace() );
@ -354,23 +394,6 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
put("%bottom%", name + "_bottom"); put("%bottom%", name + "_bottom");
} }
}; };
if (block.contains("column_top")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_COLUMN_TOP, textures);
} else if (block.contains("column")) {
return Patterns.createJson(Patterns.BLOKC_PEDESTAL_COLUMN, textures);
} else if (block.contains("top")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_TOP, textures);
} else if (block.contains("bottom")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_BOTTOM, textures);
} else if (block.contains("pillar")) {
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_PILLAR, textures);
}
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_PEDESTAL;
} }
static { static {

View file

@ -1,16 +1,15 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader; import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor; import net.minecraft.world.level.material.MaterialColor;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class SimpleLeavesBlock extends BlockBaseNotFull implements IRenderTypeable { public class SimpleLeavesBlock extends BlockBaseNotFull implements IRenderTypeable {
public SimpleLeavesBlock(MaterialColor color) { public SimpleLeavesBlock(MaterialColor color) {
@ -35,23 +34,6 @@ public class SimpleLeavesBlock extends BlockBaseNotFull implements IRenderTypeab
.isSuffocating((state, world, pos) -> false) .isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false)); .isViewBlocking((state, world, pos) -> false));
} }
@Override
public String getStatesPattern(Reader data) {
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, texture, texture);
}
@Override
public String getModelPattern(String block) {
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(Patterns.BLOCK_BASE, texture, texture);
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_SIMPLE;
}
@Override @Override
public ERenderLayer getRenderLayer() { public ERenderLayer getRenderLayer() {

View file

@ -1,6 +1,9 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
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.BlockPos.MutableBlockPos; import net.minecraft.core.BlockPos.MutableBlockPos;
import net.minecraft.core.Direction; import net.minecraft.core.Direction;
@ -28,10 +31,15 @@ import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.BlockProperties; import ru.betterend.blocks.BlockProperties;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.render.ERenderLayer; import ru.betterend.client.render.ERenderLayer;
import ru.betterend.interfaces.IRenderTypeable; import ru.betterend.interfaces.IRenderTypeable;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import java.util.Map;
import java.util.Optional;
public class StalactiteBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTypeable { public class StalactiteBlock extends BlockBaseNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTypeable {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
@ -192,19 +200,20 @@ public class StalactiteBlock extends BlockBaseNotFull implements SimpleWaterlogg
} }
@Override @Override
public String getModelPattern(String block) { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this); Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CROSS_SHADED, resourceLocation.getPath());
if (block.contains("item")) { return ModelsHelper.fromPattern(pattern);
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/" + blockId.getPath());
}
return Patterns.createJson(Patterns.BLOCK_CROSS_SHADED, block);
} }
@Override @Override
public ResourceLocation statePatternId() { public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
return Patterns.STATE_STALACTITE; BlockModelRotation rotation = blockState.getValue(IS_FLOOR) ? BlockModelRotation.X0_Y0 : BlockModelRotation.X180_Y0;
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
stateId.getPath() + "_" + blockState.getValue(SIZE));
registerBlockModel(modelId, modelId, blockState, modelCache);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
} }
@Override @Override
public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) { public boolean canPlaceLiquid(BlockGetter world, BlockPos pos, BlockState state, Fluid fluid) {
return false; return false;

View file

@ -1,10 +1,11 @@
package ru.betterend.blocks.basis; package ru.betterend.blocks.basis;
import java.io.Reader; import java.util.Optional;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings; import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.color.block.BlockColor; import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor; import net.minecraft.client.color.item.ItemColor;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.core.Registry; import net.minecraft.core.Registry;
import net.minecraft.core.Vec3i; import net.minecraft.core.Vec3i;
@ -15,9 +16,11 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.shapes.CollisionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.betterend.blocks.AuroraCrystalBlock; import ru.betterend.blocks.AuroraCrystalBlock;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.interfaces.IColorProvider; import ru.betterend.interfaces.IColorProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.util.MHelper; import ru.betterend.util.MHelper;
public class StoneLanternBlock extends EndLanternBlock implements IColorProvider { public class StoneLanternBlock extends EndLanternBlock implements IColorProvider {
@ -61,24 +64,13 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider
public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) { public VoxelShape getShape(BlockState state, BlockGetter view, BlockPos pos, CollisionContext ePos) {
return state.getValue(IS_FLOOR) ? SHAPE_FLOOR : SHAPE_CEIL; return state.getValue(IS_FLOOR) ? SHAPE_FLOOR : SHAPE_CEIL;
} }
@Override @Override
public ResourceLocation statePatternId() { public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
return Patterns.STATE_STONE_LANTERN; String blockName = resourceLocation.getPath();
} Optional<String> pattern = blockState.getValue(IS_FLOOR) ?
Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_FLOOR, blockName, blockName) :
@Override Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_CEIL, blockName, blockName);
public String getModelPattern(String block) { return ModelsHelper.fromPattern(pattern);
String texture = Registry.BLOCK.getKey(this).getPath();
if (block.contains("ceil")) {
return Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_CEIL, texture, texture);
}
return Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_FLOOR, texture, texture);
}
@Override
public String getStatesPattern(Reader data) {
String block = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(data, block, block);
} }
} }

View file

@ -30,7 +30,7 @@ public class StrippableBarkBlock extends BarkBlock {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F); world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) { if (!world.isClientSide) {
world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11); world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11);
if (player != null && !player.isCreative()) { if (!player.isCreative()) {
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player); player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
} }
} }

View file

@ -1,10 +1,19 @@
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.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;
@ -23,10 +32,11 @@ 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.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class TripleTerrainBlock extends EndTerrainBlock { public class TripleTerrainBlock extends EndTerrainBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE; public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
@ -47,25 +57,7 @@ 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 String getModelPattern(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 ResourceLocation statePatternId() {
return Patterns.STATE_TRIPLE_ROTATED_TOP;
}
@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) {
TripleShape shape = state.getValue(SHAPE); TripleShape shape = state.getValue(SHAPE);
@ -80,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) {
@ -93,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));
} }
} }
@ -109,16 +97,59 @@ 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 BlockModel getItemModel(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 stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
boolean isMiddle = isMiddle(blockState);
String middle = isMiddle ? "_middle" : "";
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(),
"block/" + stateId.getPath() + middle);
registerBlockModel(stateId, 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

@ -27,7 +27,7 @@ import ru.betterend.blocks.basis.EndStairsBlock;
import ru.betterend.blocks.basis.EndTrapdoorBlock; import ru.betterend.blocks.basis.EndTrapdoorBlock;
import ru.betterend.blocks.basis.EndWoodenPlateBlock; import ru.betterend.blocks.basis.EndWoodenPlateBlock;
import ru.betterend.item.EndArmorItem; import ru.betterend.item.EndArmorItem;
import ru.betterend.item.PatternedItem; import ru.betterend.item.ModelProviderItem;
import ru.betterend.item.tool.EndAxeItem; import ru.betterend.item.tool.EndAxeItem;
import ru.betterend.item.tool.EndHammerItem; import ru.betterend.item.tool.EndHammerItem;
import ru.betterend.item.tool.EndHoeItem; import ru.betterend.item.tool.EndHoeItem;
@ -120,8 +120,8 @@ public class MetalMaterial {
bulb_lantern = EndBlocks.registerBlock(name + "_bulb_lantern", new BulbVineLanternBlock(lanternProperties)); bulb_lantern = EndBlocks.registerBlock(name + "_bulb_lantern", new BulbVineLanternBlock(lanternProperties));
bulb_lantern_colored = new ColoredMaterial(BulbVineLanternColoredBlock::new, bulb_lantern, false); bulb_lantern_colored = new ColoredMaterial(BulbVineLanternColoredBlock::new, bulb_lantern, false);
nugget = EndItems.registerItem(name + "_nugget", new PatternedItem(itemSettings)); nugget = EndItems.registerItem(name + "_nugget", new ModelProviderItem(itemSettings));
ingot = EndItems.registerItem(name + "_ingot", new PatternedItem(itemSettings)); ingot = EndItems.registerItem(name + "_ingot", new ModelProviderItem(itemSettings));
shovelHead = EndItems.registerItem(name + "_shovel_head"); shovelHead = EndItems.registerItem(name + "_shovel_head");
pickaxeHead = EndItems.registerItem(name + "_pickaxe_head"); pickaxeHead = EndItems.registerItem(name + "_pickaxe_head");

View file

@ -13,7 +13,7 @@ import ru.betterend.blocks.basis.EndPillarBlock;
import ru.betterend.blocks.basis.EndSlabBlock; import ru.betterend.blocks.basis.EndSlabBlock;
import ru.betterend.blocks.basis.EndStairsBlock; import ru.betterend.blocks.basis.EndStairsBlock;
import ru.betterend.blocks.basis.EndStoneButtonBlock; import ru.betterend.blocks.basis.EndStoneButtonBlock;
import ru.betterend.blocks.basis.EndStonelateBlock; import ru.betterend.blocks.basis.EndStonePlateBlock;
import ru.betterend.blocks.basis.EndWallBlock; import ru.betterend.blocks.basis.EndWallBlock;
import ru.betterend.blocks.basis.StoneLanternBlock; import ru.betterend.blocks.basis.StoneLanternBlock;
import ru.betterend.recipe.CraftingRecipes; import ru.betterend.recipe.CraftingRecipes;
@ -54,7 +54,7 @@ public class StoneMaterial {
slab = EndBlocks.registerBlock(name + "_slab", new EndSlabBlock(stone)); slab = EndBlocks.registerBlock(name + "_slab", new EndSlabBlock(stone));
wall = EndBlocks.registerBlock(name + "_wall", new EndWallBlock(stone)); wall = EndBlocks.registerBlock(name + "_wall", new EndWallBlock(stone));
button = EndBlocks.registerBlock(name + "_button", new EndStoneButtonBlock(stone)); button = EndBlocks.registerBlock(name + "_button", new EndStoneButtonBlock(stone));
pressure_plate = EndBlocks.registerBlock(name + "_plate", new EndStonelateBlock(stone)); pressure_plate = EndBlocks.registerBlock(name + "_plate", new EndStonePlateBlock(stone));
pedestal = EndBlocks.registerBlock(name + "_pedestal", new EndPedestal(stone)); pedestal = EndBlocks.registerBlock(name + "_pedestal", new EndPedestal(stone));
lantern = EndBlocks.registerBlock(name + "_lantern", new StoneLanternBlock(stone)); lantern = EndBlocks.registerBlock(name + "_lantern", new StoneLanternBlock(stone));

View file

@ -0,0 +1,39 @@
package ru.betterend.client.models;
import java.util.Map;
import java.util.Optional;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import ru.betterend.BetterEnd;
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
public interface BlockModelProvider extends ItemModelProvider {
default @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
Optional<String> pattern = Patterns.createBlockSimple(resourceLocation.getPath());
return ModelsHelper.fromPattern(pattern);
}
default UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath());
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createBlockSimple(modelId);
}
default void registerBlockModel(ResourceLocation stateId, ResourceLocation modelId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
if (!modelCache.containsKey(modelId)) {
BlockModel model = getBlockModel(stateId, blockState);
if (model != null) {
model.name = modelId.toString();
modelCache.put(modelId, model);
} else {
BetterEnd.LOGGER.warning("Error loading model: {}", modelId);
modelCache.put(modelId, modelCache.get(MISSING_MODEL_LOCATION));
}
}
}
}

View file

@ -0,0 +1,12 @@
package ru.betterend.client.models;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import java.util.Optional;
public interface ItemModelProvider {
default BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createItemModel(resourceLocation.getPath());
}
}

View file

@ -0,0 +1,148 @@
package ru.betterend.client.models;
import com.google.common.collect.*;
import com.mojang.math.Transformation;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
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.renderer.block.model.multipart.Condition;
import net.minecraft.client.renderer.block.model.multipart.MultiPart;
import net.minecraft.client.renderer.block.model.multipart.Selector;
import net.minecraft.client.resources.model.BlockModelRotation;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
@Environment(EnvType.CLIENT)
public class ModelsHelper {
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public static BlockModel fromPattern(Optional<String> pattern) {
return pattern.map(BlockModel::fromString).orElse(null);
}
public static BlockModel createItemModel(String name) {
Optional<String> pattern = Patterns.createItemGenerated("item/" + name);
return fromPattern(pattern);
}
public static BlockModel createHandheldItem(String name) {
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_HANDHELD, "item/" + name);
return fromPattern(pattern);
}
public static BlockModel createBlockItem(ResourceLocation resourceLocation) {
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_BLOCK, resourceLocation.getPath());
return fromPattern(pattern);
}
public static BlockModel createBlockEmpty(ResourceLocation resourceLocation) {
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_EMPTY, resourceLocation.getPath());
return fromPattern(pattern);
}
public static MultiVariant createMultiVariant(ResourceLocation resourceLocation, Transformation transform, boolean uvLock) {
Variant variant = new Variant(resourceLocation, transform, uvLock, 1);
return new MultiVariant(Lists.newArrayList(variant));
}
public static MultiVariant createBlockSimple(ResourceLocation resourceLocation) {
return createMultiVariant(resourceLocation, Transformation.identity(), false);
}
public static MultiVariant createFacingModel(ResourceLocation resourceLocation, Direction facing, boolean uvLock, boolean inverted) {
if (inverted) {
facing = facing.getOpposite();
}
BlockModelRotation rotation = BlockModelRotation.by(0, (int) facing.toYRot());
return createMultiVariant(resourceLocation, rotation.getRotation(), uvLock);
}
public static MultiVariant createRotatedModel(ResourceLocation resourceLocation, Direction.Axis axis) {
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
switch (axis) {
case X: rotation = BlockModelRotation.X90_Y90; break;
case Z: rotation = BlockModelRotation.X90_Y0; break;
}
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 {
private final static MultiPartBuilder BUILDER = new MultiPartBuilder();
public static MultiPartBuilder create(StateDefinition<Block, BlockState> stateDefinition) {
BUILDER.stateDefinition = stateDefinition;
BUILDER.modelParts.clear();
return BUILDER;
}
private final List<ModelPart> modelParts = Lists.newArrayList();
private StateDefinition<Block, BlockState> stateDefinition;
private MultiPartBuilder() {}
public ModelPart part(ResourceLocation modelId) {
return new ModelPart(modelId);
}
public MultiPart build() {
if (modelParts.size() > 0) {
List<Selector> selectors = Lists.newArrayList();
modelParts.forEach(modelPart -> {
MultiVariant variant = createMultiVariant(modelPart.modelId, modelPart.transform, modelPart.uvLock);
selectors.add(new Selector(modelPart.condition, variant));
});
modelParts.clear();
return new MultiPart(stateDefinition, selectors);
}
throw new IllegalStateException("At least one model part need to be created.");
}
public class ModelPart {
private final ResourceLocation modelId;
private Transformation transform = Transformation.identity();
private Condition condition = Condition.TRUE;
private boolean uvLock = false;
private ModelPart(ResourceLocation modelId) {
this.modelId = modelId;
}
public ModelPart setCondition(Function<BlockState, Boolean> condition) {
this.condition = stateDefinition -> condition::apply;
return this;
}
public ModelPart setTransformation(Transformation transform) {
this.transform = transform;
return this;
}
public ModelPart setUVLock(boolean value) {
this.uvLock = value;
return this;
}
public void add() {
modelParts.add(this);
}
}
}
}

View file

@ -1,162 +1,139 @@
package ru.betterend.patterns; package ru.betterend.client.models;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.Reader; import java.io.Reader;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.stream.Collectors; import java.util.Optional;
import java.util.stream.Collectors;
import com.google.common.collect.Maps;
import com.google.common.collect.Maps;
import net.minecraft.client.Minecraft;
import net.minecraft.resources.ResourceLocation; import net.minecraft.client.Minecraft;
import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.resources.ResourceLocation;
import ru.betterend.BetterEnd; import net.minecraft.server.packs.resources.ResourceManager;
import ru.betterend.BetterEnd;
public class Patterns {
public class Patterns {
//Blockstates //Block Models
public final static ResourceLocation STATE_SIMPLE = BetterEnd.makeID("patterns/blockstate/block.json"); public final static ResourceLocation BLOCK_EMPTY = BetterEnd.makeID("patterns/block/empty.json");
public final static ResourceLocation STATE_SLAB = BetterEnd.makeID("patterns/blockstate/slab.json"); public final static ResourceLocation BLOCK_BASE = BetterEnd.makeID("patterns/block/block.json");
public final static ResourceLocation STATE_STAIRS = BetterEnd.makeID("patterns/blockstate/stairs.json"); public final static ResourceLocation BLOCK_SIDED = BetterEnd.makeID("patterns/block/block_sided.json");
public final static ResourceLocation STATE_WALL = BetterEnd.makeID("patterns/blockstate/wall.json"); public final static ResourceLocation BLOCK_BOTTOM_TOP = BetterEnd.makeID("patterns/block/block_bottom_top.json");
public final static ResourceLocation STATE_FENCE = BetterEnd.makeID("patterns/blockstate/fence.json"); public final static ResourceLocation BLOCK_SLAB = BetterEnd.makeID("patterns/block/slab.json");
public final static ResourceLocation STATE_BUTTON = BetterEnd.makeID("patterns/blockstate/button.json"); public final static ResourceLocation BLOCK_STAIR = BetterEnd.makeID("patterns/block/stairs.json");
public final static ResourceLocation STATE_PILLAR = BetterEnd.makeID("patterns/blockstate/pillar.json"); public final static ResourceLocation BLOCK_STAIR_INNER = BetterEnd.makeID("patterns/block/inner_stairs.json");
public final static ResourceLocation STATE_PLATE = BetterEnd.makeID("patterns/blockstate/pressure_plate.json"); public final static ResourceLocation BLOCK_STAIR_OUTER = BetterEnd.makeID("patterns/block/outer_stairs.json");
public final static ResourceLocation STATE_PLATE_ROTATED = BetterEnd.makeID("patterns/blockstate/pressure_plate_rotated.json"); public final static ResourceLocation BLOCK_WALL_POST = BetterEnd.makeID("patterns/block/wall_post.json");
public final static ResourceLocation STATE_DOOR = BetterEnd.makeID("patterns/blockstate/door.json"); public final static ResourceLocation BLOCK_WALL_SIDE = BetterEnd.makeID("patterns/block/wall_side.json");
public final static ResourceLocation STATE_SAPLING = BetterEnd.makeID("patterns/blockstate/sapling.json"); public final static ResourceLocation BLOCK_WALL_SIDE_TALL = BetterEnd.makeID("patterns/block/wall_side_tall.json");
public final static ResourceLocation STATE_GATE = BetterEnd.makeID("patterns/blockstate/fence_gate.json"); public final static ResourceLocation BLOCK_FENCE_POST = BetterEnd.makeID("patterns/block/fence_post.json");
public final static ResourceLocation STATE_TRAPDOOR = BetterEnd.makeID("patterns/blockstate/trapdoor.json"); public final static ResourceLocation BLOCK_FENCE_SIDE = BetterEnd.makeID("patterns/block/fence_side.json");
public final static ResourceLocation STATE_LADDER = BetterEnd.makeID("patterns/blockstate/ladder.json"); public final static ResourceLocation BLOCK_BUTTON = BetterEnd.makeID("patterns/block/button.json");
public final static ResourceLocation STATE_BARREL = BetterEnd.makeID("patterns/blockstate/barrel.json"); public final static ResourceLocation BLOCK_BUTTON_PRESSED = BetterEnd.makeID("patterns/block/button_pressed.json");
public final static ResourceLocation STATE_PEDESTAL = BetterEnd.makeID("patterns/blockstate/pedestal.json"); public final static ResourceLocation BLOCK_PILLAR = BetterEnd.makeID("patterns/block/pillar.json");
public final static ResourceLocation STATE_STONE_LANTERN = BetterEnd.makeID("patterns/blockstate/stone_lantern.json"); public final static ResourceLocation BLOCK_PLATE_UP = BetterEnd.makeID("patterns/block/pressure_plate_up.json");
public final static ResourceLocation STATE_DIRECT = BetterEnd.makeID("patterns/blockstate/direct.json"); public final static ResourceLocation BLOCK_PLATE_DOWN = BetterEnd.makeID("patterns/block/pressure_plate_down.json");
public final static ResourceLocation STATE_BULB_LANTERN = BetterEnd.makeID("patterns/blockstate/bulb_lantern.json"); public final static ResourceLocation BLOCK_DOOR_TOP = BetterEnd.makeID("patterns/block/door_top.json");
public final static ResourceLocation STATE_COMPOSTER = BetterEnd.makeID("patterns/blockstate/composter.json"); public final static ResourceLocation BLOCK_DOOR_TOP_HINGE = BetterEnd.makeID("patterns/block/door_top_hinge.json");
public final static ResourceLocation STATE_BARS = BetterEnd.makeID("patterns/blockstate/bars.json"); public final static ResourceLocation BLOCK_DOOR_BOTTOM = BetterEnd.makeID("patterns/block/door_bottom.json");
public final static ResourceLocation STATE_ANVIL = BetterEnd.makeID("patterns/blockstate/anvil.json"); public final static ResourceLocation BLOCK_DOOR_BOTTOM_HINGE = BetterEnd.makeID("patterns/block/door_bottom_hinge.json");
public final static ResourceLocation STATE_ANVIL_LONG = BetterEnd.makeID("patterns/blockstate/anvil_long.json"); public final static ResourceLocation BLOCK_CROSS = BetterEnd.makeID("patterns/block/cross.json");
public final static ResourceLocation STATE_CHAIN = BetterEnd.makeID("patterns/blockstate/chain.json"); public final static ResourceLocation BLOCK_CROSS_SHADED = BetterEnd.makeID("patterns/block/cross_shaded.json");
public final static ResourceLocation STATE_CHANDELIER = BetterEnd.makeID("patterns/blockstate/chandelier.json"); public final static ResourceLocation BLOCK_GATE_CLOSED = BetterEnd.makeID("patterns/block/fence_gate_closed.json");
public final static ResourceLocation STATE_FURNACE = BetterEnd.makeID("patterns/blockstate/furnace.json"); public final static ResourceLocation BLOCK_GATE_CLOSED_WALL = BetterEnd.makeID("patterns/block/wall_gate_closed.json");
public final static ResourceLocation STATE_ROTATED_TOP = BetterEnd.makeID("patterns/blockstate/rotated_top.json"); public final static ResourceLocation BLOCK_GATE_OPEN = BetterEnd.makeID("patterns/block/fence_gate_open.json");
public final static ResourceLocation STATE_TRIPLE_ROTATED_TOP = BetterEnd.makeID("patterns/blockstate/triple_rotated_top.json"); public final static ResourceLocation BLOCK_GATE_OPEN_WALL = BetterEnd.makeID("patterns/block/wall_gate_open.json");
public final static ResourceLocation STATE_STALACTITE = BetterEnd.makeID("patterns/blockstate/stalactite.json"); public final static ResourceLocation BLOCK_TRAPDOOR = BetterEnd.makeID("patterns/block/trapdoor.json");
public final static ResourceLocation BLOCK_LADDER = BetterEnd.makeID("patterns/block/ladder.json");
//Models Block public final static ResourceLocation BLOCK_BARREL_OPEN = BetterEnd.makeID("patterns/block/barrel_open.json");
public final static ResourceLocation BLOCK_EMPTY = BetterEnd.makeID("patterns/block/empty.json"); public final static ResourceLocation BLOCK_PEDESTAL_DEFAULT = BetterEnd.makeID("patterns/block/pedestal_default.json");
public final static ResourceLocation BLOCK_BASE = BetterEnd.makeID("patterns/block/block.json"); public final static ResourceLocation BLOKC_PEDESTAL_COLUMN = BetterEnd.makeID("patterns/block/pedestal_column.json");
public final static ResourceLocation BLOCK_SIDED = BetterEnd.makeID("patterns/block/block_sided.json"); public final static ResourceLocation BLOCK_PEDESTAL_COLUMN_TOP = BetterEnd.makeID("patterns/block/pedestal_column_top.json");
public final static ResourceLocation BLOCK_BOTTOM_TOP = BetterEnd.makeID("patterns/block/block_bottom_top.json"); public final static ResourceLocation BLOCK_PEDESTAL_TOP = BetterEnd.makeID("patterns/block/pedestal_top.json");
public final static ResourceLocation BLOCK_SLAB = BetterEnd.makeID("patterns/block/slab.json"); public final static ResourceLocation BLOCK_PEDESTAL_BOTTOM = BetterEnd.makeID("patterns/block/pedestal_bottom.json");
public final static ResourceLocation BLOCK_STAIR = BetterEnd.makeID("patterns/block/stairs.json"); public final static ResourceLocation BLOCK_PEDESTAL_PILLAR = BetterEnd.makeID("patterns/block/pedestal_pillar.json");
public final static ResourceLocation BLOCK_STAIR_INNER = BetterEnd.makeID("patterns/block/inner_stairs.json"); public final static ResourceLocation BLOCK_BOOKSHELF = BetterEnd.makeID("patterns/block/bookshelf.json");
public final static ResourceLocation BLOCK_STAIR_OUTER = BetterEnd.makeID("patterns/block/outer_stairs.json"); public final static ResourceLocation BLOCK_STONE_LANTERN_CEIL = BetterEnd.makeID("patterns/block/stone_lantern_ceil.json");
public final static ResourceLocation BLOCK_WALL_POST = BetterEnd.makeID("patterns/block/wall_post.json"); public final static ResourceLocation BLOCK_STONE_LANTERN_FLOOR = BetterEnd.makeID("patterns/block/stone_lantern_floor.json");
public final static ResourceLocation BLOCK_WALL_SIDE = BetterEnd.makeID("patterns/block/wall_side.json"); public final static ResourceLocation BLOCK_BULB_LANTERN_FLOOR = BetterEnd.makeID("patterns/block/bulb_lantern_floor.json");
public final static ResourceLocation BLOCK_WALL_SIDE_TALL = BetterEnd.makeID("patterns/block/wall_side_tall.json"); public final static ResourceLocation BLOCK_BULB_LANTERN_CEIL = BetterEnd.makeID("patterns/block/bulb_lantern_ceil.json");
public final static ResourceLocation BLOCK_FENCE_POST = BetterEnd.makeID("patterns/block/fence_post.json"); public final static ResourceLocation BLOCK_PETAL_COLORED = BetterEnd.makeID("models/block/block_petal_colored.json");
public final static ResourceLocation BLOCK_FENCE_SIDE = BetterEnd.makeID("patterns/block/fence_side.json"); public final static ResourceLocation BLOCK_COMPOSTER = BetterEnd.makeID("patterns/block/composter.json");
public final static ResourceLocation BLOCK_BUTTON = BetterEnd.makeID("patterns/block/button.json"); public final static ResourceLocation BLOCK_COLORED = BetterEnd.makeID("patterns/block/block_colored.json");
public final static ResourceLocation BLOCK_BUTTON_PRESSED = BetterEnd.makeID("patterns/block/button_pressed.json"); public final static ResourceLocation BLOCK_BARS_POST = BetterEnd.makeID("patterns/block/bars_post.json");
public final static ResourceLocation BLOCK_PILLAR = BetterEnd.makeID("patterns/block/pillar.json"); public final static ResourceLocation BLOCK_BARS_SIDE = BetterEnd.makeID("patterns/block/bars_side.json");
public final static ResourceLocation BLOCK_PLATE_UP = BetterEnd.makeID("patterns/block/pressure_plate_up.json"); public final static ResourceLocation BLOCK_ANVIL = BetterEnd.makeID("patterns/block/anvil.json");
public final static ResourceLocation BLOCK_PLATE_DOWN = BetterEnd.makeID("patterns/block/pressure_plate_down.json"); public final static ResourceLocation BLOCK_CHAIN = BetterEnd.makeID("patterns/block/chain.json");
public final static ResourceLocation BLOCK_DOOR_TOP = BetterEnd.makeID("patterns/block/door_top.json"); public final static ResourceLocation BLOCK_CHANDELIER_FLOOR = BetterEnd.makeID("patterns/block/chandelier_floor.json");
public final static ResourceLocation BLOCK_DOOR_TOP_HINGE = BetterEnd.makeID("patterns/block/door_top_hinge.json"); public final static ResourceLocation BLOCK_CHANDELIER_WALL = BetterEnd.makeID("patterns/block/chandelier_wall.json");
public final static ResourceLocation BLOCK_DOOR_BOTTOM = BetterEnd.makeID("patterns/block/door_bottom.json"); public final static ResourceLocation BLOCK_CHANDELIER_CEIL = BetterEnd.makeID("patterns/block/chandelier_ceil.json");
public final static ResourceLocation BLOCK_DOOR_BOTTOM_HINGE = BetterEnd.makeID("patterns/block/door_bottom_hinge.json"); public final static ResourceLocation BLOCK_FURNACE = BetterEnd.makeID("patterns/block/furnace.json");
public final static ResourceLocation BLOCK_CROSS = BetterEnd.makeID("patterns/block/cross.json"); public final static ResourceLocation BLOCK_FURNACE_LIT = BetterEnd.makeID("patterns/block/furnace_glow.json");
public final static ResourceLocation BLOCK_CROSS_SHADED = BetterEnd.makeID("patterns/block/cross_shaded.json"); public final static ResourceLocation BLOCK_TOP_SIDE_BOTTOM = BetterEnd.makeID("patterns/block/top_side_bottom.json");
public final static ResourceLocation BLOCK_GATE_CLOSED = BetterEnd.makeID("patterns/block/fence_gate_closed.json"); public final static ResourceLocation BLOCK_PATH = BetterEnd.makeID("patterns/block/path.json");
public final static ResourceLocation BLOCK_GATE_CLOSED_WALL = BetterEnd.makeID("patterns/block/wall_gate_closed.json");
public final static ResourceLocation BLOCK_GATE_OPEN = BetterEnd.makeID("patterns/block/fence_gate_open.json"); //Item Models
public final static ResourceLocation BLOCK_GATE_OPEN_WALL = BetterEnd.makeID("patterns/block/wall_gate_open.json"); public final static ResourceLocation ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json");
public final static ResourceLocation BLOCK_TRAPDOOR = BetterEnd.makeID("patterns/block/trapdoor.json"); public final static ResourceLocation ITEM_FENCE = BetterEnd.makeID("patterns/item/pattern_fence.json");
public final static ResourceLocation BLOCK_LADDER = BetterEnd.makeID("patterns/block/ladder.json"); public final static ResourceLocation ITEM_BUTTON = BetterEnd.makeID("patterns/item/pattern_button.json");
public final static ResourceLocation BLOCK_BARREL_OPEN = BetterEnd.makeID("patterns/block/barrel_open.json"); public final static ResourceLocation ITEM_CHEST = BetterEnd.makeID("patterns/item/pattern_chest.json");
public final static ResourceLocation BLOCK_PEDESTAL_DEFAULT = BetterEnd.makeID("patterns/block/pedestal_default.json"); public final static ResourceLocation ITEM_BLOCK = BetterEnd.makeID("patterns/item/pattern_block_item.json");
public final static ResourceLocation BLOKC_PEDESTAL_COLUMN = BetterEnd.makeID("patterns/block/pedestal_column.json"); public final static ResourceLocation ITEM_GENERATED = BetterEnd.makeID("patterns/item/pattern_item_generated.json");
public final static ResourceLocation BLOCK_PEDESTAL_COLUMN_TOP = BetterEnd.makeID("patterns/block/pedestal_column_top.json"); public final static ResourceLocation ITEM_HANDHELD = BetterEnd.makeID("patterns/item/pattern_item_handheld.json");
public final static ResourceLocation BLOCK_PEDESTAL_TOP = BetterEnd.makeID("patterns/block/pedestal_top.json"); public final static ResourceLocation ITEM_SPAWN_EGG = BetterEnd.makeID("patterns/item/pattern_item_spawn_egg.json");
public final static ResourceLocation BLOCK_PEDESTAL_BOTTOM = BetterEnd.makeID("patterns/block/pedestal_bottom.json");
public final static ResourceLocation BLOCK_PEDESTAL_PILLAR = BetterEnd.makeID("patterns/block/pedestal_pillar.json"); public static Optional<String> createItemGenerated(String name) {
public final static ResourceLocation BLOCK_BOOKSHELF = BetterEnd.makeID("patterns/block/bookshelf.json"); return createJson(ITEM_GENERATED, name);
public final static ResourceLocation BLOCK_STONE_LANTERN_CEIL = BetterEnd.makeID("patterns/block/stone_lantern_ceil.json"); }
public final static ResourceLocation BLOCK_STONE_LANTERN_FLOOR = BetterEnd.makeID("patterns/block/stone_lantern_floor.json");
public final static ResourceLocation BLOCK_BULB_LANTERN_FLOOR = BetterEnd.makeID("patterns/block/bulb_lantern_floor.json"); public static Optional<String> createBlockSimple(String name) {
public final static ResourceLocation BLOCK_BULB_LANTERN_CEIL = BetterEnd.makeID("patterns/block/bulb_lantern_ceil.json"); return Patterns.createJson(Patterns.BLOCK_BASE, name, name);
public final static ResourceLocation BLOCK_PETAL_COLORED = BetterEnd.makeID("models/block/block_petal_colored.json"); }
public final static ResourceLocation BLOCK_COMPOSTER = BetterEnd.makeID("patterns/block/composter.json"); public static Optional<String> createBlockPillar(String name) {
public final static ResourceLocation BLOCK_COLORED = BetterEnd.makeID("patterns/block/block_colored.json"); return Patterns.createJson(Patterns.BLOCK_PILLAR, name, name);
public final static ResourceLocation BLOCK_BARS_POST = BetterEnd.makeID("patterns/block/bars_post.json"); }
public final static ResourceLocation BLOCK_BARS_SIDE = BetterEnd.makeID("patterns/block/bars_side.json");
public final static ResourceLocation BLOCK_ANVIL = BetterEnd.makeID("patterns/block/anvil.json"); public static String createJson(Reader data, String parent, String block) {
public final static ResourceLocation BLOCK_CHAIN = BetterEnd.makeID("patterns/block/chain.json"); try (BufferedReader buffer = new BufferedReader(data)) {
public final static ResourceLocation BLOCK_CHANDELIER_FLOOR = BetterEnd.makeID("patterns/block/chandelier_floor.json"); return buffer.lines().collect(Collectors.joining())
public final static ResourceLocation BLOCK_CHANDELIER_WALL = BetterEnd.makeID("patterns/block/chandelier_wall.json"); .replace("%parent%", parent)
public final static ResourceLocation BLOCK_CHANDELIER_CEIL = BetterEnd.makeID("patterns/block/chandelier_ceil.json"); .replace("%block%", block);
public final static ResourceLocation BLOCK_FURNACE = BetterEnd.makeID("patterns/block/furnace.json"); } catch (Exception ex) {
public final static ResourceLocation BLOCK_FURNACE_GLOW = BetterEnd.makeID("patterns/block/furnace_glow.json"); return null;
public final static ResourceLocation BLOCK_TOP_SIDE_BOTTOM = BetterEnd.makeID("patterns/block/top_side_bottom.json"); }
public final static ResourceLocation BLOCK_PATH = BetterEnd.makeID("patterns/block/path.json"); }
//Models Item public static Optional<String> createJson(ResourceLocation patternId, String parent, String block) {
public final static ResourceLocation ITEM_WALL = BetterEnd.makeID("patterns/item/pattern_wall.json"); ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
public final static ResourceLocation ITEM_FENCE = BetterEnd.makeID("patterns/item/pattern_fence.json"); try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
public final static ResourceLocation ITEM_BUTTON = BetterEnd.makeID("patterns/item/pattern_button.json"); return Optional.ofNullable(createJson(new InputStreamReader(input, StandardCharsets.UTF_8), parent, block));
public final static ResourceLocation ITEM_CHEST = BetterEnd.makeID("patterns/item/pattern_chest.json"); } catch (Exception ex) {
public final static ResourceLocation ITEM_BLOCK = BetterEnd.makeID("patterns/item/pattern_block_item.json"); return Optional.empty();
public final static ResourceLocation ITEM_GENERATED = BetterEnd.makeID("patterns/item/pattern_item_generated.json"); }
public final static ResourceLocation ITEM_HANDHELD = BetterEnd.makeID("patterns/item/pattern_item_handheld.json"); }
public final static ResourceLocation ITEM_SPAWN_EGG = BetterEnd.makeID("patterns/item/pattern_item_spawn_egg.json");
public static Optional<String> createJson(ResourceLocation patternId, String texture) {
public static String createItemGenerated(String name) { Map<String, String> textures = Maps.newHashMap();
return createJson(ITEM_GENERATED, name); textures.put("%texture%", texture);
} return createJson(patternId, textures);
}
public static String createJson(Reader data, String parent, String block) {
try (BufferedReader buffer = new BufferedReader(data)) { public static Optional<String> createJson(ResourceLocation patternId, Map<String, String> textures) {
return buffer.lines().collect(Collectors.joining()) ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
.replace("%parent%", parent) try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
.replace("%block%", block); String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
} catch (Exception ex) { .lines().collect(Collectors.joining());
return null; for (Entry<String, String> texture : textures.entrySet()) {
} json = json.replace(texture.getKey(), texture.getValue());
} }
return Optional.of(json);
public static String createJson(ResourceLocation patternId, String parent, String block) { } catch (Exception ex) {
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager(); return Optional.empty();
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) { }
return createJson(new InputStreamReader(input, StandardCharsets.UTF_8), parent, block); }
} catch (Exception ex) {
return null; }
}
}
public static String createJson(ResourceLocation patternId, String texture) {
Map<String, String> textures = Maps.newHashMap();
textures.put("%texture%", texture);
return createJson(patternId, textures);
}
public static String createJson(ResourceLocation patternId, Map<String, String> textures) {
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
.lines().collect(Collectors.joining());
for (Entry<String, String> texture : textures.entrySet()) {
json = json.replace(texture.getKey(), texture.getValue());
}
return json;
} catch (Exception ex) {
return null;
}
}
}

View file

@ -0,0 +1,17 @@
package ru.betterend.events;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.advancements.Advancement;
import net.minecraft.server.level.ServerPlayer;
public interface PlayerAdvancementsCallback {
Event<PlayerAdvancementsCallback> PLAYER_ADVANCEMENT_COMPLETE = EventFactory.createArrayBacked(PlayerAdvancementsCallback.class, callbacks -> (player, advancement, criterionName) -> {
for (PlayerAdvancementsCallback event : callbacks) {
event.onAdvancementComplete(player, advancement, criterionName);
}
});
void onAdvancementComplete(ServerPlayer player, Advancement advancement, String criterionName);
}

View file

@ -1,19 +0,0 @@
package ru.betterend.events;
import net.fabricmc.fabric.api.event.Event;
import net.fabricmc.fabric.api.event.EventFactory;
import net.minecraft.advancements.Advancement;
import net.minecraft.server.level.ServerPlayer;
public final class PlayerAdvancementsEvents {
public static Event<AdvancementComplete> PLAYER_ADVENCEMENT_COMPLETE = EventFactory.createArrayBacked(AdvancementComplete.class, callbacks -> (player, advancement, criterionName) -> {
for (AdvancementComplete event : callbacks) {
event.onAdvancementComplete(player, advancement, criterionName);
}
});
public interface AdvancementComplete {
void onAdvancementComplete(ServerPlayer player, Advancement advancement, String criterionName);
}
}

View file

@ -13,7 +13,7 @@ import net.minecraft.world.item.Items;
import net.minecraft.world.item.UseAnim; import net.minecraft.world.item.UseAnim;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
public class DrinkItem extends PatternedItem { public class DrinkItem extends ModelProviderItem {
public DrinkItem(Properties settings) { public DrinkItem(Properties settings) {
super(settings); super(settings);
} }

View file

@ -1,11 +1,16 @@
package ru.betterend.item; package ru.betterend.item;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity; import net.minecraft.world.item.Rarity;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndItems; import ru.betterend.registry.EndItems;
public class EnchantedPetalItem extends PatternedItem { import java.util.Optional;
public class EnchantedPetalItem extends ModelProviderItem {
public EnchantedPetalItem() { public EnchantedPetalItem() {
super(EndItems.makeItemSettings().rarity(Rarity.RARE).stacksTo(16)); super(EndItems.makeItemSettings().rarity(Rarity.RARE).stacksTo(16));
} }
@ -16,7 +21,7 @@ public class EnchantedPetalItem extends PatternedItem {
} }
@Override @Override
public String getModelPattern(String name) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/hydralux_petal"); return ModelsHelper.createItemModel("hydralux_petal");
} }
} }

View file

@ -1,7 +1,5 @@
package ru.betterend.item; package ru.betterend.item;
import java.util.UUID;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
@ -11,10 +9,13 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes; import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial; import net.minecraft.world.item.ArmorMaterial;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
public class EndArmorItem extends ArmorItem implements Patterned { import java.util.Optional;
import java.util.UUID;
public class EndArmorItem extends ArmorItem implements ItemModelProvider {
protected static final UUID[] ARMOR_MODIFIER_UUID_PER_SLOT = new UUID[] { protected static final UUID[] ARMOR_MODIFIER_UUID_PER_SLOT = new UUID[] {
UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"), UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"),
@ -47,9 +48,4 @@ public class EndArmorItem extends ArmorItem implements Patterned {
} }
defaultModifiers.put(attribute, modifier); defaultModifiers.put(attribute, modifier);
} }
@Override
public String getModelPattern(String name) {
return Patterns.createItemGenerated(name);
}
} }

View file

@ -3,17 +3,14 @@ package ru.betterend.item;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.FishBucketItem; import net.minecraft.world.item.FishBucketItem;
import net.minecraft.world.level.material.Fluids; import net.minecraft.world.level.material.Fluids;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndItems; import ru.betterend.registry.EndItems;
public class EndBucketItem extends FishBucketItem implements Patterned { import java.util.Optional;
public class EndBucketItem extends FishBucketItem implements ItemModelProvider {
public EndBucketItem(EntityType<?> type) { public EndBucketItem(EntityType<?> type) {
super(type, Fluids.WATER, EndItems.makeItemSettings().stacksTo(1)); super(type, Fluids.WATER, EndItems.makeItemSettings().stacksTo(1));
} }
@Override
public String getModelPattern(String name) {
return Patterns.createJson(Patterns.ITEM_GENERATED, name);
}
} }

View file

@ -0,0 +1,14 @@
package ru.betterend.item;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.RecordItem;
import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.client.models.Patterns;
import java.util.Optional;
public class EndDiscItem extends RecordItem implements ItemModelProvider {
public EndDiscItem(int comparatorOutput, SoundEvent sound, Properties settings) {
super(comparatorOutput, sound, settings);
}
}

View file

@ -1,17 +1,23 @@
package ru.betterend.item; package ru.betterend.item;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.SpawnEggItem; import net.minecraft.world.item.SpawnEggItem;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndSpawnEggItem extends SpawnEggItem implements Patterned { import java.util.Optional;
public class EndSpawnEggItem extends SpawnEggItem implements ItemModelProvider {
public EndSpawnEggItem(EntityType<?> type, int primaryColor, int secondaryColor, Properties settings) { public EndSpawnEggItem(EntityType<?> type, int primaryColor, int secondaryColor, Properties settings) {
super(type, primaryColor, secondaryColor, settings); super(type, primaryColor, secondaryColor, settings);
} }
@Override @Override
public String getModelPattern(String name) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
return Patterns.createJson(Patterns.ITEM_SPAWN_EGG, name); Optional<String> pattern = Patterns.createJson(Patterns.ITEM_SPAWN_EGG, resourceLocation.getPath());
return ModelsHelper.fromPattern(pattern);
} }
} }

View file

@ -3,7 +3,7 @@ package ru.betterend.item;
import net.minecraft.world.item.Rarity; import net.minecraft.world.item.Rarity;
import ru.betterend.registry.EndItems; import ru.betterend.registry.EndItems;
public class EternalCrystalItem extends PatternedItem { public class EternalCrystalItem extends ModelProviderItem {
public EternalCrystalItem() { public EternalCrystalItem() {
super(EndItems.makeItemSettings().stacksTo(16).rarity(Rarity.EPIC)); super(EndItems.makeItemSettings().stacksTo(16).rarity(Rarity.EPIC));
} }

View file

@ -18,7 +18,7 @@ import ru.betterend.registry.EndItems;
import ru.betterend.util.LangUtil; import ru.betterend.util.LangUtil;
import vazkii.patchouli.api.PatchouliAPI; import vazkii.patchouli.api.PatchouliAPI;
public class GuideBookItem extends PatternedItem { public class GuideBookItem extends ModelProviderItem {
public final static ResourceLocation BOOK_ID = BetterEnd.makeID("guidebook"); public final static ResourceLocation BOOK_ID = BetterEnd.makeID("guidebook");
public static final Item GUIDE_BOOK = EndItems.registerItem(BOOK_ID, new GuideBookItem()); public static final Item GUIDE_BOOK = EndItems.registerItem(BOOK_ID, new GuideBookItem());

View file

@ -0,0 +1,21 @@
package ru.betterend.item;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
import java.util.Optional;
public class ModelProviderItem extends Item implements ItemModelProvider {
public ModelProviderItem(Properties settings) {
super(settings);
}
@Override
public BlockModel getItemModel(ResourceLocation resourceLocation) {
return ModelsHelper.createItemModel(resourceLocation.getPath());
}
}

View file

@ -1,17 +0,0 @@
package ru.betterend.item;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.RecordItem;
import ru.betterend.patterns.Patterned;
import ru.betterend.patterns.Patterns;
public class PatternedDiscItem extends RecordItem implements Patterned {
public PatternedDiscItem(int comparatorOutput, SoundEvent sound, Properties settings) {
super(comparatorOutput, sound, settings);
}
@Override
public String getModelPattern(String name) {
return Patterns.createJson(Patterns.ITEM_GENERATED, name);
}
}

View file

@ -1,16 +0,0 @@
package ru.betterend.item;
import net.minecraft.world.item.Item;
import ru.betterend.patterns.Patterned;
import ru.betterend.patterns.Patterns;
public class PatternedItem extends Item implements Patterned {
public PatternedItem(Properties settings) {
super(settings);
}
@Override
public String getModelPattern(String name) {
return Patterns.createItemGenerated(name);
}
}

View file

@ -2,6 +2,8 @@ package ru.betterend.item.tool;
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.AxeItem; import net.minecraft.world.item.AxeItem;
@ -9,10 +11,13 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndAxeItem extends AxeItem implements DynamicAttributeTool, Patterned { import java.util.Optional;
public class EndAxeItem extends AxeItem implements DynamicAttributeTool, ItemModelProvider {
public EndAxeItem(Tier material, float attackDamage, float attackSpeed, Properties settings) { public EndAxeItem(Tier material, float attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings); super(material, attackDamage, attackSpeed, settings);
} }
@ -26,7 +31,7 @@ public class EndAxeItem extends AxeItem implements DynamicAttributeTool, Pattern
} }
@Override @Override
public String getModelPattern(String name) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
return Patterns.createJson(Patterns.ITEM_HANDHELD, name); return ModelsHelper.createHandheldItem(resourceLocation.getPath());
} }
} }

View file

@ -1,5 +1,6 @@
package ru.betterend.item.tool; package ru.betterend.item.tool;
import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import com.google.common.collect.ImmutableMultimap; import com.google.common.collect.ImmutableMultimap;
@ -9,7 +10,9 @@ import com.google.common.collect.Sets;
import io.netty.util.internal.ThreadLocalRandom; import io.netty.util.internal.ThreadLocalRandom;
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.util.Mth; import net.minecraft.util.Mth;
import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.EquipmentSlot;
@ -26,11 +29,12 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material; import net.minecraft.world.level.material.Material;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
import ru.betterend.registry.EndTags; import ru.betterend.registry.EndTags;
public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, Patterned { public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, ItemModelProvider {
public final static UUID ATTACK_KNOCKBACK_MODIFIER_ID = Mth.createInsecureUUID(ThreadLocalRandom.current()); public final static UUID ATTACK_KNOCKBACK_MODIFIER_ID = Mth.createInsecureUUID(ThreadLocalRandom.current());
private final Multimap<Attribute, AttributeModifier> attributeModifiers; private final Multimap<Attribute, AttributeModifier> attributeModifiers;
@ -57,9 +61,7 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P
@Override @Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
stack.hurtAndBreak(1, attacker, ((entity) -> { stack.hurtAndBreak(1, attacker, ((entity) -> entity.broadcastBreakEvent(EquipmentSlot.MAINHAND)));
entity.broadcastBreakEvent(EquipmentSlot.MAINHAND);
}));
return true; return true;
} }
@ -67,9 +69,7 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P
@Override @Override
public boolean mineBlock(ItemStack stack, Level world, BlockState state, BlockPos pos, LivingEntity miner) { public boolean mineBlock(ItemStack stack, Level world, BlockState state, BlockPos pos, LivingEntity miner) {
if (state.getDestroySpeed(world, pos) != 0.0F) { if (state.getDestroySpeed(world, pos) != 0.0F) {
stack.hurtAndBreak(1, miner, ((entity) -> { stack.hurtAndBreak(1, miner, ((entity) -> entity.broadcastBreakEvent(EquipmentSlot.MAINHAND)));
entity.broadcastBreakEvent(EquipmentSlot.MAINHAND);
}));
} }
return true; return true;
@ -81,13 +81,13 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P
return this.getTier().getSpeed() * 2.0F; return this.getTier().getSpeed() * 2.0F;
} }
if (isCorrectToolForDrops(state)) { if (isCorrectToolForDrops(state)) {
float mult = 1.0F; float mult;
if (state.is(Blocks.DIAMOND_BLOCK) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.LAPIS_BLOCK) || state.is(Blocks.REDSTONE_BLOCK)) { if (state.is(Blocks.DIAMOND_BLOCK) || state.is(Blocks.EMERALD_BLOCK) || state.is(Blocks.LAPIS_BLOCK) || state.is(Blocks.REDSTONE_BLOCK)) {
mult = this.getTier().getSpeed(); mult = this.getTier().getSpeed();
} else { } else {
mult = this.getTier().getSpeed() / 2.0F; mult = this.getTier().getSpeed() / 2.0F;
} }
return mult > 1.0F ? mult : 1.0F; return Math.max(mult, 1.0F);
} }
return 1.0F; return 1.0F;
} }
@ -135,7 +135,7 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, P
} }
@Override @Override
public String getModelPattern(String name) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
return Patterns.createJson(Patterns.ITEM_HANDHELD, name); return ModelsHelper.createHandheldItem(resourceLocation.getPath());
} }
} }

View file

@ -1,17 +1,22 @@
package ru.betterend.item.tool; package ru.betterend.item.tool;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.HoeItem; import net.minecraft.world.item.HoeItem;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndHoeItem extends HoeItem implements Patterned { import java.util.Optional;
public class EndHoeItem extends HoeItem implements ItemModelProvider {
public EndHoeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) { public EndHoeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings); super(material, attackDamage, attackSpeed, settings);
} }
@Override @Override
public String getModelPattern(String name) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
return Patterns.createJson(Patterns.ITEM_HANDHELD, name); return ModelsHelper.createHandheldItem(resourceLocation.getPath());
} }
} }

View file

@ -4,6 +4,8 @@ import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl; import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl;
import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry; import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
@ -12,10 +14,13 @@ import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndPickaxeItem extends PickaxeItem implements DynamicAttributeTool, Patterned { import java.util.Optional;
public class EndPickaxeItem extends PickaxeItem implements DynamicAttributeTool, ItemModelProvider {
public EndPickaxeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) { public EndPickaxeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings); super(material, attackDamage, attackSpeed, settings);
} }
@ -23,22 +28,22 @@ public class EndPickaxeItem extends PickaxeItem implements DynamicAttributeTool,
@Override @Override
public int getMiningLevel(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) { public int getMiningLevel(Tag<Item> tag, BlockState state, ItemStack stack, LivingEntity user) {
if (tag.equals(FabricToolTags.PICKAXES)) { if (tag.equals(FabricToolTags.PICKAXES)) {
return this.getTier().getLevel(); return getTier().getLevel();
} }
return 0; return 0;
} }
@Override @Override
public float getDestroySpeed(ItemStack stack, BlockState state) { public float getDestroySpeed(ItemStack stack, BlockState state) {
if (this.getTier().getLevel() > 2 && state.getMaterial().equals(Blocks.END_STONE.defaultBlockState().getMaterial())) { if (getTier().getLevel() > 2 && state.getMaterial().equals(Blocks.END_STONE.defaultBlockState().getMaterial())) {
return this.speed * 3; return speed * 3;
} }
Entry entry = ToolManagerImpl.entryNullable(state.getBlock()); Entry entry = ToolManagerImpl.entryNullable(state.getBlock());
return (entry != null && entry.getMiningLevel(FabricToolTags.PICKAXES) >= 0) ? this.speed : super.getDestroySpeed(stack, state); return (entry != null && entry.getMiningLevel(FabricToolTags.PICKAXES) >= 0) ? speed : super.getDestroySpeed(stack, state);
} }
@Override @Override
public String getModelPattern(String name) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
return Patterns.createJson(Patterns.ITEM_HANDHELD, name); return ModelsHelper.createHandheldItem(resourceLocation.getPath());
} }
} }

View file

@ -4,6 +4,8 @@ import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl; import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl;
import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry; import net.fabricmc.fabric.impl.tool.attribute.ToolManagerImpl.Entry;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.Tag; import net.minecraft.tags.Tag;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
@ -11,10 +13,13 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShovelItem; import net.minecraft.world.item.ShovelItem;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndShovelItem extends ShovelItem implements DynamicAttributeTool, Patterned { import java.util.Optional;
public class EndShovelItem extends ShovelItem implements DynamicAttributeTool, ItemModelProvider {
public EndShovelItem(Tier material, float attackDamage, float attackSpeed, Properties settings) { public EndShovelItem(Tier material, float attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings); super(material, attackDamage, attackSpeed, settings);
} }
@ -30,11 +35,11 @@ public class EndShovelItem extends ShovelItem implements DynamicAttributeTool, P
@Override @Override
public float getDestroySpeed(ItemStack stack, BlockState state) { public float getDestroySpeed(ItemStack stack, BlockState state) {
Entry entry = ToolManagerImpl.entryNullable(state.getBlock()); Entry entry = ToolManagerImpl.entryNullable(state.getBlock());
return (entry != null && entry.getMiningLevel(FabricToolTags.SHOVELS) >= 0) ? this.speed : super.getDestroySpeed(stack, state); return (entry != null && entry.getMiningLevel(FabricToolTags.SHOVELS) >= 0) ? speed : super.getDestroySpeed(stack, state);
} }
@Override @Override
public String getModelPattern(String name) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
return Patterns.createJson(Patterns.ITEM_HANDHELD, name); return ModelsHelper.createHandheldItem(resourceLocation.getPath());
} }
} }

View file

@ -1,18 +1,23 @@
package ru.betterend.item.tool; package ru.betterend.item.tool;
import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool; import net.fabricmc.fabric.api.tool.attribute.v1.DynamicAttributeTool;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.SwordItem; import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.patterns.Patterns; import ru.betterend.client.models.ModelsHelper;
import ru.betterend.client.models.Patterns;
public class EndSwordItem extends SwordItem implements DynamicAttributeTool, Patterned { import java.util.Optional;
public class EndSwordItem extends SwordItem implements DynamicAttributeTool, ItemModelProvider {
public EndSwordItem(Tier material, int attackDamage, float attackSpeed, Properties settings) { public EndSwordItem(Tier material, int attackDamage, float attackSpeed, Properties settings) {
super(material, attackDamage, attackSpeed, settings); super(material, attackDamage, attackSpeed, settings);
} }
@Override @Override
public String getModelPattern(String name) { public BlockModel getItemModel(ResourceLocation resourceLocation) {
return Patterns.createJson(Patterns.ITEM_HANDHELD, name); return ModelsHelper.createHandheldItem(resourceLocation.getPath());
} }
} }

View file

@ -1,63 +1,103 @@
package ru.betterend.mixin.client; package ru.betterend.mixin.client;
import java.io.InputStreamReader; import net.minecraft.client.renderer.block.BlockModelShaper;
import java.io.Reader; import net.minecraft.client.renderer.block.model.BlockModel;
import java.nio.charset.StandardCharsets; import net.minecraft.client.renderer.block.model.multipart.MultiPart;
import java.util.Optional; import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.spongepowered.asm.mixin.Final; import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyVariable; import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.patterns.Patterned; import ru.betterend.client.models.BlockModelProvider;
import ru.betterend.client.models.ItemModelProvider;
import ru.betterend.world.generator.GeneratorOptions; import ru.betterend.world.generator.GeneratorOptions;
import java.util.List;
import java.util.Map;
import java.util.Optional;
@Mixin(ModelBakery.class) @Mixin(ModelBakery.class)
public class ModelLoaderMixin { public abstract class ModelLoaderMixin {
@Final @Final
@Shadow @Shadow
private ResourceManager resourceManager; private ResourceManager resourceManager;
@Final
@Inject(method = "loadBlockModel", at = @At("HEAD"), cancellable = true) @Shadow
private void be_loadModelPattern(ResourceLocation id, CallbackInfoReturnable<BlockModel> info) { private Map<ResourceLocation, UnbakedModel> unbakedCache;
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
ResourceLocation modelId = new ResourceLocation(id.getNamespace(), "models/" + id.getPath() + ".json"); @Shadow
BlockModel model; protected abstract void cacheAndQueueDependencies(ResourceLocation resourceLocation, UnbakedModel unbakedModel);
try (Resource resource = this.resourceManager.getResource(modelId)) {
Reader reader = new InputStreamReader(resource.getInputStream(), StandardCharsets.UTF_8); @Inject(method = "loadModel", at = @At("HEAD"), cancellable = true)
model = BlockModel.fromStream(reader); private void be_loadModels(ResourceLocation resourceLocation, CallbackInfo info) {
model.name = id.toString(); if (resourceLocation instanceof ModelResourceLocation) {
info.setReturnValue(model); String modId = resourceLocation.getNamespace();
} catch (Exception ex) { String path = resourceLocation.getPath();
String[] data = id.getPath().split("/"); ResourceLocation clearLoc = new ResourceLocation(modId, path);
if (data.length > 1) { ModelResourceLocation modelId = (ModelResourceLocation) resourceLocation;
ResourceLocation itemId = new ResourceLocation(id.getNamespace(), data[1]); if ("inventory".equals(modelId.getVariant())) {
Optional<Block> block = Registry.BLOCK.getOptional(itemId); ResourceLocation itemLoc = new ResourceLocation(modId, "item/" + path);
if (block.isPresent()) { ResourceLocation itemModelLoc = new ResourceLocation(modId, "models/" + itemLoc.getPath() + ".json");
if (block.get() instanceof Patterned) { if (!resourceManager.hasResource(itemModelLoc)) {
Patterned patterned = (Patterned) block.get(); Item item = Registry.ITEM.get(clearLoc);
model = this.be_getModel(data, id, patterned); ItemModelProvider modelProvider = null;
info.setReturnValue(model); if (item instanceof ItemModelProvider) {
modelProvider = (ItemModelProvider) item;
} else if (item instanceof BlockItem) {
Block block = Registry.BLOCK.get(clearLoc);
if (block instanceof ItemModelProvider) {
modelProvider = (ItemModelProvider) block;
} }
} else { }
Optional<Item> item = Registry.ITEM.getOptional(itemId); if (modelProvider != null) {
if (item.isPresent() && item.get() instanceof Patterned) { BlockModel model = modelProvider.getItemModel(clearLoc);
Patterned patterned = (Patterned) item.get(); if (model != null) {
model = this.be_getModel(data, id, patterned); model.name = itemLoc.toString();
info.setReturnValue(model); cacheAndQueueDependencies(modelId, model);
unbakedCache.put(itemLoc, model);
} else {
BetterEnd.LOGGER.warning("Error loading model: {}", itemLoc);
}
info.cancel();
}
}
} else {
ResourceLocation stateLoc = new ResourceLocation(modId, "blockstates/" + path + ".json");
if (!resourceManager.hasResource(stateLoc)) {
Block block = Registry.BLOCK.get(clearLoc);
if (block instanceof BlockModelProvider) {
List<BlockState> possibleStates = block.getStateDefinition().getPossibleStates();
Optional<BlockState> possibleState = possibleStates.stream()
.filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state)))
.findFirst();
if (possibleState.isPresent()) {
UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, possibleState.get(), unbakedCache);
if (modelVariant != null) {
if (modelVariant instanceof MultiPart) {
possibleStates.forEach(state -> {
ResourceLocation stateId = BlockModelShaper.stateToModelLocation(clearLoc, state);
cacheAndQueueDependencies(stateId, modelVariant);
});
} else {
cacheAndQueueDependencies(modelId, modelVariant);
}
} else {
BetterEnd.LOGGER.warning("Error loading variant: {}", modelId);
}
info.cancel();
} }
} }
} }
@ -65,23 +105,6 @@ public class ModelLoaderMixin {
} }
} }
private BlockModel be_getModel(String[] data, ResourceLocation id, Patterned patterned) {
String pattern;
if (id.getPath().contains("item")) {
pattern = patterned.getModelPattern(id.getPath());
} else {
if (data.length > 2) {
pattern = patterned.getModelPattern(data[2]);
} else {
pattern = patterned.getModelPattern(data[1]);
}
}
BlockModel model = BlockModel.fromString(pattern);
model.name = id.toString();
return model;
}
@ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE")) @ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE"))
public ResourceLocation be_switchModel(ResourceLocation id) { public ResourceLocation be_switchModel(ResourceLocation id) {
if (GeneratorOptions.changeChorusPlant() && id.getNamespace().equals("minecraft") && id.getPath().startsWith("blockstates/") && id.getPath().contains("chorus") && !id.getPath().contains("custom_")) { if (GeneratorOptions.changeChorusPlant() && id.getNamespace().equals("minecraft") && id.getPath().startsWith("blockstates/") && id.getPath().contains("chorus") && !id.getPath().contains("custom_")) {

View file

@ -1,31 +0,0 @@
package ru.betterend.mixin.client;
import java.io.Reader;
import java.io.StringReader;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.google.gson.Gson;
import net.minecraft.client.renderer.block.model.BlockModelDefinition;
import net.minecraft.util.GsonHelper;
import net.minecraft.world.level.block.Block;
import ru.betterend.patterns.BlockPatterned;
@Mixin(BlockModelDefinition.class)
public abstract class ModelVariantMapMixin {
@Inject(method = "fromStream", at = @At("HEAD"), cancellable = true)
private static void be_deserializeBlockState(BlockModelDefinition.Context context, Reader reader, CallbackInfoReturnable<BlockModelDefinition> info) {
Block block = context.getDefinition().any().getBlock();
if (block instanceof BlockPatterned) {
String pattern = ((BlockPatterned) block).getStatesPattern(reader);
Gson gson = ContextGsonAccessor.class.cast(context).getGson();
BlockModelDefinition map = GsonHelper.fromJson(gson, new StringReader(pattern), BlockModelDefinition.class);
info.setReturnValue(map);
}
}
}

View file

@ -1,52 +0,0 @@
package ru.betterend.mixin.client;
import java.util.List;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.At.Shift;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import com.google.common.collect.Lists;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.FallbackResourceManager;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.world.level.block.Block;
import ru.betterend.BetterEnd;
import ru.betterend.patterns.BlockPatterned;
@Mixin(FallbackResourceManager.class)
public abstract class NamespaceResourceManagerMixin {
@Shadow
public abstract Resource getResource(ResourceLocation id);
@Inject(method = "getResources", cancellable = true, at = @At(
value = "NEW",
target = "java/io/FileNotFoundException",
shift = Shift.BEFORE))
public void be_getStatesPattern(ResourceLocation id, CallbackInfoReturnable<List<Resource>> info) {
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
String[] data = id.getPath().split("/");
if (data.length > 1) {
ResourceLocation blockId = BetterEnd.makeID(data[1].replace(".json", ""));
Block block = Registry.BLOCK.get(blockId);
if (block instanceof BlockPatterned) {
ResourceLocation stateId = ((BlockPatterned) block).statePatternId();
try {
List<Resource> resources = Lists.newArrayList();
Resource stateRes = this.getResource(stateId);
resources.add(stateRes);
info.setReturnValue(resources);
} catch (Exception ex) {
BetterEnd.LOGGER.catching(ex);
}
}
}
}
}
}

View file

@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.advancements.Advancement; import net.minecraft.advancements.Advancement;
import net.minecraft.server.PlayerAdvancements; import net.minecraft.server.PlayerAdvancements;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import ru.betterend.events.PlayerAdvancementsEvents; import ru.betterend.events.PlayerAdvancementsCallback;
@Mixin(PlayerAdvancements.class) @Mixin(PlayerAdvancements.class)
public abstract class PlayerAdvancementsMixin { public abstract class PlayerAdvancementsMixin {
@ -22,6 +22,6 @@ public abstract class PlayerAdvancementsMixin {
target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V", target = "Lnet/minecraft/advancements/AdvancementRewards;grant(Lnet/minecraft/server/level/ServerPlayer;)V",
shift = Shift.AFTER)) shift = Shift.AFTER))
public void be_award(Advancement advancement, String criterionName, CallbackInfoReturnable<Boolean> info) { public void be_award(Advancement advancement, String criterionName, CallbackInfoReturnable<Boolean> info) {
PlayerAdvancementsEvents.PLAYER_ADVENCEMENT_COMPLETE.invoker().onAdvancementComplete(player, advancement, criterionName); PlayerAdvancementsCallback.PLAYER_ADVANCEMENT_COMPLETE.invoker().onAdvancementComplete(player, advancement, criterionName);
} }
} }

View file

@ -1,14 +0,0 @@
package ru.betterend.patterns;
import java.io.Reader;
import net.minecraft.resources.ResourceLocation;
public interface BlockPatterned extends Patterned {
default String getStatesPattern(Reader data) {
return null;
}
default ResourceLocation statePatternId() {
return null;
}
}

View file

@ -1,7 +0,0 @@
package ru.betterend.patterns;
public interface Patterned {
default String getModelPattern(String name) {
return null;
}
}

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

@ -1,9 +1,6 @@
package ru.betterend.registry; package ru.betterend.registry;
import java.util.List;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings; import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags; import net.fabricmc.fabric.api.tool.attribute.v1.FabricToolTags;
import net.minecraft.core.BlockSource; import net.minecraft.core.BlockSource;
@ -20,42 +17,19 @@ import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.entity.MobSpawnType;
import net.minecraft.world.food.FoodProperties; import net.minecraft.world.food.FoodProperties;
import net.minecraft.world.food.Foods; import net.minecraft.world.food.Foods;
import net.minecraft.world.item.ArmorItem; import net.minecraft.world.item.*;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ShovelItem;
import net.minecraft.world.item.SpawnEggItem;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.TieredItem;
import net.minecraft.world.item.Tiers;
import net.minecraft.world.level.block.DispenserBlock; import net.minecraft.world.level.block.DispenserBlock;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.config.Configs; import ru.betterend.config.Configs;
import ru.betterend.item.ArmoredElytra; import ru.betterend.item.*;
import ru.betterend.item.CrystaliteBoots;
import ru.betterend.item.CrystaliteChestplate;
import ru.betterend.item.CrystaliteHelmet;
import ru.betterend.item.CrystaliteLeggings;
import ru.betterend.item.DrinkItem;
import ru.betterend.item.EnchantedPetalItem;
import ru.betterend.item.EndArmorItem;
import ru.betterend.item.EndBucketItem;
import ru.betterend.item.EndSpawnEggItem;
import ru.betterend.item.EternalCrystalItem;
import ru.betterend.item.PatternedDiscItem;
import ru.betterend.item.PatternedItem;
import ru.betterend.item.material.EndArmorMaterial; import ru.betterend.item.material.EndArmorMaterial;
import ru.betterend.item.material.EndToolMaterial; import ru.betterend.item.material.EndToolMaterial;
import ru.betterend.item.tool.EndAxeItem; import ru.betterend.item.tool.*;
import ru.betterend.item.tool.EndHammerItem;
import ru.betterend.item.tool.EndHoeItem;
import ru.betterend.item.tool.EndPickaxeItem;
import ru.betterend.item.tool.EndShovelItem;
import ru.betterend.item.tool.EndSwordItem;
import ru.betterend.tab.CreativeTabs; import ru.betterend.tab.CreativeTabs;
import ru.betterend.util.TagHelper; import ru.betterend.util.TagHelper;
import java.util.List;
public class EndItems { public class EndItems {
private static final List<Item> MOD_BLOCKS = Lists.newArrayList(); private static final List<Item> MOD_BLOCKS = Lists.newArrayList();
private static final List<Item> MOD_ITEMS = Lists.newArrayList(); private static final List<Item> MOD_ITEMS = Lists.newArrayList();
@ -143,11 +117,11 @@ public class EndItems {
public final static Item UMBRELLA_CLUSTER_JUICE = registerDrink("umbrella_cluster_juice", 5, 0.7F); public final static Item UMBRELLA_CLUSTER_JUICE = registerDrink("umbrella_cluster_juice", 5, 0.7F);
public static Item registerDisc(String name, int power, SoundEvent sound) { public static Item registerDisc(String name, int power, SoundEvent sound) {
return registerItem(BetterEnd.makeID(name), new PatternedDiscItem(power, sound, makeItemSettings())); return registerItem(BetterEnd.makeID(name), new EndDiscItem(power, sound, makeItemSettings()));
} }
public static Item registerItem(String name) { public static Item registerItem(String name) {
return registerItem(BetterEnd.makeID(name), new PatternedItem(makeItemSettings())); return registerItem(BetterEnd.makeID(name), new ModelProviderItem(makeItemSettings()));
} }
public static Item registerItem(String name, Item item) { public static Item registerItem(String name, Item item) {
@ -233,7 +207,7 @@ public class EndItems {
} }
public static Item registerFood(String name, FoodProperties foodComponent) { public static Item registerFood(String name, FoodProperties foodComponent) {
return registerItem(name, new PatternedItem(makeItemSettings().food(foodComponent))); return registerItem(name, new ModelProviderItem(makeItemSettings().food(foodComponent)));
} }
public static Item registerDrink(String name) { public static Item registerDrink(String name) {

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;

View file

@ -1,7 +0,0 @@
{
"variants": {
"": {
"model": "betterend:block/violecite"
}
}
}

View file

@ -1,16 +0,0 @@
{
"variants": {
"destruction=0,facing=east": { "model": "betterend:pattern/%block%/%block%_0", "y": 270 },
"destruction=0,facing=north": { "model": "betterend:pattern/%block%/%block%_0", "y": 180 },
"destruction=0,facing=south": { "model": "betterend:pattern/%block%/%block%_0" },
"destruction=0,facing=west": { "model": "betterend:pattern/%block%/%block%_0", "y": 90 },
"destruction=1,facing=east": { "model": "betterend:pattern/%block%/%block%_1", "y": 270 },
"destruction=1,facing=north": { "model": "betterend:pattern/%block%/%block%_1", "y": 180 },
"destruction=1,facing=south": { "model": "betterend:pattern/%block%/%block%_1" },
"destruction=1,facing=west": { "model": "betterend:pattern/%block%/%block%_1", "y": 90 },
"destruction=2,facing=east": { "model": "betterend:pattern/%block%/%block%_2", "y": 270 },
"destruction=2,facing=north": { "model": "betterend:pattern/%block%/%block%_2", "y": 180 },
"destruction=2,facing=south": { "model": "betterend:pattern/%block%/%block%_2" },
"destruction=2,facing=west": { "model": "betterend:pattern/%block%/%block%_2", "y": 90 }
}
}

View file

@ -1,48 +0,0 @@
{
"variants": {
"destruction=0,facing=east": { "model": "betterend:pattern/%block%/%block%_0", "y": 270 },
"destruction=0,facing=north": { "model": "betterend:pattern/%block%/%block%_0", "y": 180 },
"destruction=0,facing=south": { "model": "betterend:pattern/%block%/%block%_0" },
"destruction=0,facing=west": { "model": "betterend:pattern/%block%/%block%_0", "y": 90 },
"destruction=1,facing=east": { "model": "betterend:pattern/%block%/%block%_0", "y": 270 },
"destruction=1,facing=north": { "model": "betterend:pattern/%block%/%block%_0", "y": 180 },
"destruction=1,facing=south": { "model": "betterend:pattern/%block%/%block%_0" },
"destruction=1,facing=west": { "model": "betterend:pattern/%block%/%block%_0", "y": 90 },
"destruction=2,facing=east": { "model": "betterend:pattern/%block%/%block%_0", "y": 270 },
"destruction=2,facing=north": { "model": "betterend:pattern/%block%/%block%_0", "y": 180 },
"destruction=2,facing=south": { "model": "betterend:pattern/%block%/%block%_0" },
"destruction=2,facing=west": { "model": "betterend:pattern/%block%/%block%_0", "y": 90 },
"destruction=3,facing=east": { "model": "betterend:pattern/%block%/%block%_1", "y": 270 },
"destruction=3,facing=north": { "model": "betterend:pattern/%block%/%block%_1", "y": 180 },
"destruction=3,facing=south": { "model": "betterend:pattern/%block%/%block%_1" },
"destruction=3,facing=west": { "model": "betterend:pattern/%block%/%block%_1", "y": 90 },
"destruction=4,facing=east": { "model": "betterend:pattern/%block%/%block%_1", "y": 270 },
"destruction=4,facing=north": { "model": "betterend:pattern/%block%/%block%_1", "y": 180 },
"destruction=4,facing=south": { "model": "betterend:pattern/%block%/%block%_1" },
"destruction=4,facing=west": { "model": "betterend:pattern/%block%/%block%_1", "y": 90 },
"destruction=5,facing=east": { "model": "betterend:pattern/%block%/%block%_1", "y": 270 },
"destruction=5,facing=north": { "model": "betterend:pattern/%block%/%block%_1", "y": 180 },
"destruction=5,facing=south": { "model": "betterend:pattern/%block%/%block%_1" },
"destruction=5,facing=west": { "model": "betterend:pattern/%block%/%block%_1", "y": 90 },
"destruction=6,facing=east": { "model": "betterend:pattern/%block%/%block%_2", "y": 270 },
"destruction=6,facing=north": { "model": "betterend:pattern/%block%/%block%_2", "y": 180 },
"destruction=6,facing=south": { "model": "betterend:pattern/%block%/%block%_2" },
"destruction=6,facing=west": { "model": "betterend:pattern/%block%/%block%_2", "y": 90 },
"destruction=7,facing=east": { "model": "betterend:pattern/%block%/%block%_2", "y": 270 },
"destruction=7,facing=north": { "model": "betterend:pattern/%block%/%block%_2", "y": 180 },
"destruction=7,facing=south": { "model": "betterend:pattern/%block%/%block%_2" },
"destruction=7,facing=west": { "model": "betterend:pattern/%block%/%block%_2", "y": 90 },
"destruction=8,facing=east": { "model": "betterend:pattern/%block%/%block%_2", "y": 270 },
"destruction=8,facing=north": { "model": "betterend:pattern/%block%/%block%_2", "y": 180 },
"destruction=8,facing=south": { "model": "betterend:pattern/%block%/%block%_2" },
"destruction=8,facing=west": { "model": "betterend:pattern/%block%/%block%_2", "y": 90 }
}
}

View file

@ -1,56 +0,0 @@
{
"variants": {
"facing=down,open=false": {
"model": "betterend:pattern/%block%",
"x": 180
},
"facing=down,open=true": {
"model": "betterend:pattern/%block%/%block%_open",
"x": 180
},
"facing=east,open=false": {
"model": "betterend:pattern/%block%",
"x": 90,
"y": 90
},
"facing=east,open=true": {
"model": "betterend:pattern/%block%/%block%_open",
"x": 90,
"y": 90
},
"facing=north,open=false": {
"model": "betterend:pattern/%block%",
"x": 90
},
"facing=north,open=true": {
"model": "betterend:pattern/%block%/%block%_open",
"x": 90
},
"facing=south,open=false": {
"model": "betterend:pattern/%block%",
"x": 90,
"y": 180
},
"facing=south,open=true": {
"model": "betterend:pattern/%block%/%block%_open",
"x": 90,
"y": 180
},
"facing=up,open=false": {
"model": "betterend:pattern/%block%"
},
"facing=up,open=true": {
"model": "betterend:pattern/%block%/%block%_open"
},
"facing=west,open=false": {
"model": "betterend:pattern/%block%",
"x": 90,
"y": 270
},
"facing=west,open=true": {
"model": "betterend:pattern/%block%/%block%_open",
"x": 90,
"y": 270
}
}
}

View file

@ -1,53 +0,0 @@
{
"multipart": [
{
"when": {
"west": "false",
"east": "false",
"south": "false",
"north": "false"
},
"apply": {
"model": "betterend:pattern/%block%/%block%_post"
}
},
{
"when": {
"north": "true"
},
"apply": {
"model": "betterend:pattern/%block%/%block%_side"
}
},
{
"when": {
"east": "true"
},
"apply": {
"model": "betterend:pattern/%block%/%block%_side",
"uvlock": true,
"y": 90
}
},
{
"when": {
"south": "true"
},
"apply": {
"model": "betterend:pattern/%block%/%block%_side",
"uvlock": true,
"y": 180
}
},
{
"when": {
"west": "true"
},
"apply": {
"model": "betterend:pattern/%block%/%block%_side",
"uvlock": true,
"y": 270
}
}
]
}

View file

@ -1,7 +0,0 @@
{
"variants": {
"": {
"model": "betterend:pattern/%block%"
}
}
}

View file

@ -1,6 +0,0 @@
{
"variants": {
"is_floor=false": { "model": "betterend:pattern/%block%/%block%_ceil" },
"is_floor=true": { "model": "betterend:pattern/%block%/%block%_floor" }
}
}

View file

@ -1,118 +0,0 @@
{
"variants": {
"face=ceiling,facing=east,powered=false": {
"model": "betterend:pattern/%block%",
"x": 180,
"y": 270
},
"face=ceiling,facing=east,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"x": 180,
"y": 270
},
"face=ceiling,facing=north,powered=false": {
"model": "betterend:pattern/%block%",
"x": 180,
"y": 180
},
"face=ceiling,facing=north,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"x": 180,
"y": 180
},
"face=ceiling,facing=south,powered=false": {
"model": "betterend:pattern/%block%",
"x": 180
},
"face=ceiling,facing=south,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"x": 180
},
"face=ceiling,facing=west,powered=false": {
"model": "betterend:pattern/%block%",
"x": 180,
"y": 90
},
"face=ceiling,facing=west,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"x": 180,
"y": 90
},
"face=floor,facing=east,powered=false": {
"model": "betterend:pattern/%block%",
"y": 90
},
"face=floor,facing=east,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"y": 90
},
"face=floor,facing=north,powered=false": {
"model": "betterend:pattern/%block%"
},
"face=floor,facing=north,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed"
},
"face=floor,facing=south,powered=false": {
"model": "betterend:pattern/%block%",
"y": 180
},
"face=floor,facing=south,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"y": 180
},
"face=floor,facing=west,powered=false": {
"model": "betterend:pattern/%block%",
"y": 270
},
"face=floor,facing=west,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"y": 270
},
"face=wall,facing=east,powered=false": {
"model": "betterend:pattern/%block%",
"uvlock": true,
"x": 90,
"y": 90
},
"face=wall,facing=east,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"uvlock": true,
"x": 90,
"y": 90
},
"face=wall,facing=north,powered=false": {
"model": "betterend:pattern/%block%",
"uvlock": true,
"x": 90
},
"face=wall,facing=north,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"uvlock": true,
"x": 90
},
"face=wall,facing=south,powered=false": {
"model": "betterend:pattern/%block%",
"uvlock": true,
"x": 90,
"y": 180
},
"face=wall,facing=south,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"uvlock": true,
"x": 90,
"y": 180
},
"face=wall,facing=west,powered=false": {
"model": "betterend:pattern/%block%",
"uvlock": true,
"x": 90,
"y": 270
},
"face=wall,facing=west,powered=true": {
"model": "betterend:pattern/%block%/%block%_pressed",
"uvlock": true,
"x": 90,
"y": 270
}
}
}

View file

@ -1,16 +0,0 @@
{
"variants": {
"axis=x": {
"model": "betterend:pattern/%block%",
"x": 90,
"y": 90
},
"axis=y": {
"model": "betterend:pattern/%block%"
},
"axis=z": {
"model": "betterend:pattern/%block%",
"x": 90
}
}
}

View file

@ -1,10 +0,0 @@
{
"variants": {
"facing=up": { "model": "betterend:pattern/%block%/%block%_floor" },
"facing=down": { "model": "betterend:pattern/%block%/%block%_ceil" },
"facing=north": { "model": "betterend:pattern/%block%/%block%_wall", "y": 180 },
"facing=south": { "model": "betterend:pattern/%block%/%block%_wall" },
"facing=east": { "model": "betterend:pattern/%block%/%block%_wall", "y": 270 },
"facing=west": { "model": "betterend:pattern/%block%/%block%_wall", "y": 90 }
}
}

View file

@ -1,73 +0,0 @@
{
"multipart": [
{
"apply": {
"model": "betterend:pattern/%block%"
}
},
{
"when": {
"level": "1"
},
"apply": {
"model": "minecraft:block/composter_contents1"
}
},
{
"when": {
"level": "2"
},
"apply": {
"model": "minecraft:block/composter_contents2"
}
},
{
"when": {
"level": "3"
},
"apply": {
"model": "minecraft:block/composter_contents3"
}
},
{
"when": {
"level": "4"
},
"apply": {
"model": "minecraft:block/composter_contents4"
}
},
{
"when": {
"level": "5"
},
"apply": {
"model": "minecraft:block/composter_contents5"
}
},
{
"when": {
"level": "6"
},
"apply": {
"model": "minecraft:block/composter_contents6"
}
},
{
"when": {
"level": "7"
},
"apply": {
"model": "minecraft:block/composter_contents7"
}
},
{
"when": {
"level": "8"
},
"apply": {
"model": "minecraft:block/composter_contents_ready"
}
}
]
}

View file

@ -1,7 +0,0 @@
{
"variants": {
"": {
"model": "%block%"
}
}
}

View file

@ -1,124 +0,0 @@
{
"variants": {
"facing=east,half=lower,hinge=left,open=false": {
"model": "betterend:pattern/%block%/%block%_bottom"
},
"facing=east,half=lower,hinge=left,open=true": {
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
"y": 90
},
"facing=east,half=lower,hinge=right,open=false": {
"model": "betterend:pattern/%block%/%block%_bottom_hinge"
},
"facing=east,half=lower,hinge=right,open=true": {
"model": "betterend:pattern/%block%/%block%_bottom",
"y": 270
},
"facing=east,half=upper,hinge=left,open=false": {
"model": "betterend:pattern/%block%/%block%_top"
},
"facing=east,half=upper,hinge=left,open=true": {
"model": "betterend:pattern/%block%/%block%_top_hinge",
"y": 90
},
"facing=east,half=upper,hinge=right,open=false": {
"model": "betterend:pattern/%block%/%block%_top_hinge"
},
"facing=east,half=upper,hinge=right,open=true": {
"model": "betterend:pattern/%block%/%block%_top",
"y": 270
},
"facing=north,half=lower,hinge=left,open=false": {
"model": "betterend:pattern/%block%/%block%_bottom",
"y": 270
},
"facing=north,half=lower,hinge=left,open=true": {
"model": "betterend:pattern/%block%/%block%_bottom_hinge"
},
"facing=north,half=lower,hinge=right,open=false": {
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
"y": 270
},
"facing=north,half=lower,hinge=right,open=true": {
"model": "betterend:pattern/%block%/%block%_bottom",
"y": 180
},
"facing=north,half=upper,hinge=left,open=false": {
"model": "betterend:pattern/%block%/%block%_top",
"y": 270
},
"facing=north,half=upper,hinge=left,open=true": {
"model": "betterend:pattern/%block%/%block%_top_hinge"
},
"facing=north,half=upper,hinge=right,open=false": {
"model": "betterend:pattern/%block%/%block%_top_hinge",
"y": 270
},
"facing=north,half=upper,hinge=right,open=true": {
"model": "betterend:pattern/%block%/%block%_top",
"y": 180
},
"facing=south,half=lower,hinge=left,open=false": {
"model": "betterend:pattern/%block%/%block%_bottom",
"y": 90
},
"facing=south,half=lower,hinge=left,open=true": {
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
"y": 180
},
"facing=south,half=lower,hinge=right,open=false": {
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
"y": 90
},
"facing=south,half=lower,hinge=right,open=true": {
"model": "betterend:pattern/%block%/%block%_bottom"
},
"facing=south,half=upper,hinge=left,open=false": {
"model": "betterend:pattern/%block%/%block%_top",
"y": 90
},
"facing=south,half=upper,hinge=left,open=true": {
"model": "betterend:pattern/%block%/%block%_top_hinge",
"y": 180
},
"facing=south,half=upper,hinge=right,open=false": {
"model": "betterend:pattern/%block%/%block%_top_hinge",
"y": 90
},
"facing=south,half=upper,hinge=right,open=true": {
"model": "betterend:pattern/%block%/%block%_top"
},
"facing=west,half=lower,hinge=left,open=false": {
"model": "betterend:pattern/%block%/%block%_bottom",
"y": 180
},
"facing=west,half=lower,hinge=left,open=true": {
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
"y": 270
},
"facing=west,half=lower,hinge=right,open=false": {
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
"y": 180
},
"facing=west,half=lower,hinge=right,open=true": {
"model": "betterend:pattern/%block%/%block%_bottom",
"y": 90
},
"facing=west,half=upper,hinge=left,open=false": {
"model": "betterend:pattern/%block%/%block%_top",
"y": 180
},
"facing=west,half=upper,hinge=left,open=true": {
"model": "betterend:pattern/%block%/%block%_top_hinge",
"y": 270
},
"facing=west,half=upper,hinge=right,open=false": {
"model": "betterend:pattern/%block%/%block%_top_hinge",
"y": 180
},
"facing=west,half=upper,hinge=right,open=true": {
"model": "betterend:pattern/%block%/%block%_top",
"y": 90
}
}
}

Some files were not shown because too many files have changed in this diff Show more