Change models loading (still WIP)
This commit is contained in:
parent
2d23ca72ea
commit
744fe40a00
64 changed files with 437 additions and 269 deletions
|
@ -2,6 +2,9 @@ package ru.betterend.client.models;
|
|||
|
||||
import com.google.common.collect.*;
|
||||
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.MultiVariant;
|
||||
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 org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
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) {
|
||||
String pattern = Patterns.createJson(Patterns.ITEM_BLOCK, resourceLocation.getPath());
|
||||
return BlockModel.fromString(pattern);
|
||||
Optional<String> pattern = Patterns.createJson(Patterns.ITEM_BLOCK, resourceLocation.getPath());
|
||||
return pattern.map(BlockModel::fromString).orElse(null);
|
||||
}
|
||||
|
||||
public static MultiVariant createBlockSimple(ResourceLocation resourceLocation) {
|
||||
|
@ -41,7 +31,7 @@ public class ModelsHelper {
|
|||
}
|
||||
|
||||
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);
|
||||
return new MultiVariant(Lists.newArrayList(variant));
|
||||
}
|
||||
|
@ -50,19 +40,15 @@ public class ModelsHelper {
|
|||
BlockModelRotation rotation = BlockModelRotation.X0_Y0;
|
||||
switch (axis) {
|
||||
case X: {
|
||||
rotation = BlockModelRotation.by(90, 0);
|
||||
rotation = BlockModelRotation.by(90, 90);
|
||||
break;
|
||||
}
|
||||
case Z: {
|
||||
rotation = BlockModelRotation.by(90, 90);
|
||||
rotation = BlockModelRotation.by(90, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Variant variant = new Variant(resourceLocation, rotation.getRotation(), false, 1);
|
||||
return new MultiVariant(Lists.newArrayList(variant));
|
||||
}
|
||||
|
||||
static {
|
||||
STATES_MAP = HashBiMap.create();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue