Change models loading (WIP)

This commit is contained in:
Aleksey 2021-05-15 22:22:33 +03:00
parent de8baa4b83
commit 2910df3078
8 changed files with 129 additions and 41 deletions

View file

@ -4,8 +4,13 @@ import java.io.Reader;
import java.util.Collections;
import java.util.List;
import com.mojang.math.Transformation;
import com.mojang.math.Vector3f;
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.core.Direction;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
@ -16,7 +21,7 @@ import net.minecraft.world.level.storage.loot.LootContext;
import ru.betterend.patterns.BlockModelProvider;
import ru.betterend.patterns.Patterns;
public abstract class EndPillarBlock extends RotatedPillarBlock implements BlockModelProvider {
public class EndPillarBlock extends RotatedPillarBlock implements BlockModelProvider {
public EndPillarBlock(Properties settings) {
super(settings);
}
@ -43,12 +48,43 @@ public abstract class EndPillarBlock extends RotatedPillarBlock implements Block
@Override
public String getModelString(String block) {
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createJson(Patterns.BLOCK_PILLAR, texture, texture);
return createBlockPattern();
}
@Override
public ResourceLocation statePatternId() {
return Patterns.STATE_PILLAR;
}
@Override
public BlockModel getBlockModel(BlockState blockState) {
ResourceLocation blockId = Registry.BLOCK.getKey(this);
BlockModel model = BlockModel.fromString(createBlockPattern());
ResourceLocation modelLoc = new ResourceLocation(blockId.getNamespace(), "blocks/" + blockId.getPath());
model.name = modelLoc.toString();
return model;
}
@Override
public MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState) {
Direction.Axis axis = blockState.getValue(AXIS);
Transformation transform = Transformation.identity();
switch (axis) {
case X: {
transform = new Transformation(null, Vector3f.ZP.rotationDegrees(90), null, null);
break;
}
case Z: {
transform = new Transformation(null, Vector3f.XP.rotationDegrees(90), null, null);
break;
}
}
Variant variant = new Variant(resourceLocation, transform, false, 1);
return new MultiVariant(Collections.singletonList(variant));
}
private String createBlockPattern() {
String texture = Registry.BLOCK.getKey(this).getPath();
return Patterns.createBlockPillar(texture);
}
}