WIP: patterns
This commit is contained in:
parent
7e1d018140
commit
bde2ac8291
9 changed files with 76 additions and 29 deletions
|
@ -11,13 +11,20 @@ import net.minecraft.block.SlabBlock;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.loot.context.LootContext;
|
import net.minecraft.loot.context.LootContext;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
import ru.betterend.BetterEnd;
|
import ru.betterend.BetterEnd;
|
||||||
import ru.betterend.interfaces.Patterned;
|
import ru.betterend.interfaces.Patterned;
|
||||||
|
|
||||||
public class BlockSlab extends SlabBlock implements Patterned {
|
public class BlockSlab extends SlabBlock implements Patterned {
|
||||||
|
|
||||||
|
private final static Identifier STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_slab.json");
|
||||||
|
private final static Identifier MODEL_PATTERN = BetterEnd.makeID("patterns/block/pattern_slab.json");
|
||||||
|
|
||||||
|
private final Block parent;
|
||||||
|
|
||||||
public BlockSlab(Block source) {
|
public BlockSlab(Block source) {
|
||||||
super(FabricBlockSettings.copyOf(source));
|
super(FabricBlockSettings.copyOf(source));
|
||||||
|
this.parent = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -27,13 +34,17 @@ public class BlockSlab extends SlabBlock implements Patterned {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String blockStatePattern(String name) {
|
public String blockStatePattern(String name) {
|
||||||
Identifier patternId = BetterEnd.makeID("patterns/blockstate/pattern_slab.json");
|
Identifier parentId = Registry.BLOCK.getId(parent);
|
||||||
return Patterned.createJson(patternId, name.replace("_slab", ""));
|
return Patterned.createJson(STATES_PATTERN, parentId.getPath());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String modelPattern(String name) {
|
public String modelPattern(String name) {
|
||||||
Identifier patternId = BetterEnd.makeID("patterns/block/pattern_slab.json");
|
Identifier parentId = Registry.BLOCK.getId(parent);
|
||||||
return Patterned.createJson(patternId, name.replace("_slab", ""));
|
return Patterned.createJson(MODEL_PATTERN, parentId.getPath());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Identifier statePatternId() {
|
||||||
|
return STATES_PATTERN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,4 +5,8 @@ import net.minecraft.util.Identifier;
|
||||||
public interface IdentifiedContext {
|
public interface IdentifiedContext {
|
||||||
public Identifier getContextId();
|
public Identifier getContextId();
|
||||||
public void setContextId(Identifier id);
|
public void setContextId(Identifier id);
|
||||||
|
|
||||||
|
default void removeId() {
|
||||||
|
this.setContextId(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,19 @@ public interface Patterned {
|
||||||
default String blockStatePattern(String name) {
|
default String blockStatePattern(String name) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
default String modelPattern(String name) {
|
default String modelPattern(String name) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default Identifier statePatternId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
default Identifier modelPatternId() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static String createJson(Identifier patternId, String name) {
|
public static String createJson(Identifier patternId, String name) {
|
||||||
ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager();
|
ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager();
|
||||||
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.At.Shift;
|
import org.spongepowered.asm.mixin.injection.At.Shift;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
@ -46,8 +47,7 @@ public class ModelLoaderMixin {
|
||||||
private void loadModel(Identifier id, CallbackInfo info) {
|
private void loadModel(Identifier id, CallbackInfo info) {
|
||||||
IdentifiedContext context = IdentifiedContext.class.cast(variantMapDeserializationContext);
|
IdentifiedContext context = IdentifiedContext.class.cast(variantMapDeserializationContext);
|
||||||
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
|
if (id.getNamespace().equals(BetterEnd.MOD_ID)) {
|
||||||
Identifier blockstateId = new Identifier(id.getNamespace(), "pattern/" + id.getPath());
|
context.setContextId(BetterEnd.makeID("pattern/" + id.getPath()));
|
||||||
context.setContextId(blockstateId);
|
|
||||||
} else {
|
} else {
|
||||||
context.setContextId(null);
|
context.setContextId(null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,9 +33,9 @@ public abstract class ModelVariantMapMixin {
|
||||||
String[] data = id.getPath().split("/");
|
String[] data = id.getPath().split("/");
|
||||||
Identifier blockId = new Identifier(id.getNamespace(), data[1]);
|
Identifier blockId = new Identifier(id.getNamespace(), data[1]);
|
||||||
Block block = Registry.BLOCK.get(blockId);
|
Block block = Registry.BLOCK.get(blockId);
|
||||||
|
idContext.removeId();
|
||||||
if (block instanceof Patterned) {
|
if (block instanceof Patterned) {
|
||||||
String pattern = ((Patterned) block).blockStatePattern(data[1]);
|
String pattern = ((Patterned) block).blockStatePattern(data[1]);
|
||||||
idContext.setContextId(null);
|
|
||||||
info.setReturnValue(deserialize(context, new StringReader(pattern)));
|
info.setReturnValue(deserialize(context, new StringReader(pattern)));
|
||||||
info.cancel();
|
info.cancel();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package ru.betterend.mixin.client;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.Shadow;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
|
import net.minecraft.block.Block;
|
||||||
|
import net.minecraft.resource.NamespaceResourceManager;
|
||||||
|
import net.minecraft.resource.Resource;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.registry.Registry;
|
||||||
|
import ru.betterend.BetterEnd;
|
||||||
|
import ru.betterend.interfaces.Patterned;
|
||||||
|
|
||||||
|
@Mixin(NamespaceResourceManager.class)
|
||||||
|
public abstract class NamespaceResourceManagerMixin {
|
||||||
|
|
||||||
|
@Shadow
|
||||||
|
public abstract Resource getResource(Identifier id);
|
||||||
|
|
||||||
|
@Inject(method = "getAllResources", at = @At("HEAD"), cancellable = true)
|
||||||
|
public void getAllResources(Identifier id, CallbackInfoReturnable<List<Resource>> info) {
|
||||||
|
if (id.getNamespace().contains(BetterEnd.MOD_ID)) {
|
||||||
|
String[] data = id.getPath().split("/");
|
||||||
|
if (data.length > 1) {
|
||||||
|
Identifier blockId = BetterEnd.makeID(data[1].replace(".json", ""));
|
||||||
|
Block block = Registry.BLOCK.get(blockId);
|
||||||
|
if (block instanceof Patterned) {
|
||||||
|
List<Resource> resources = Lists.newArrayList();
|
||||||
|
resources.add(this.getResource(((Patterned) block).statePatternId()));
|
||||||
|
info.setReturnValue(resources);
|
||||||
|
info.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,15 +0,0 @@
|
||||||
{
|
|
||||||
"variants": {
|
|
||||||
"type=bottom": {
|
|
||||||
"model": "betterend:block/flavolite_slab"
|
|
||||||
},
|
|
||||||
"type=double": {
|
|
||||||
"model": "betterend:block/flavolite"
|
|
||||||
},
|
|
||||||
"type=top": {
|
|
||||||
"model": "betterend:block/flavolite_slab",
|
|
||||||
"uvlock": true,
|
|
||||||
"x": 180
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
{
|
|
||||||
"parent": "minecraft:block/cube_all",
|
|
||||||
"textures": {
|
|
||||||
"all": "betterend:block/flavolite"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -11,6 +11,7 @@
|
||||||
"ModelVariantMapMixin",
|
"ModelVariantMapMixin",
|
||||||
"DeserializationContextMixin",
|
"DeserializationContextMixin",
|
||||||
"ClientPlayNetworkHandlerMixin",
|
"ClientPlayNetworkHandlerMixin",
|
||||||
|
"NamespaceResourceManagerMixin",
|
||||||
"MinecraftClientMixin"
|
"MinecraftClientMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue