Change models loading (WIP)
This commit is contained in:
parent
2ece809541
commit
d9c5f8e89c
4 changed files with 98 additions and 22 deletions
|
@ -97,35 +97,35 @@ public class EndDoorBlock extends DoorBlock implements IRenderTypeable, BlockMod
|
||||||
switch (facing) {
|
switch (facing) {
|
||||||
case EAST: {
|
case EAST: {
|
||||||
if (hinge && open) {
|
if (hinge && open) {
|
||||||
rotation = BlockModelRotation.by(0, 90);
|
rotation = BlockModelRotation.X0_Y90;
|
||||||
} else if (open) {
|
} else if (open) {
|
||||||
rotation = BlockModelRotation.by(0, 270);
|
rotation = BlockModelRotation.X0_Y270;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case SOUTH: {
|
case SOUTH: {
|
||||||
if (!hinge && !open || hinge && !open) {
|
if (!hinge && !open || hinge && !open) {
|
||||||
rotation = BlockModelRotation.by(0, 90);
|
rotation = BlockModelRotation.X0_Y90;
|
||||||
} else if (hinge) {
|
} else if (hinge) {
|
||||||
rotation = BlockModelRotation.by(0, 180);
|
rotation = BlockModelRotation.X0_Y180;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case WEST: {
|
case WEST: {
|
||||||
if (!hinge && !open || hinge && !open) {
|
if (!hinge && !open || hinge && !open) {
|
||||||
rotation = BlockModelRotation.by(0, 180);
|
rotation = BlockModelRotation.X0_Y180;
|
||||||
} else if (hinge) {
|
} else if (hinge) {
|
||||||
rotation = BlockModelRotation.by(0, 270);
|
rotation = BlockModelRotation.X0_Y270;
|
||||||
} else {
|
} else {
|
||||||
rotation = BlockModelRotation.by(0, 90);
|
rotation = BlockModelRotation.X0_Y90;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case NORTH: {
|
case NORTH: {
|
||||||
if (!hinge && !open || hinge && !open) {
|
if (!hinge && !open || hinge && !open) {
|
||||||
rotation = BlockModelRotation.by(0, 270);
|
rotation = BlockModelRotation.X0_Y270;
|
||||||
} else if (!hinge) {
|
} else if (!hinge) {
|
||||||
rotation = BlockModelRotation.by(0, 180);
|
rotation = BlockModelRotation.X0_Y180;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,9 +25,12 @@ import net.minecraft.world.level.block.state.BlockState;
|
||||||
import net.minecraft.world.level.block.state.StateDefinition;
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
import net.minecraft.world.level.storage.loot.LootContext;
|
import net.minecraft.world.level.storage.loot.LootContext;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.client.models.BlockModelProvider;
|
import ru.betterend.client.models.BlockModelProvider;
|
||||||
import ru.betterend.client.models.Patterns;
|
import ru.betterend.client.models.Patterns;
|
||||||
|
|
||||||
|
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
|
||||||
|
|
||||||
public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
||||||
private final Block parent;
|
private final Block parent;
|
||||||
|
|
||||||
|
@ -63,11 +66,12 @@ public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
public @Nullable UnbakedModel getBlockModel(ResourceLocation blockId, BlockState blockState) {
|
||||||
ResourceLocation postId = new ResourceLocation(blockId.getNamespace(),
|
ResourceLocation thisId = Registry.BLOCK.getKey(this);
|
||||||
"block/" + blockId.getPath() + "_post");
|
|
||||||
ResourceLocation sideId = new ResourceLocation(blockId.getNamespace(),
|
|
||||||
"block/" + blockId.getPath() + "_side");
|
|
||||||
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
|
||||||
|
ResourceLocation postId = new ResourceLocation(thisId.getNamespace(),
|
||||||
|
"block/" + thisId.getPath() + "_post");
|
||||||
|
ResourceLocation sideId = new ResourceLocation(thisId.getNamespace(),
|
||||||
|
"block/" + thisId.getPath() + "_side");
|
||||||
if (blockId.equals(postId)) {
|
if (blockId.equals(postId)) {
|
||||||
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath());
|
Optional<String> pattern = Patterns.createJson(Patterns.BLOCK_FENCE_POST, parentId.getPath(), blockId.getPath());
|
||||||
return pattern.map(BlockModel::fromString).orElse(null);
|
return pattern.map(BlockModel::fromString).orElse(null);
|
||||||
|
@ -85,10 +89,9 @@ public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
||||||
"block/" + blockId.getPath() + "_post");
|
"block/" + blockId.getPath() + "_post");
|
||||||
ResourceLocation sideId = new ResourceLocation(blockId.getNamespace(),
|
ResourceLocation sideId = new ResourceLocation(blockId.getNamespace(),
|
||||||
"block/" + blockId.getPath() + "_side");
|
"block/" + blockId.getPath() + "_side");
|
||||||
registerBlockModel(blockId, postId, blockState, modelCache);
|
registerBlockModel(postId, postId, blockState, modelCache);
|
||||||
registerBlockModel(blockId, sideId, blockState, modelCache);
|
registerBlockModel(sideId, sideId, blockState, modelCache);
|
||||||
|
|
||||||
StateDefinition<Block, BlockState> blockStateDefinition = getStateDefinition();
|
|
||||||
MultiVariant postVariant = new MultiVariant(Lists.newArrayList(
|
MultiVariant postVariant = new MultiVariant(Lists.newArrayList(
|
||||||
new Variant(postId, Transformation.identity(), false, 1)));
|
new Variant(postId, Transformation.identity(), false, 1)));
|
||||||
MultiVariant sideNorth = new MultiVariant(Lists.newArrayList(
|
MultiVariant sideNorth = new MultiVariant(Lists.newArrayList(
|
||||||
|
@ -99,6 +102,7 @@ public class EndFenceBlock extends FenceBlock implements BlockModelProvider {
|
||||||
new Variant(sideId, BlockModelRotation.X0_Y180.getRotation(), true, 1)));
|
new Variant(sideId, BlockModelRotation.X0_Y180.getRotation(), true, 1)));
|
||||||
MultiVariant sideWest = new MultiVariant(Lists.newArrayList(
|
MultiVariant sideWest = new MultiVariant(Lists.newArrayList(
|
||||||
new Variant(sideId, BlockModelRotation.X0_Y270.getRotation(), true, 1)));
|
new Variant(sideId, BlockModelRotation.X0_Y270.getRotation(), true, 1)));
|
||||||
|
StateDefinition<Block, BlockState> blockStateDefinition = getStateDefinition();
|
||||||
return new MultiPart(blockStateDefinition, Lists.newArrayList(
|
return new MultiPart(blockStateDefinition, Lists.newArrayList(
|
||||||
new Selector(Condition.TRUE, postVariant),
|
new Selector(Condition.TRUE, postVariant),
|
||||||
new Selector(stateDefinition -> state -> state.getValue(NORTH), sideNorth),
|
new Selector(stateDefinition -> state -> state.getValue(NORTH), sideNorth),
|
||||||
|
|
|
@ -2,22 +2,22 @@ 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.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
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;
|
||||||
|
import net.minecraft.client.renderer.block.model.multipart.Condition;
|
||||||
|
import net.minecraft.client.renderer.block.model.multipart.MultiPart;
|
||||||
|
import net.minecraft.client.renderer.block.model.multipart.Selector;
|
||||||
import net.minecraft.client.resources.model.BlockModelRotation;
|
import net.minecraft.client.resources.model.BlockModelRotation;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.Registry;
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import net.minecraft.world.level.block.state.StateDefinition;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
|
@ -58,4 +58,68 @@ public class ModelsHelper {
|
||||||
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class MultiPartBuilder {
|
||||||
|
|
||||||
|
private final List<ModelPart> modelParts = Lists.newArrayList();
|
||||||
|
|
||||||
|
private StateDefinition<Block, BlockState> stateDefinition;
|
||||||
|
private ModelPart activePart;
|
||||||
|
|
||||||
|
private MultiPartBuilder() {}
|
||||||
|
|
||||||
|
public MultiPartBuilder create(StateDefinition<Block, BlockState> stateDefinition) {
|
||||||
|
this.stateDefinition = stateDefinition;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiPartBuilder createPart(ResourceLocation modelId) {
|
||||||
|
activePart = new ModelPart(modelId);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiPartBuilder setCondition(Condition condition) {
|
||||||
|
activePart.condition = condition;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiPartBuilder setTransformation(Transformation transform) {
|
||||||
|
activePart.transform = transform;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiPartBuilder setUVLock(boolean value) {
|
||||||
|
activePart.uvLock = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiPartBuilder savePart() {
|
||||||
|
if (activePart != null) {
|
||||||
|
modelParts.add(activePart);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MultiPart build() {
|
||||||
|
List<Selector> selectors = Lists.newArrayList();
|
||||||
|
modelParts.forEach(modelPart -> {
|
||||||
|
MultiVariant variant = new MultiVariant(Lists.newArrayList(
|
||||||
|
new Variant(modelPart.modelId, modelPart.transform, modelPart.uvLock, 1)));
|
||||||
|
selectors.add(new Selector(modelPart.condition, variant));
|
||||||
|
});
|
||||||
|
modelParts.clear();
|
||||||
|
return new MultiPart(stateDefinition, selectors);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class ModelPart {
|
||||||
|
private final ResourceLocation modelId;
|
||||||
|
private Transformation transform = Transformation.identity();
|
||||||
|
private Condition condition = Condition.TRUE;
|
||||||
|
private boolean uvLock = false;
|
||||||
|
|
||||||
|
private ModelPart(ResourceLocation modelId) {
|
||||||
|
this.modelId = modelId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package ru.betterend.mixin.client;
|
||||||
import net.minecraft.client.renderer.block.BlockModelShaper;
|
import net.minecraft.client.renderer.block.BlockModelShaper;
|
||||||
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.multipart.MultiPart;
|
||||||
import net.minecraft.client.resources.model.ModelBakery;
|
import net.minecraft.client.resources.model.ModelBakery;
|
||||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
import net.minecraft.client.resources.model.UnbakedModel;
|
||||||
|
@ -81,7 +82,14 @@ public abstract class ModelLoaderMixin {
|
||||||
if (stateOptional.isPresent()) {
|
if (stateOptional.isPresent()) {
|
||||||
UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, stateOptional.get(), unbakedCache);
|
UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, stateOptional.get(), unbakedCache);
|
||||||
if (modelVariant != null) {
|
if (modelVariant != null) {
|
||||||
cacheAndQueueDependencies(modelId, modelVariant);
|
if (modelVariant instanceof MultiPart) {
|
||||||
|
block.getStateDefinition().getPossibleStates().forEach(state -> {
|
||||||
|
ResourceLocation stateId = BlockModelShaper.stateToModelLocation(clearLoc, state);
|
||||||
|
cacheAndQueueDependencies(stateId, modelVariant);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
cacheAndQueueDependencies(modelId, modelVariant);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
BetterEnd.LOGGER.warning("Error loading variant: {}", modelId);
|
BetterEnd.LOGGER.warning("Error loading variant: {}", modelId);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue