Change models loading (still WIP)
This commit is contained in:
parent
2d23ca72ea
commit
744fe40a00
64 changed files with 437 additions and 269 deletions
|
@ -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));
|
||||||
|
|
|
@ -11,21 +11,15 @@ import ru.betterend.client.models.Patterns;
|
||||||
import ru.betterend.registry.EndBlocks;
|
import ru.betterend.registry.EndBlocks;
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ru.betterend.blocks;
|
||||||
|
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ public class BulbVineLanternBlock extends EndLanternBlock implements IRenderType
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
Map<String, String> map = Maps.newHashMap();
|
Map<String, String> map = Maps.newHashMap();
|
||||||
map.put("%glow%", getGlowTexture());
|
map.put("%glow%", getGlowTexture());
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ru.betterend.blocks;
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.EnumMap;
|
import java.util.EnumMap;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ public class ChandelierBlock extends AttachedBlock implements IRenderTypeable, B
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(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_GENERATED, "item/" + blockId.getPath());
|
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/" + blockId.getPath());
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks;
|
||||||
import java.io.Reader;
|
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 org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
@ -93,7 +94,7 @@ public class EmeraldIceBlock extends HalfTransparentBlock implements IRenderType
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
|
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks;
|
||||||
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;
|
||||||
|
|
||||||
|
@ -55,7 +56,7 @@ public class EndPathBlock extends BlockBaseNotFull {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
String name = Registry.BLOCK.getKey(this).getPath();
|
String name = Registry.BLOCK.getKey(this).getPath();
|
||||||
Map<String, String> map = Maps.newHashMap();
|
Map<String, String> map = Maps.newHashMap();
|
||||||
map.put("%top%", name + "_top");
|
map.put("%top%", name + "_top");
|
||||||
|
|
|
@ -1,9 +1,6 @@
|
||||||
package ru.betterend.blocks;
|
package ru.betterend.blocks;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
|
||||||
|
@ -95,7 +92,7 @@ public class EndTerrainBlock extends BlockBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
String name = Registry.BLOCK.getKey(this).getPath();
|
String name = Registry.BLOCK.getKey(this).getPath();
|
||||||
Map<String, String> map = Maps.newHashMap();
|
Map<String, String> map = Maps.newHashMap();
|
||||||
map.put("%top%", "betterend:block/" + name + "_top");
|
map.put("%top%", "betterend:block/" + name + "_top");
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.betterend.blocks;
|
package ru.betterend.blocks;
|
||||||
|
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -36,7 +37,7 @@ public class HydraluxPetalColoredBlock extends HydraluxPetalBlock implements ICo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
String path = "betterend:block/block_petal_colored";
|
String path = "betterend:block/block_petal_colored";
|
||||||
return Patterns.createJson(Patterns.BLOCK_PETAL_COLORED, path, path);
|
return Patterns.createJson(Patterns.BLOCK_PETAL_COLORED, path, path);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package ru.betterend.blocks;
|
||||||
|
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
|
||||||
|
@ -73,7 +74,7 @@ public class JellyshroomCapBlock extends SlimeBlock implements IRenderTypeable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
return Patterns.createJson(Patterns.BLOCK_COLORED, "jellyshroom_cap");
|
return Patterns.createJson(Patterns.BLOCK_COLORED, "jellyshroom_cap");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
|
||||||
|
@ -74,7 +75,7 @@ public class UmbrellaTreeMembraneBlock extends SlimeBlock implements IRenderType
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
|
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.betterend.blocks.basis;
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -18,7 +19,7 @@ public class BarkBlock extends EndPillarBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String createBlockPattern(ResourceLocation blockId) {
|
protected Optional<String> createBlockPattern(ResourceLocation blockId) {
|
||||||
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());
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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.client.renderer.block.model.BlockModel;
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
@ -31,7 +32,7 @@ public class BlockBase extends Block implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
return Patterns.createBlockSimple(blockId.getPath());
|
return Patterns.createBlockSimple(blockId.getPath());
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,14 @@ 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.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
|
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;
|
||||||
|
@ -38,7 +40,7 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
@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() {
|
||||||
|
@ -64,7 +66,7 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
Map<String, String> map = Maps.newHashMap();
|
Map<String, String> map = Maps.newHashMap();
|
||||||
map.put("%anvil%", blockId.getPath());
|
map.put("%anvil%", blockId.getPath());
|
||||||
|
@ -98,19 +100,18 @@ public class EndAnvilBlock extends AnvilBlock implements BlockModelProvider {
|
||||||
Map<String, String> textures = Maps.newHashMap();
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
textures.put("%anvil%", name);
|
textures.put("%anvil%", name);
|
||||||
textures.put("%top%", name + "_top_" + destruction);
|
textures.put("%top%", name + "_top_" + destruction);
|
||||||
String pattern = Patterns.createJson(Patterns.BLOCK_ANVIL, textures);
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_ANVIL, textures);
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
IntegerProperty destructionProperty = getDestructionProperty();
|
IntegerProperty destructionProperty = getDestructionProperty();
|
||||||
int destruction = blockState.getValue(destructionProperty);
|
int destruction = blockState.getValue(destructionProperty);
|
||||||
String modId = resourceLocation.getNamespace();
|
String modId = resourceLocation.getNamespace();
|
||||||
String modelId = "block/" + resourceLocation.getPath() + "_top_" + destruction;
|
String modelId = "block/" + resourceLocation.getPath() + "_top_" + destruction;
|
||||||
ResourceLocation modelLocation = new ResourceLocation(modId, modelId);
|
ResourceLocation modelLocation = new ResourceLocation(modId, modelId);
|
||||||
System.out.println(modelLocation);
|
registerBlockModel(resourceLocation, modelLocation, blockState, modelCache);
|
||||||
ModelsHelper.addBlockState(blockState, modelLocation);
|
|
||||||
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING).getOpposite());
|
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING).getOpposite());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,13 +2,15 @@ package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.io.Reader;
|
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.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
|
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;
|
||||||
|
@ -99,7 +101,7 @@ public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
String texture = Registry.BLOCK.getKey(this).getPath();
|
String texture = Registry.BLOCK.getKey(this).getPath();
|
||||||
if (block.contains("open")) {
|
if (block.contains("open")) {
|
||||||
return Patterns.createJson(Patterns.BLOCK_BARREL_OPEN, texture, texture);
|
return Patterns.createJson(Patterns.BLOCK_BARREL_OPEN, texture, texture);
|
||||||
|
@ -120,24 +122,21 @@ public class EndBarrelBlock extends BarrelBlock implements BlockModelProvider {
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String texture = blockId.getPath();
|
String texture = blockId.getPath();
|
||||||
String pattern;
|
Optional<String> pattern;
|
||||||
if (blockState.getValue(OPEN)) {
|
if (blockState.getValue(OPEN)) {
|
||||||
pattern = Patterns.createJson(Patterns.BLOCK_BARREL_OPEN, texture, texture);
|
pattern = Patterns.createJson(Patterns.BLOCK_BARREL_OPEN, texture, texture);
|
||||||
} else {
|
} else {
|
||||||
pattern = Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture);
|
pattern = Patterns.createJson(Patterns.BLOCK_BOTTOM_TOP, texture, texture);
|
||||||
}
|
}
|
||||||
if (pattern != null) {
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
return BlockModel.fromString(pattern);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
String open = blockState.getValue(OPEN) ? "_open" : "";
|
String open = blockState.getValue(OPEN) ? "_open" : "";
|
||||||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||||
"block/" + resourceLocation.getPath() + open);
|
"block/" + resourceLocation.getPath() + open);
|
||||||
ModelsHelper.addBlockState(blockState, modelId);
|
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||||
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING));
|
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -40,7 +42,7 @@ public class EndBookshelfBlock extends BlockBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
return Patterns.createJson(Patterns.BLOCK_BOOKSHELF, getName(blockId), blockId.getPath());
|
return Patterns.createJson(Patterns.BLOCK_BOOKSHELF, getName(blockId), blockId.getPath());
|
||||||
}
|
}
|
||||||
|
@ -50,7 +52,14 @@ public class EndBookshelfBlock extends BlockBase {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
return Patterns.createJson(data, getName(blockId), blockId.getPath());
|
return Patterns.createJson(data, getName(blockId), blockId.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_BOOKSHELF,
|
||||||
|
getName(blockId), blockId.getPath());
|
||||||
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
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", "");
|
||||||
|
|
|
@ -3,10 +3,13 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
|
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;
|
||||||
|
@ -40,7 +43,7 @@ public class EndChainBlock extends ChainBlock implements BlockModelProvider, IRe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
if (block.contains("item")) {
|
if (block.contains("item")) {
|
||||||
return Patterns.createItemGenerated(block);
|
return Patterns.createItemGenerated(block);
|
||||||
|
@ -61,18 +64,16 @@ public class EndChainBlock extends ChainBlock implements BlockModelProvider, IRe
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String name = blockId.getPath();
|
String name = blockId.getPath();
|
||||||
String pattern = Patterns.createJson(Patterns.BLOCK_CHAIN, name, name);
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CHAIN, name, name);
|
||||||
if (pattern != null) {
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
return BlockModel.fromString(pattern);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
Direction.Axis axis = blockState.getValue(AXIS);
|
Direction.Axis axis = blockState.getValue(AXIS);
|
||||||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||||
"block/" + resourceLocation.getPath());
|
"block/" + resourceLocation.getPath());
|
||||||
|
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||||
return ModelsHelper.createRotatedModel(modelId, axis);
|
return ModelsHelper.createRotatedModel(modelId, axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,10 +2,10 @@ package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.io.Reader;
|
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.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
|
||||||
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;
|
||||||
|
@ -16,7 +16,6 @@ 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.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
import ru.betterend.client.models.ModelsHelper;
|
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
import ru.betterend.registry.EndBlockEntities;
|
import ru.betterend.registry.EndBlockEntities;
|
||||||
|
|
||||||
|
@ -50,7 +49,7 @@ public class EndChestBlock extends ChestBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String path) {
|
public Optional<String> getModelString(String path) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
if (path.contains("item")) {
|
if (path.contains("item")) {
|
||||||
|
@ -61,8 +60,8 @@ public class EndChestBlock extends ChestBlock implements BlockModelProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation blockId) {
|
public BlockModel getModel(ResourceLocation blockId) {
|
||||||
String pattern = Patterns.createJson(Patterns.ITEM_CHEST, blockId.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_CHEST, blockId.getPath());
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -73,7 +72,7 @@ public class EndChestBlock extends ChestBlock implements BlockModelProvider {
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
String pattern = Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_EMPTY, parentId.getPath());
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,13 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
|
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;
|
||||||
|
@ -34,7 +37,7 @@ public class EndComposterBlock extends ComposterBlock implements BlockModelProvi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
String blockName = blockId.getPath();
|
String blockName = blockId.getPath();
|
||||||
return Patterns.createJson(Patterns.BLOCK_COMPOSTER, blockName);
|
return Patterns.createJson(Patterns.BLOCK_COMPOSTER, blockName);
|
||||||
|
@ -56,7 +59,7 @@ public class EndComposterBlock extends ComposterBlock implements BlockModelProvi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@ 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.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
|
||||||
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;
|
||||||
|
@ -16,7 +16,6 @@ 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.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
import ru.betterend.client.models.ModelsHelper;
|
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
public class EndCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider {
|
public class EndCraftingTableBlock extends CraftingTableBlock implements BlockModelProvider {
|
||||||
|
@ -36,7 +35,7 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockMo
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
String blockName = blockId.getPath();
|
String blockName = blockId.getPath();
|
||||||
return Patterns.createJson(Patterns.BLOCK_SIDED, new HashMap<String, String>() {
|
return Patterns.createJson(Patterns.BLOCK_SIDED, new HashMap<String, String>() {
|
||||||
|
@ -66,7 +65,7 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockMo
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
String blockName = blockId.getPath();
|
String blockName = blockId.getPath();
|
||||||
String pattern = 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");
|
||||||
|
@ -78,6 +77,6 @@ public class EndCraftingTableBlock extends CraftingTableBlock implements BlockMo
|
||||||
put("%east%", blockName + "_side");
|
put("%east%", blockName + "_side");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,25 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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 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.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.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 ru.betterend.client.render.ERenderLayer;
|
import ru.betterend.client.render.ERenderLayer;
|
||||||
|
@ -41,9 +52,9 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockMod
|
||||||
String blockId = Registry.BLOCK.getKey(this).getPath();
|
String blockId = Registry.BLOCK.getKey(this).getPath();
|
||||||
return Patterns.createJson(data, blockId, blockId);
|
return Patterns.createJson(data, blockId, blockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
String blockId = Registry.BLOCK.getKey(this).getPath();
|
String blockId = Registry.BLOCK.getKey(this).getPath();
|
||||||
if (block.contains("item")) {
|
if (block.contains("item")) {
|
||||||
return Patterns.createJson(Patterns.ITEM_GENERATED, block);
|
return Patterns.createJson(Patterns.ITEM_GENERATED, block);
|
||||||
|
@ -59,9 +70,127 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockMod
|
||||||
}
|
}
|
||||||
return Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM, blockId, blockId);
|
return Patterns.createJson(Patterns.BLOCK_DOOR_BOTTOM, blockId, blockId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
|
String blockName = resourceLocation.getPath();
|
||||||
|
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 pattern.map(BlockModel::fromString).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
|
Direction facing = blockState.getValue(FACING);
|
||||||
|
DoorType doorType = getDoorType(blockState);
|
||||||
|
boolean open = blockState.getValue(OPEN);
|
||||||
|
boolean hinge = doorType.isHinge();
|
||||||
|
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
|
||||||
|
switch (facing) {
|
||||||
|
case EAST: {
|
||||||
|
if (hinge && open) {
|
||||||
|
rotation = BlockModelRotation.by(0, 90);
|
||||||
|
} else if (open) {
|
||||||
|
rotation = BlockModelRotation.by(0, 270);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case SOUTH: {
|
||||||
|
if (!hinge && !open || hinge && !open) {
|
||||||
|
rotation = BlockModelRotation.by(0, 90);
|
||||||
|
} else if (hinge) {
|
||||||
|
rotation = BlockModelRotation.by(0, 180);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case WEST: {
|
||||||
|
if (!hinge && !open || hinge && !open) {
|
||||||
|
rotation = BlockModelRotation.by(0, 180);
|
||||||
|
} else if (hinge) {
|
||||||
|
rotation = BlockModelRotation.by(0, 270);
|
||||||
|
} else {
|
||||||
|
rotation = BlockModelRotation.by(0, 90);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case NORTH: {
|
||||||
|
if (!hinge && !open || hinge && !open) {
|
||||||
|
rotation = BlockModelRotation.by(0, 270);
|
||||||
|
} else if (!hinge) {
|
||||||
|
rotation = BlockModelRotation.by(0, 180);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||||
|
"block/" + resourceLocation.getPath() + "_" + doorType);
|
||||||
|
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||||
|
Variant variant = new Variant(modelId, rotation.getRotation(), false, 1);
|
||||||
|
return new MultiVariant(Lists.newArrayList(variant));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResourceLocation statePatternId() {
|
public ResourceLocation statePatternId() {
|
||||||
return Patterns.STATE_DOOR;
|
return Patterns.STATE_DOOR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected DoorType getDoorType(BlockState blockState) {
|
||||||
|
boolean isHinge = isHinge(blockState.getValue(HINGE), blockState.getValue(OPEN));
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -36,7 +37,7 @@ public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
if (block.contains("item")) {
|
if (block.contains("item")) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -10,8 +11,8 @@ 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.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
|
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.stats.Stats;
|
import net.minecraft.stats.Stats;
|
||||||
|
@ -59,7 +60,7 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
Map<String, String> map = Maps.newHashMap();
|
Map<String, String> map = Maps.newHashMap();
|
||||||
map.put("%top%", blockId.getPath() + "_top");
|
map.put("%top%", blockId.getPath() + "_top");
|
||||||
|
@ -86,7 +87,7 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider,
|
||||||
Map<String, String> textures = Maps.newHashMap();
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
textures.put("%top%", blockName + "_top");
|
textures.put("%top%", blockName + "_top");
|
||||||
textures.put("%side%", blockName + "_side");
|
textures.put("%side%", blockName + "_side");
|
||||||
String pattern;
|
Optional<String> pattern;
|
||||||
if (blockState.getValue(LIT)) {
|
if (blockState.getValue(LIT)) {
|
||||||
textures.put("%front%", blockName + "_front_on");
|
textures.put("%front%", blockName + "_front_on");
|
||||||
textures.put("%glow%", blockName + "_glow");
|
textures.put("%glow%", blockName + "_glow");
|
||||||
|
@ -95,7 +96,7 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider,
|
||||||
textures.put("%front%", blockName + "_front");
|
textures.put("%front%", blockName + "_front");
|
||||||
pattern = Patterns.createJson(Patterns.BLOCK_FURNACE, textures);
|
pattern = Patterns.createJson(Patterns.BLOCK_FURNACE, textures);
|
||||||
}
|
}
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,11 +105,11 @@ public class EndFurnaceBlock extends FurnaceBlock implements BlockModelProvider,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
String lit = blockState.getValue(LIT) ? "_lit" : "";
|
String lit = blockState.getValue(LIT) ? "_lit" : "";
|
||||||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||||
"block/" + resourceLocation.getPath() + lit);
|
"block/" + resourceLocation.getPath() + lit);
|
||||||
ModelsHelper.addBlockState(blockState, modelId);
|
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||||
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING));
|
return ModelsHelper.createFacingModel(modelId, blockState.getValue(FACING));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -36,7 +37,7 @@ public class EndGateBlock extends FenceGateBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
if (block.contains("wall")) {
|
if (block.contains("wall")) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.betterend.blocks.basis;
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.io.Reader;
|
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.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -144,7 +145,7 @@ public class EndLadderBlock extends BlockBaseNotFull implements IRenderTypeable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(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());
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ public class EndLeavesBlock extends LeavesBlock implements BlockModelProvider, I
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
String blockId = Registry.BLOCK.getKey(this).getPath();
|
String blockId = Registry.BLOCK.getKey(this).getPath();
|
||||||
return Patterns.createJson(Patterns.BLOCK_BASE, blockId, blockId);
|
return Patterns.createJson(Patterns.BLOCK_BASE, blockId, blockId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
@ -37,7 +38,7 @@ public class EndMetalPaneBlock extends IronBarsBlock implements BlockModelProvid
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(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());
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -36,7 +37,7 @@ public class EndMetalPlateBlock extends WeightedPressurePlateBlock implements Bl
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
if (block.contains("down")) {
|
if (block.contains("down")) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -78,7 +79,7 @@ public class EndOreBlock extends OreBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
|
return Patterns.createJson(Patterns.BLOCK_BASE, blockId.getPath(), block);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,11 +3,13 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
import net.minecraft.core.Direction;
|
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;
|
||||||
|
@ -45,7 +47,7 @@ public class EndPillarBlock extends RotatedPillarBlock implements BlockModelProv
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
return createBlockPattern(blockId);
|
return createBlockPattern(blockId);
|
||||||
}
|
}
|
||||||
|
@ -57,18 +59,19 @@ public class EndPillarBlock extends RotatedPillarBlock implements BlockModelProv
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public BlockModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
return BlockModel.fromString(createBlockPattern(blockId));
|
Optional<String> pattern = createBlockPattern(blockId);
|
||||||
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||||
"block/" + resourceLocation.getPath());
|
"block/" + resourceLocation.getPath());
|
||||||
ModelsHelper.addBlockState(blockState, modelId);
|
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||||
return ModelsHelper.createRotatedModel(modelId, blockState.getValue(AXIS));
|
return ModelsHelper.createRotatedModel(modelId, blockState.getValue(AXIS));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createBlockPattern(ResourceLocation blockId) {
|
protected Optional<String> createBlockPattern(ResourceLocation blockId) {
|
||||||
return Patterns.createBlockPillar(blockId.getPath());
|
return Patterns.createBlockPillar(blockId.getPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -36,7 +37,7 @@ public class EndPlateBlock extends PressurePlateBlock implements BlockModelProvi
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
if (block.contains("down")) {
|
if (block.contains("down")) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
@ -152,7 +153,7 @@ public class EndSignBlock extends SignBlock implements BlockModelProvider, ISpet
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String path) {
|
public Optional<String> getModelString(String path) {
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
if (path.contains("item")) {
|
if (path.contains("item")) {
|
||||||
return Patterns.createJson(Patterns.ITEM_GENERATED, path);
|
return Patterns.createJson(Patterns.ITEM_GENERATED, path);
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -36,7 +37,7 @@ public class EndSlabBlock extends SlabBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
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());
|
return Patterns.createJson(Patterns.BLOCK_SLAB, parentId.getPath(), blockId.getPath());
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -37,16 +38,17 @@ public class EndStairsBlock extends StairBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_STAIR, parentId.getPath(), blockId.getPath());
|
||||||
if (block.contains("inner")) {
|
if (block.contains("inner")) {
|
||||||
return Patterns.createJson(Patterns.BLOCK_STAIR_INNER, parentId.getPath(), blockId.getPath());
|
pattern = Patterns.createJson(Patterns.BLOCK_STAIR_INNER, parentId.getPath(), blockId.getPath());
|
||||||
}
|
}
|
||||||
if (block.contains("outer")) {
|
if (block.contains("outer")) {
|
||||||
return Patterns.createJson(Patterns.BLOCK_STAIR_OUTER, parentId.getPath(), blockId.getPath());
|
pattern = Patterns.createJson(Patterns.BLOCK_STAIR_OUTER, parentId.getPath(), blockId.getPath());
|
||||||
}
|
}
|
||||||
return Patterns.createJson(Patterns.BLOCK_STAIR, parentId.getPath(), blockId.getPath());
|
return pattern;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -36,7 +37,7 @@ public class EndStoneButtonBlock extends StoneButtonBlock implements BlockModelP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
if (block.contains("item")) {
|
if (block.contains("item")) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ 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.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
|
@ -40,7 +41,7 @@ public class EndTrapdoorBlock extends TrapDoorBlock implements IRenderTypeable,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
String name = blockId.getPath();
|
String name = blockId.getPath();
|
||||||
return Patterns.createJson(Patterns.BLOCK_TRAPDOOR, new HashMap<String, String>() {
|
return Patterns.createJson(Patterns.BLOCK_TRAPDOOR, new HashMap<String, String>() {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -37,7 +38,7 @@ public class EndWallBlock extends WallBlock implements BlockModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
if (block.contains("item")) {
|
if (block.contains("item")) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -36,7 +37,7 @@ public class EndWoodenButtonBlock extends WoodButtonBlock implements BlockModelP
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
ResourceLocation blockId = Registry.BLOCK.getKey(this);
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
if (block.contains("item")) {
|
if (block.contains("item")) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.blocks.basis;
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -116,7 +117,7 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
if (block.contains("item")) {
|
if (block.contains("item")) {
|
||||||
block = block.split("/")[1];
|
block = block.split("/")[1];
|
||||||
return Patterns.createJson(Patterns.ITEM_BLOCK, block);
|
return Patterns.createJson(Patterns.ITEM_BLOCK, block);
|
||||||
|
@ -136,7 +137,7 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
String pattern = Patterns.createJson(Patterns.BLOCK_CROSS, resourceLocation.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_CROSS, resourceLocation.getPath());
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,9 +5,11 @@ 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.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
|
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;
|
||||||
|
@ -344,7 +346,7 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
Map<String, String> textures = createTexturesMap();
|
Map<String, String> textures = createTexturesMap();
|
||||||
if (block.contains("column_top")) {
|
if (block.contains("column_top")) {
|
||||||
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_COLUMN_TOP, textures);
|
return Patterns.createJson(Patterns.BLOCK_PEDESTAL_COLUMN_TOP, textures);
|
||||||
|
@ -369,7 +371,7 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
|
||||||
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
public BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
Map<String, String> textures = createTexturesMap();
|
Map<String, String> textures = createTexturesMap();
|
||||||
PedestalState state = blockState.getValue(STATE);
|
PedestalState state = blockState.getValue(STATE);
|
||||||
String pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_DEFAULT, textures);
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case COLUMN_TOP: {
|
case COLUMN_TOP: {
|
||||||
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_COLUMN_TOP, textures);
|
pattern = Patterns.createJson(Patterns.BLOCK_PEDESTAL_COLUMN_TOP, textures);
|
||||||
|
@ -392,15 +394,16 @@ public class PedestalBlock extends BlockBaseNotFull implements EntityBlock {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
PedestalState state = blockState.getValue(STATE);
|
PedestalState state = blockState.getValue(STATE);
|
||||||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||||
"block/" + resourceLocation.getPath() + "_" + state);
|
"block/" + resourceLocation.getPath() + "_" + state);
|
||||||
return super.getModelVariant(modelId, blockState);
|
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||||
|
return ModelsHelper.createBlockSimple(modelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.betterend.blocks.basis;
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -43,7 +44,7 @@ public class SimpleLeavesBlock extends BlockBaseNotFull implements IRenderTypeab
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
String texture = Registry.BLOCK.getKey(this).getPath();
|
String texture = Registry.BLOCK.getKey(this).getPath();
|
||||||
return Patterns.createJson(Patterns.BLOCK_BASE, texture, texture);
|
return Patterns.createJson(Patterns.BLOCK_BASE, texture, texture);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,8 @@ import ru.betterend.client.render.ERenderLayer;
|
||||||
import ru.betterend.interfaces.IRenderTypeable;
|
import ru.betterend.interfaces.IRenderTypeable;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
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;
|
||||||
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
|
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
|
||||||
|
@ -192,7 +194,7 @@ public class StalactiteBlock extends BlockBaseNotFull implements SimpleWaterlogg
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(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_GENERATED, "item/" + blockId.getPath());
|
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/" + blockId.getPath());
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.betterend.blocks.basis;
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
import java.io.Reader;
|
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;
|
||||||
|
@ -68,7 +69,7 @@ public class StoneLanternBlock extends EndLanternBlock implements IColorProvider
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
String texture = Registry.BLOCK.getKey(this).getPath();
|
String texture = Registry.BLOCK.getKey(this).getPath();
|
||||||
if (block.contains("ceil")) {
|
if (block.contains("ceil")) {
|
||||||
return Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_CEIL, texture, texture);
|
return Patterns.createJson(Patterns.BLOCK_STONE_LANTERN_CEIL, texture, texture);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package ru.betterend.blocks.basis;
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
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.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
@ -49,7 +50,7 @@ public class TripleTerrainBlock extends EndTerrainBlock {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String block) {
|
public Optional<String> getModelString(String block) {
|
||||||
String name = Registry.BLOCK.getKey(this).getPath();
|
String name = Registry.BLOCK.getKey(this).getPath();
|
||||||
if (block.endsWith("_middle")) {
|
if (block.endsWith("_middle")) {
|
||||||
return Patterns.createJson(Patterns.BLOCK_BASE, name + "_top", name + "_top");
|
return Patterns.createJson(Patterns.BLOCK_BASE, name + "_top", name + "_top");
|
||||||
|
|
|
@ -1,25 +1,45 @@
|
||||||
package ru.betterend.client.models;
|
package ru.betterend.client.models;
|
||||||
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
|
import net.minecraft.client.resources.model.UnbakedModel;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
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 ModelProvider {
|
public interface BlockModelProvider extends ModelProvider {
|
||||||
String getStatesPattern(Reader data);
|
String getStatesPattern(Reader data);
|
||||||
ResourceLocation statePatternId();
|
ResourceLocation statePatternId();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
default BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
default BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
String pattern = Patterns.createBlockSimple(resourceLocation.getPath());
|
Optional<String> pattern = Patterns.createBlockSimple(resourceLocation.getPath());
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
default MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
|
default MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
|
||||||
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
|
||||||
"block/" + resourceLocation.getPath());
|
"block/" + resourceLocation.getPath());
|
||||||
ModelsHelper.addBlockState(blockState, modelId);
|
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
|
||||||
return ModelsHelper.createBlockSimple(modelId);
|
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) {
|
||||||
|
modelCache.put(modelId, model);
|
||||||
|
} else {
|
||||||
|
BetterEnd.LOGGER.warning("Error loading model: {}", modelId);
|
||||||
|
modelCache.put(modelId, modelCache.get(MISSING_MODEL_LOCATION));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,15 +3,17 @@ package ru.betterend.client.models;
|
||||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
import net.minecraft.client.renderer.block.model.BlockModel;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface ModelProvider {
|
public interface ModelProvider {
|
||||||
String getModelString(String name);
|
Optional<String> getModelString(String name);
|
||||||
|
|
||||||
default BlockModel getModel(ResourceLocation resourceLocation) {
|
default BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
return createItemModel(resourceLocation.getPath());
|
return createItemModel(resourceLocation.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
static BlockModel createItemModel(String name) {
|
static BlockModel createItemModel(String name) {
|
||||||
String pattern = Patterns.createItemGenerated("item/" + name);
|
Optional<String> pattern = Patterns.createItemGenerated("item/" + name);
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -2,6 +2,9 @@ package ru.betterend.client.models;
|
||||||
|
|
||||||
import com.google.common.collect.*;
|
import com.google.common.collect.*;
|
||||||
import com.mojang.math.Transformation;
|
import com.mojang.math.Transformation;
|
||||||
|
import javafx.print.Collation;
|
||||||
|
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.BlockModel;
|
||||||
import net.minecraft.client.renderer.block.model.MultiVariant;
|
import net.minecraft.client.renderer.block.model.MultiVariant;
|
||||||
import net.minecraft.client.renderer.block.model.Variant;
|
import net.minecraft.client.renderer.block.model.Variant;
|
||||||
|
@ -11,28 +14,15 @@ import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Environment(EnvType.CLIENT)
|
||||||
public class ModelsHelper {
|
public class ModelsHelper {
|
||||||
|
|
||||||
private final static BiMap<BlockState, ResourceLocation> STATES_MAP;
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static BlockState getBlockState(ResourceLocation resourceLocation) {
|
|
||||||
BlockState blockState = STATES_MAP.inverse().get(resourceLocation);
|
|
||||||
if (blockState != null) {
|
|
||||||
STATES_MAP.remove(blockState);
|
|
||||||
}
|
|
||||||
return blockState;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addBlockState(BlockState blockState, ResourceLocation resourceLocation) {
|
|
||||||
STATES_MAP.put(blockState, resourceLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static BlockModel createBlockItem(ResourceLocation resourceLocation) {
|
public static BlockModel createBlockItem(ResourceLocation resourceLocation) {
|
||||||
String pattern = Patterns.createJson(Patterns.ITEM_BLOCK, resourceLocation.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_BLOCK, resourceLocation.getPath());
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultiVariant createBlockSimple(ResourceLocation resourceLocation) {
|
public static MultiVariant createBlockSimple(ResourceLocation resourceLocation) {
|
||||||
|
@ -41,7 +31,7 @@ public class ModelsHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MultiVariant createFacingModel(ResourceLocation resourceLocation, Direction facing) {
|
public static MultiVariant createFacingModel(ResourceLocation resourceLocation, Direction facing) {
|
||||||
BlockModelRotation rotation = BlockModelRotation.by(0, (int) facing.toYRot());
|
BlockModelRotation rotation = BlockModelRotation.by(0, (int) facing.getOpposite().toYRot());
|
||||||
Variant variant = new Variant(resourceLocation, rotation.getRotation(), false, 1);
|
Variant variant = new Variant(resourceLocation, rotation.getRotation(), false, 1);
|
||||||
return new MultiVariant(Lists.newArrayList(variant));
|
return new MultiVariant(Lists.newArrayList(variant));
|
||||||
}
|
}
|
||||||
|
@ -50,19 +40,15 @@ public class ModelsHelper {
|
||||||
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
|
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
|
||||||
switch (axis) {
|
switch (axis) {
|
||||||
case X: {
|
case X: {
|
||||||
rotation = BlockModelRotation.by(90, 0);
|
rotation = BlockModelRotation.by(90, 90);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case Z: {
|
case Z: {
|
||||||
rotation = BlockModelRotation.by(90, 90);
|
rotation = BlockModelRotation.by(90, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Variant variant = new Variant(resourceLocation, rotation.getRotation(), false, 1);
|
Variant variant = new Variant(resourceLocation, rotation.getRotation(), false, 1);
|
||||||
return new MultiVariant(Lists.newArrayList(variant));
|
return new MultiVariant(Lists.newArrayList(variant));
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
|
||||||
STATES_MAP = HashBiMap.create();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ 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.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
import com.google.common.collect.Maps;
|
||||||
|
@ -117,14 +118,14 @@ public class Patterns {
|
||||||
public final static ResourceLocation ITEM_HANDHELD = BetterEnd.makeID("patterns/item/pattern_item_handheld.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 final static ResourceLocation ITEM_SPAWN_EGG = BetterEnd.makeID("patterns/item/pattern_item_spawn_egg.json");
|
||||||
|
|
||||||
public static String createItemGenerated(String name) {
|
public static Optional<String> createItemGenerated(String name) {
|
||||||
return createJson(ITEM_GENERATED, name);
|
return createJson(ITEM_GENERATED, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createBlockSimple(String name) {
|
public static Optional<String> createBlockSimple(String name) {
|
||||||
return Patterns.createJson(Patterns.BLOCK_BASE, name, name);
|
return Patterns.createJson(Patterns.BLOCK_BASE, name, name);
|
||||||
}
|
}
|
||||||
public static String createBlockPillar(String name) {
|
public static Optional<String> createBlockPillar(String name) {
|
||||||
return Patterns.createJson(Patterns.BLOCK_PILLAR, name, name);
|
return Patterns.createJson(Patterns.BLOCK_PILLAR, name, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,22 +139,22 @@ public class Patterns {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createJson(ResourceLocation patternId, String parent, String block) {
|
public static Optional<String> createJson(ResourceLocation patternId, String parent, String block) {
|
||||||
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
|
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
|
||||||
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
||||||
return createJson(new InputStreamReader(input, StandardCharsets.UTF_8), parent, block);
|
return Optional.ofNullable(createJson(new InputStreamReader(input, StandardCharsets.UTF_8), parent, block));
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return null;
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createJson(ResourceLocation patternId, String texture) {
|
public static Optional<String> createJson(ResourceLocation patternId, String texture) {
|
||||||
Map<String, String> textures = Maps.newHashMap();
|
Map<String, String> textures = Maps.newHashMap();
|
||||||
textures.put("%texture%", texture);
|
textures.put("%texture%", texture);
|
||||||
return createJson(patternId, textures);
|
return createJson(patternId, textures);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createJson(ResourceLocation patternId, Map<String, String> textures) {
|
public static Optional<String> createJson(ResourceLocation patternId, Map<String, String> textures) {
|
||||||
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
|
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
|
||||||
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
||||||
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
|
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
|
||||||
|
@ -161,9 +162,9 @@ public class Patterns {
|
||||||
for (Entry<String, String> texture : textures.entrySet()) {
|
for (Entry<String, String> texture : textures.entrySet()) {
|
||||||
json = json.replace(texture.getKey(), texture.getValue());
|
json = json.replace(texture.getKey(), texture.getValue());
|
||||||
}
|
}
|
||||||
return json;
|
return Optional.of(json);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return "";
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -8,6 +8,8 @@ import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
import ru.betterend.registry.EndItems;
|
import ru.betterend.registry.EndItems;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EnchantedPetalItem extends ModelProviderItem {
|
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));
|
||||||
|
@ -19,7 +21,7 @@ public class EnchantedPetalItem extends ModelProviderItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/hydralux_petal");
|
return Patterns.createJson(Patterns.ITEM_GENERATED, "item/hydralux_petal");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.world.item.ArmorMaterial;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class EndArmorItem extends ArmorItem implements ModelProvider {
|
public class EndArmorItem extends ArmorItem implements ModelProvider {
|
||||||
|
@ -49,7 +50,7 @@ public class EndArmorItem extends ArmorItem implements ModelProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createItemGenerated(name);
|
return Patterns.createItemGenerated(name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,15 @@ import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
import ru.betterend.registry.EndItems;
|
import ru.betterend.registry.EndItems;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EndBucketItem extends FishBucketItem implements ModelProvider {
|
public class EndBucketItem extends FishBucketItem implements ModelProvider {
|
||||||
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
|
@Override
|
||||||
public String getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_GENERATED, name);
|
return Patterns.createJson(Patterns.ITEM_GENERATED, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,19 +7,21 @@ import net.minecraft.world.item.SpawnEggItem;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EndSpawnEggItem extends SpawnEggItem implements ModelProvider {
|
public class EndSpawnEggItem extends SpawnEggItem implements ModelProvider {
|
||||||
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 getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_SPAWN_EGG, name);
|
return Patterns.createJson(Patterns.ITEM_SPAWN_EGG, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public BlockModel getModel(ResourceLocation resourceLocation) {
|
public BlockModel getModel(ResourceLocation resourceLocation) {
|
||||||
String pattern = Patterns.createJson(Patterns.ITEM_SPAWN_EGG, resourceLocation.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_SPAWN_EGG, resourceLocation.getPath());
|
||||||
return BlockModel.fromString(pattern);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,15 @@ import net.minecraft.world.item.RecordItem;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ModelProviderDiscItem extends RecordItem implements ModelProvider {
|
public class ModelProviderDiscItem extends RecordItem implements ModelProvider {
|
||||||
public ModelProviderDiscItem(int comparatorOutput, SoundEvent sound, Properties settings) {
|
public ModelProviderDiscItem(int comparatorOutput, SoundEvent sound, Properties settings) {
|
||||||
super(comparatorOutput, sound, settings);
|
super(comparatorOutput, sound, settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_GENERATED, name);
|
return Patterns.createJson(Patterns.ITEM_GENERATED, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,15 @@ import net.minecraft.world.item.Item;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class ModelProviderItem extends Item implements ModelProvider {
|
public class ModelProviderItem extends Item implements ModelProvider {
|
||||||
public ModelProviderItem(Properties settings) {
|
public ModelProviderItem(Properties settings) {
|
||||||
super(settings);
|
super(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createItemGenerated(name);
|
return Patterns.createItemGenerated(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EndAxeItem extends AxeItem implements DynamicAttributeTool, ModelProvider {
|
public class EndAxeItem extends AxeItem implements DynamicAttributeTool, ModelProvider {
|
||||||
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 +28,7 @@ public class EndAxeItem extends AxeItem implements DynamicAttributeTool, ModelPr
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -135,7 +136,7 @@ public class EndHammerItem extends DiggerItem implements DynamicAttributeTool, M
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,15 @@ import net.minecraft.world.item.Tier;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EndHoeItem extends HoeItem implements ModelProvider {
|
public class EndHoeItem extends HoeItem implements ModelProvider {
|
||||||
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 getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,6 +15,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EndPickaxeItem extends PickaxeItem implements DynamicAttributeTool, ModelProvider {
|
public class EndPickaxeItem extends PickaxeItem implements DynamicAttributeTool, ModelProvider {
|
||||||
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);
|
||||||
|
@ -38,7 +40,7 @@ public class EndPickaxeItem extends PickaxeItem implements DynamicAttributeTool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,8 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EndShovelItem extends ShovelItem implements DynamicAttributeTool, ModelProvider {
|
public class EndShovelItem extends ShovelItem implements DynamicAttributeTool, ModelProvider {
|
||||||
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);
|
||||||
|
@ -34,7 +36,7 @@ public class EndShovelItem extends ShovelItem implements DynamicAttributeTool, M
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,13 +6,15 @@ import net.minecraft.world.item.Tier;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public class EndSwordItem extends SwordItem implements DynamicAttributeTool, ModelProvider {
|
public class EndSwordItem extends SwordItem implements DynamicAttributeTool, ModelProvider {
|
||||||
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 getModelString(String name) {
|
public Optional<String> getModelString(String name) {
|
||||||
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
return Patterns.createJson(Patterns.ITEM_HANDHELD, name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
import ru.betterend.client.models.ModelProvider;
|
import ru.betterend.client.models.ModelProvider;
|
||||||
import ru.betterend.client.models.ModelsHelper;
|
|
||||||
import ru.betterend.world.generator.GeneratorOptions;
|
import ru.betterend.world.generator.GeneratorOptions;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
@ -47,13 +47,13 @@ public abstract class ModelLoaderMixin {
|
||||||
protected abstract BlockModel loadBlockModel(ResourceLocation resourceLocation);
|
protected abstract BlockModel loadBlockModel(ResourceLocation resourceLocation);
|
||||||
|
|
||||||
@Inject(method = "loadModel", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "loadModel", at = @At("HEAD"), cancellable = true)
|
||||||
private void be_loadModels(ResourceLocation resourceLocation, CallbackInfo info) {
|
private void be_loadModels(ResourceLocation resourceLocation, CallbackInfo info) throws IOException {
|
||||||
if (resourceLocation instanceof ModelResourceLocation) {
|
if (resourceLocation instanceof ModelResourceLocation) {
|
||||||
String modId = resourceLocation.getNamespace();
|
String modId = resourceLocation.getNamespace();
|
||||||
String path = resourceLocation.getPath();
|
String path = resourceLocation.getPath();
|
||||||
ResourceLocation clearLoc = new ResourceLocation(modId, path);
|
ResourceLocation clearLoc = new ResourceLocation(modId, path);
|
||||||
ModelResourceLocation modelLoc = (ModelResourceLocation) resourceLocation;
|
ModelResourceLocation modelId = (ModelResourceLocation) resourceLocation;
|
||||||
if (Objects.equals(modelLoc.getVariant(), "inventory")) {
|
if (Objects.equals(modelId.getVariant(), "inventory")) {
|
||||||
ResourceLocation itemLoc = new ResourceLocation(modId, "item/" + path);
|
ResourceLocation itemLoc = new ResourceLocation(modId, "item/" + path);
|
||||||
ResourceLocation itemModelLoc = new ResourceLocation(modId, "models/" + itemLoc.getPath() + ".json");
|
ResourceLocation itemModelLoc = new ResourceLocation(modId, "models/" + itemLoc.getPath() + ".json");
|
||||||
if (!resourceManager.hasResource(itemModelLoc)) {
|
if (!resourceManager.hasResource(itemModelLoc)) {
|
||||||
|
@ -62,30 +62,31 @@ public abstract class ModelLoaderMixin {
|
||||||
BlockModel model = ((ModelProvider) item).getModel(clearLoc);
|
BlockModel model = ((ModelProvider) item).getModel(clearLoc);
|
||||||
if (model != null) {
|
if (model != null) {
|
||||||
model.name = itemLoc.toString();
|
model.name = itemLoc.toString();
|
||||||
|
cacheAndQueueDependencies(modelId, model);
|
||||||
|
unbakedCache.put(itemLoc, model);
|
||||||
} else {
|
} else {
|
||||||
model = loadBlockModel(itemLoc);
|
BetterEnd.LOGGER.warning("Error loading model: {}", itemLoc);
|
||||||
}
|
}
|
||||||
cacheAndQueueDependencies(modelLoc, model);
|
|
||||||
unbakedCache.put(itemLoc, model);
|
|
||||||
info.cancel();
|
info.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ResourceLocation blockstateId = new ResourceLocation(modId, "blockstates/" + path + ".json");
|
ResourceLocation stateLoc = new ResourceLocation(modId, "blockstates/" + path + ".json");
|
||||||
if (!resourceManager.hasResource(blockstateId)) {
|
if (!resourceManager.hasResource(stateLoc)) {
|
||||||
Block block = Registry.BLOCK.get(clearLoc);
|
Block block = Registry.BLOCK.get(clearLoc);
|
||||||
if (block instanceof BlockModelProvider) {
|
if (block instanceof BlockModelProvider) {
|
||||||
block.getStateDefinition().getPossibleStates().forEach(blockState -> {
|
Optional<BlockState> stateOptional = block.getStateDefinition().getPossibleStates().stream()
|
||||||
System.out.println(blockState);
|
.filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state)))
|
||||||
ModelResourceLocation stateLoc = BlockModelShaper.stateToModelLocation(clearLoc, blockState);
|
.findFirst();
|
||||||
MultiVariant modelVariant = ((BlockModelProvider) block).getModelVariant(stateLoc, blockState);
|
if (stateOptional.isPresent()) {
|
||||||
|
MultiVariant modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, stateOptional.get(), unbakedCache);
|
||||||
if (modelVariant != null) {
|
if (modelVariant != null) {
|
||||||
cacheAndQueueDependencies(stateLoc, modelVariant);
|
cacheAndQueueDependencies(modelId, modelVariant);
|
||||||
} else {
|
} else {
|
||||||
BetterEnd.LOGGER.warning("Error loading variant: {}", stateLoc);
|
BetterEnd.LOGGER.warning("Error loading variant: {}", modelId);
|
||||||
}
|
}
|
||||||
});
|
info.cancel();
|
||||||
info.cancel();
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,39 +94,32 @@ public abstract class ModelLoaderMixin {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "loadBlockModel", at = @At("HEAD"), cancellable = true)
|
@Inject(method = "loadBlockModel", at = @At("HEAD"), cancellable = true)
|
||||||
private void be_loadModelPattern(ResourceLocation modelId, CallbackInfoReturnable<BlockModel> info) {
|
private void be_loadModelPattern(ResourceLocation modelId, CallbackInfoReturnable<BlockModel> info) throws IOException {
|
||||||
ResourceLocation modelLocation = new ResourceLocation(modelId.getNamespace(), "models/" + modelId.getPath() + ".json");
|
ResourceLocation modelLocation = new ResourceLocation(modelId.getNamespace(), "models/" + modelId.getPath() + ".json");
|
||||||
if (!resourceManager.hasResource(modelLocation)) {
|
if (!resourceManager.hasResource(modelLocation)) {
|
||||||
BlockState blockState = ModelsHelper.getBlockState(modelId);
|
String[] data = modelId.getPath().split("/");
|
||||||
if (blockState != null) {
|
if (data.length > 1) {
|
||||||
Block block = blockState.getBlock();
|
ResourceLocation itemId = new ResourceLocation(modelId.getNamespace(), data[1]);
|
||||||
if (block instanceof BlockModelProvider) {
|
Optional<Block> block = Registry.BLOCK.getOptional(itemId);
|
||||||
ResourceLocation blockId = Registry.BLOCK.getKey(block);
|
if (block.isPresent()) {
|
||||||
BlockModel model = ((BlockModelProvider) block).getBlockModel(blockId, blockState);
|
if (block.get() instanceof ModelProvider) {
|
||||||
if (model != null) {
|
ModelProvider modelProvider = (ModelProvider) block.get();
|
||||||
model.name = modelId.toString();
|
Optional<BlockModel> model = be_getModel(data, modelId, modelProvider);
|
||||||
info.setReturnValue(model);
|
if (model.isPresent()) {
|
||||||
} else {
|
info.setReturnValue(model.get());
|
||||||
BetterEnd.LOGGER.warning("Error loading model: {}", modelId);
|
} else {
|
||||||
}
|
throw new FileNotFoundException("Error loading model: " + modelId);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String[] data = modelId.getPath().split("/");
|
|
||||||
if (data.length > 1) {
|
|
||||||
ResourceLocation itemId = new ResourceLocation(modelId.getNamespace(), data[1]);
|
|
||||||
Optional<Block> block = Registry.BLOCK.getOptional(itemId);
|
|
||||||
if (block.isPresent()) {
|
|
||||||
if (block.get() instanceof ModelProvider) {
|
|
||||||
ModelProvider modelProvider = (ModelProvider) block.get();
|
|
||||||
BlockModel model = be_getModel(data, modelId, modelProvider);
|
|
||||||
info.setReturnValue(model);
|
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
Optional<Item> item = Registry.ITEM.getOptional(itemId);
|
} else {
|
||||||
if (item.isPresent() && item.get() instanceof ModelProvider) {
|
Optional<Item> item = Registry.ITEM.getOptional(itemId);
|
||||||
ModelProvider modelProvider = (ModelProvider) item.get();
|
if (item.isPresent() && item.get() instanceof ModelProvider) {
|
||||||
BlockModel model = be_getModel(data, modelId, modelProvider);
|
ModelProvider modelProvider = (ModelProvider) item.get();
|
||||||
info.setReturnValue(model);
|
Optional<BlockModel> model = be_getModel(data, modelId, modelProvider);
|
||||||
|
if (model.isPresent()) {
|
||||||
|
info.setReturnValue(model.get());
|
||||||
|
} else {
|
||||||
|
throw new FileNotFoundException("Error loading model: " + modelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,8 +127,8 @@ public abstract class ModelLoaderMixin {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BlockModel be_getModel(String[] data, ResourceLocation id, ModelProvider modelProvider) {
|
private Optional<BlockModel> be_getModel(String[] data, ResourceLocation id, ModelProvider modelProvider) {
|
||||||
String pattern;
|
Optional<String> pattern;
|
||||||
if (id.getPath().contains("item")) {
|
if (id.getPath().contains("item")) {
|
||||||
pattern = modelProvider.getModelString(id.getPath());
|
pattern = modelProvider.getModelString(id.getPath());
|
||||||
} else {
|
} else {
|
||||||
|
@ -144,10 +138,12 @@ public abstract class ModelLoaderMixin {
|
||||||
pattern = modelProvider.getModelString(data[1]);
|
pattern = modelProvider.getModelString(data[1]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
BlockModel model = BlockModel.fromString(pattern);
|
if (pattern.isPresent()) {
|
||||||
model.name = id.toString();
|
BlockModel model = BlockModel.fromString(pattern.get());
|
||||||
|
model.name = id.toString();
|
||||||
return model;
|
return Optional.of(model);
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE"))
|
@ModifyVariable(method = "loadModel", ordinal = 2, at = @At(value = "INVOKE"))
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue