Trapdoor pattern
This commit is contained in:
parent
7d0363483c
commit
24ec8637e7
4 changed files with 122 additions and 5 deletions
|
@ -1,18 +1,25 @@
|
||||||
package ru.betterend.blocks.basis;
|
package ru.betterend.blocks.basis;
|
||||||
|
|
||||||
|
import java.io.Reader;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockState;
|
import net.minecraft.block.BlockState;
|
||||||
import net.minecraft.block.TrapdoorBlock;
|
import net.minecraft.block.TrapdoorBlock;
|
||||||
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.registry.Registry;
|
||||||
|
|
||||||
import ru.betterend.client.ERenderLayer;
|
import ru.betterend.client.ERenderLayer;
|
||||||
import ru.betterend.client.IRenderTypeable;
|
import ru.betterend.client.IRenderTypeable;
|
||||||
|
import ru.betterend.interfaces.Patterned;
|
||||||
|
|
||||||
public class BlockTrapdoor extends TrapdoorBlock implements IRenderTypeable {
|
public class BlockTrapdoor extends TrapdoorBlock implements IRenderTypeable, Patterned {
|
||||||
public BlockTrapdoor(Block source) {
|
public BlockTrapdoor(Block source) {
|
||||||
super(FabricBlockSettings.copyOf(source).nonOpaque());
|
super(FabricBlockSettings.copyOf(source).nonOpaque());
|
||||||
}
|
}
|
||||||
|
@ -26,4 +33,28 @@ public class BlockTrapdoor extends TrapdoorBlock implements IRenderTypeable {
|
||||||
public ERenderLayer getRenderLayer() {
|
public ERenderLayer getRenderLayer() {
|
||||||
return ERenderLayer.CUTOUT;
|
return ERenderLayer.CUTOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getStatesPattern(Reader data, String block) {
|
||||||
|
Identifier blockId = Registry.BLOCK.getId(this);
|
||||||
|
return Patterned.createJson(data, blockId, block);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getModelPattern(String block) {
|
||||||
|
Identifier blockId = Registry.BLOCK.getId(this);
|
||||||
|
String name = blockId.getPath();
|
||||||
|
return Patterned.createJson(Patterned.TRAPDOOR_MODEL, new HashMap<String, String>() {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
{
|
||||||
|
put("%block%", name);
|
||||||
|
put("%texture%", name.replace("trapdoor", "door_side"));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Identifier statePatternId() {
|
||||||
|
return Patterned.TRAPDOOR_STATES_PATTERN;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ public interface Patterned {
|
||||||
public final static Identifier DOOR_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_door.json");
|
public final static Identifier DOOR_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_door.json");
|
||||||
public final static Identifier SAPLING_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_sapling.json");
|
public final static Identifier SAPLING_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_sapling.json");
|
||||||
public final static Identifier GATE_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_fence_gate.json");
|
public final static Identifier GATE_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_fence_gate.json");
|
||||||
|
public final static Identifier TRAPDOOR_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_trapdoor.json");
|
||||||
|
|
||||||
//Models Block
|
//Models Block
|
||||||
public final static Identifier BASE_BLOCK_MODEL = BetterEnd.makeID("patterns/block/pattern_block.json");
|
public final static Identifier BASE_BLOCK_MODEL = BetterEnd.makeID("patterns/block/pattern_block.json");
|
||||||
|
@ -53,6 +54,7 @@ public interface Patterned {
|
||||||
public final static Identifier GATE_MODEL_WALL_CLOSED = BetterEnd.makeID("patterns/block/pattern_wall_gate_closed.json");
|
public final static Identifier GATE_MODEL_WALL_CLOSED = BetterEnd.makeID("patterns/block/pattern_wall_gate_closed.json");
|
||||||
public final static Identifier GATE_MODEL_OPEN = BetterEnd.makeID("patterns/block/pattern_fence_gate_open.json");
|
public final static Identifier GATE_MODEL_OPEN = BetterEnd.makeID("patterns/block/pattern_fence_gate_open.json");
|
||||||
public final static Identifier GATE_MODEL_WALL_OPEN = BetterEnd.makeID("patterns/block/pattern_wall_gate_open.json");
|
public final static Identifier GATE_MODEL_WALL_OPEN = BetterEnd.makeID("patterns/block/pattern_wall_gate_open.json");
|
||||||
|
public final static Identifier TRAPDOOR_MODEL = BetterEnd.makeID("patterns/block/pattern_trapdoor.json");
|
||||||
|
|
||||||
//Models Item
|
//Models Item
|
||||||
public final static Identifier WALL_ITEM_MODEL = BetterEnd.makeID("patterns/item/pattern_wall.json");
|
public final static Identifier WALL_ITEM_MODEL = BetterEnd.makeID("patterns/item/pattern_wall.json");
|
||||||
|
@ -109,15 +111,15 @@ public interface Patterned {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String createJson(Identifier patternId, Map<String, String> texturesMap, String block) {
|
public static String createJson(Identifier patternId, Map<String, String> textures) {
|
||||||
ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager();
|
ResourceManager resourceManager = MinecraftClient.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))
|
||||||
.lines().collect(Collectors.joining());
|
.lines().collect(Collectors.joining());
|
||||||
for (Entry<String, String> entry : texturesMap.entrySet()) {
|
for (Entry<String, String> texture : textures.entrySet()) {
|
||||||
json = json.replace(entry.getKey(), entry.getValue());
|
json = json.replace(texture.getKey(), texture.getValue());
|
||||||
}
|
}
|
||||||
return json.replace("%block%", block);
|
return json;
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
{
|
||||||
|
"parent": "betterend:block/sided_trapdoor",
|
||||||
|
"textures": {
|
||||||
|
"texture": "betterend:block/%block%",
|
||||||
|
"side": "betterend:block/%texture%"
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,77 @@
|
||||||
|
{
|
||||||
|
"variants": {
|
||||||
|
"facing=east,half=bottom,open=false": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"y": 90
|
||||||
|
},
|
||||||
|
"facing=east,half=bottom,open=true": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 90,
|
||||||
|
"y": 90
|
||||||
|
},
|
||||||
|
"facing=east,half=top,open=false": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 180,
|
||||||
|
"y": 90
|
||||||
|
},
|
||||||
|
"facing=east,half=top,open=true": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 270,
|
||||||
|
"y": 270
|
||||||
|
},
|
||||||
|
"facing=north,half=bottom,open=false": {
|
||||||
|
"model": "betterend:pattern/%block%"
|
||||||
|
},
|
||||||
|
"facing=north,half=bottom,open=true": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 90
|
||||||
|
},
|
||||||
|
"facing=north,half=top,open=false": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 180
|
||||||
|
},
|
||||||
|
"facing=north,half=top,open=true": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 270,
|
||||||
|
"y": 180
|
||||||
|
},
|
||||||
|
"facing=south,half=bottom,open=false": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"y": 180
|
||||||
|
},
|
||||||
|
"facing=south,half=bottom,open=true": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 90,
|
||||||
|
"y": 180
|
||||||
|
},
|
||||||
|
"facing=south,half=top,open=false": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 180,
|
||||||
|
"y": 180
|
||||||
|
},
|
||||||
|
"facing=south,half=top,open=true": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 270,
|
||||||
|
"y": 0
|
||||||
|
},
|
||||||
|
"facing=west,half=bottom,open=false": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"y": 270
|
||||||
|
},
|
||||||
|
"facing=west,half=bottom,open=true": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 90,
|
||||||
|
"y": 270
|
||||||
|
},
|
||||||
|
"facing=west,half=top,open=false": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 180,
|
||||||
|
"y": 270
|
||||||
|
},
|
||||||
|
"facing=west,half=top,open=true": {
|
||||||
|
"model": "betterend:pattern/%block%",
|
||||||
|
"x": 270,
|
||||||
|
"y": 90
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue