Door and Sapling patterns
This commit is contained in:
parent
04f4b5576f
commit
c955d3032e
11 changed files with 249 additions and 14 deletions
|
@ -1,5 +1,6 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -10,10 +11,13 @@ import net.minecraft.block.DoorBlock;
|
|||
import net.minecraft.block.enums.DoubleBlockHalf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
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.IRenderTypeable;
|
||||
import ru.betterend.client.IRenderTypeable;
|
||||
import ru.betterend.interfaces.Patterned;
|
||||
|
||||
public class BlockDoor extends DoorBlock implements IRenderTypeable {
|
||||
public class BlockDoor extends DoorBlock implements IRenderTypeable, Patterned {
|
||||
public BlockDoor(Block block) {
|
||||
super(FabricBlockSettings.copy(block).nonOpaque());
|
||||
}
|
||||
|
@ -30,4 +34,33 @@ public class BlockDoor extends DoorBlock implements IRenderTypeable {
|
|||
public ERenderLayer getRenderLayer() {
|
||||
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);
|
||||
if (block.contains("item")) {
|
||||
block = block.split("/")[1];
|
||||
return Patterned.createJson(Patterned.ITEM_MODEL, block);
|
||||
}
|
||||
if (block.contains("top_hinge")) {
|
||||
return Patterned.createJson(Patterned.DOOR_MODEL_TOP_HINGE, blockId, block);
|
||||
}
|
||||
if (block.contains("bottom_hinge")) {
|
||||
return Patterned.createJson(Patterned.DOOR_MODEL_BOTTOM_HINGE, blockId, block);
|
||||
}
|
||||
if (block.contains("top")) {
|
||||
return Patterned.createJson(Patterned.DOOR_MODEL_TOP, blockId, block);
|
||||
}
|
||||
return Patterned.createJson(Patterned.DOOR_MODEL_BOTTOM, blockId, block);
|
||||
}
|
||||
|
||||
public Identifier statePatternId() {
|
||||
return Patterned.DOOR_STATES_PATTERN;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package ru.betterend.blocks.basis;
|
||||
|
||||
import java.io.Reader;
|
||||
import java.util.Random;
|
||||
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
|
@ -11,8 +12,10 @@ import net.minecraft.block.Material;
|
|||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -21,6 +24,7 @@ import net.minecraft.world.WorldView;
|
|||
import net.minecraft.world.gen.feature.Feature;
|
||||
import ru.betterend.client.ERenderLayer;
|
||||
import ru.betterend.client.IRenderTypeable;
|
||||
import ru.betterend.interfaces.Patterned;
|
||||
import ru.betterend.registry.BlockTagRegistry;
|
||||
import ru.betterend.util.BlocksHelper;
|
||||
|
||||
|
@ -96,4 +100,24 @@ public abstract class BlockFeatureSapling extends BlockBaseNotFull implements Fe
|
|||
public ERenderLayer getRenderLayer() {
|
||||
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) {
|
||||
if (block.contains("item")) {
|
||||
block = block.split("/")[1];
|
||||
return Patterned.createJson(Patterned.ITEM_MODEL, block);
|
||||
}
|
||||
return Patterned.createJson(Patterned.SAPLING_MODEL, block);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier statePatternId() {
|
||||
return Patterned.SAPLING_STATES_PATTERN;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,10 @@ public interface Patterned {
|
|||
public final static Identifier BUTTON_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_button.json");
|
||||
public final static Identifier PILLAR_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_pillar.json");
|
||||
public final static Identifier PLATE_STATES_PATTERN = BetterEnd.makeID("patterns/blockstate/pattern_pressure_plate.json");
|
||||
//Models
|
||||
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");
|
||||
|
||||
//Models Block
|
||||
public final static Identifier BASE_BLOCK_MODEL = BetterEnd.makeID("patterns/block/pattern_block.json");
|
||||
public final static Identifier SLAB_BLOCK_MODEL = BetterEnd.makeID("patterns/block/pattern_slab.json");
|
||||
public final static Identifier STAIRS_MODEL = BetterEnd.makeID("patterns/block/pattern_stairs.json");
|
||||
|
@ -32,13 +35,21 @@ public interface Patterned {
|
|||
public final static Identifier WALL_POST_MODEL = BetterEnd.makeID("patterns/block/pattern_wall_post.json");
|
||||
public final static Identifier WALL_SIDE_MODEL = BetterEnd.makeID("patterns/block/pattern_wall_side.json");
|
||||
public final static Identifier WALL_SIDE_TALL_MODEL = BetterEnd.makeID("patterns/block/pattern_wall_side_tall.json");
|
||||
public final static Identifier WALL_ITEM_MODEL = BetterEnd.makeID("patterns/item/pattern_wall.json");
|
||||
public final static Identifier BUTTON_BLOCK_MODEL = BetterEnd.makeID("patterns/block/pattern_button.json");
|
||||
public final static Identifier BUTTON_PRESSED_MODEL = BetterEnd.makeID("patterns/block/pattern_button_pressed.json");
|
||||
public final static Identifier BUTTON_ITEM_MODEL = BetterEnd.makeID("patterns/item/pattern_button.json");
|
||||
public final static Identifier PILLAR_BLOCK_MODEL = BetterEnd.makeID("patterns/block/pattern_pillar.json");
|
||||
public final static Identifier PLATE_MODEL_UP = BetterEnd.makeID("patterns/block/pattern_pressure_plate_up.json");
|
||||
public final static Identifier PLATE_MODEL_DOWN = BetterEnd.makeID("patterns/block/pattern_pressure_plate_down.json");
|
||||
public final static Identifier DOOR_MODEL_TOP = BetterEnd.makeID("patterns/block/pattern_door_top.json");
|
||||
public final static Identifier DOOR_MODEL_TOP_HINGE = BetterEnd.makeID("patterns/block/pattern_door_top_hinge.json");
|
||||
public final static Identifier DOOR_MODEL_BOTTOM = BetterEnd.makeID("patterns/block/pattern_door_bottom.json");
|
||||
public final static Identifier DOOR_MODEL_BOTTOM_HINGE = BetterEnd.makeID("patterns/block/pattern_door_bottom_hinge.json");
|
||||
public final static Identifier SAPLING_MODEL = BetterEnd.makeID("patterns/block/pattern_sapling.json");
|
||||
|
||||
//Models Item
|
||||
public final static Identifier WALL_ITEM_MODEL = BetterEnd.makeID("patterns/item/pattern_wall.json");
|
||||
public final static Identifier BUTTON_ITEM_MODEL = BetterEnd.makeID("patterns/item/pattern_button.json");
|
||||
public final static Identifier ITEM_MODEL = BetterEnd.makeID("patterns/item/pattern_item.json");
|
||||
|
||||
default String getStatesPattern(Reader data, String name) {
|
||||
return null;
|
||||
|
@ -78,28 +89,26 @@ public interface Patterned {
|
|||
}
|
||||
}
|
||||
|
||||
public static String createJson(Identifier patternId, String texture, String block) {
|
||||
public static String createJson(Identifier patternId, String texture) {
|
||||
ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager();
|
||||
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
||||
return new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
|
||||
.lines().collect(Collectors.joining())
|
||||
.replace("%texture%", texture)
|
||||
.replace("%block%", block);
|
||||
.replace("%texture%", texture);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String createJson(Identifier patternId, String block, Map<String, String> textures) {
|
||||
public static String createJson(Identifier patternId, Map<String, String> texturesMap, String block) {
|
||||
ResourceManager resourceManager = MinecraftClient.getInstance().getResourceManager();
|
||||
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
|
||||
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8))
|
||||
.lines().collect(Collectors.joining())
|
||||
.replace("%block%", block);
|
||||
for (Entry<String, String> texture : textures.entrySet()) {
|
||||
json = json.replace(texture.getKey(), texture.getValue());
|
||||
.lines().collect(Collectors.joining());
|
||||
for (Entry<String, String> entry : texturesMap.entrySet()) {
|
||||
json = json.replace(entry.getKey(), entry.getValue());
|
||||
}
|
||||
return json;
|
||||
return json.replace("%block%", block);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"parent": "betterend:block/sided_door_bottom",
|
||||
"textures": {
|
||||
"facade": "betterend:block/%block%_bottom",
|
||||
"side": "betterend:block/%block%_side"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"parent": "betterend:block/sided_door_bottom_rh",
|
||||
"textures": {
|
||||
"facade": "betterend:block/%block%_bottom",
|
||||
"side": "betterend:block/%block%_side"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"parent": "betterend:block/sided_door_top",
|
||||
"textures": {
|
||||
"facade": "betterend:block/%block%_top",
|
||||
"side": "betterend:block/%block%_side"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
{
|
||||
"parent": "betterend:block/sided_door_top_rh",
|
||||
"textures": {
|
||||
"facade": "betterend:block/%block%_top",
|
||||
"side": "betterend:block/%block%_side"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "minecraft:block/cross",
|
||||
"textures": {
|
||||
"cross": "betterend:block/%texture%"
|
||||
}
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
{
|
||||
"variants": {
|
||||
"facing=east,half=lower,hinge=left,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom"
|
||||
},
|
||||
"facing=east,half=lower,hinge=left,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
|
||||
"y": 90
|
||||
},
|
||||
"facing=east,half=lower,hinge=right,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom_hinge"
|
||||
},
|
||||
"facing=east,half=lower,hinge=right,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom",
|
||||
"y": 270
|
||||
},
|
||||
"facing=east,half=upper,hinge=left,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_top"
|
||||
},
|
||||
"facing=east,half=upper,hinge=left,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_top_hinge",
|
||||
"y": 90
|
||||
},
|
||||
"facing=east,half=upper,hinge=right,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_top_hinge"
|
||||
},
|
||||
"facing=east,half=upper,hinge=right,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_top",
|
||||
"y": 270
|
||||
},
|
||||
"facing=north,half=lower,hinge=left,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom",
|
||||
"y": 270
|
||||
},
|
||||
"facing=north,half=lower,hinge=left,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom_hinge"
|
||||
},
|
||||
"facing=north,half=lower,hinge=right,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
|
||||
"y": 270
|
||||
},
|
||||
"facing=north,half=lower,hinge=right,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom",
|
||||
"y": 180
|
||||
},
|
||||
"facing=north,half=upper,hinge=left,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_top",
|
||||
"y": 270
|
||||
},
|
||||
"facing=north,half=upper,hinge=left,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_top_hinge"
|
||||
},
|
||||
"facing=north,half=upper,hinge=right,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_top_hinge",
|
||||
"y": 270
|
||||
},
|
||||
"facing=north,half=upper,hinge=right,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_top",
|
||||
"y": 180
|
||||
},
|
||||
"facing=south,half=lower,hinge=left,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom",
|
||||
"y": 90
|
||||
},
|
||||
"facing=south,half=lower,hinge=left,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
|
||||
"y": 180
|
||||
},
|
||||
"facing=south,half=lower,hinge=right,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
|
||||
"y": 90
|
||||
},
|
||||
"facing=south,half=lower,hinge=right,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom"
|
||||
},
|
||||
"facing=south,half=upper,hinge=left,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_top",
|
||||
"y": 90
|
||||
},
|
||||
"facing=south,half=upper,hinge=left,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_top_hinge",
|
||||
"y": 180
|
||||
},
|
||||
"facing=south,half=upper,hinge=right,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_top_hinge",
|
||||
"y": 90
|
||||
},
|
||||
"facing=south,half=upper,hinge=right,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_top"
|
||||
},
|
||||
"facing=west,half=lower,hinge=left,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom",
|
||||
"y": 180
|
||||
},
|
||||
"facing=west,half=lower,hinge=left,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
|
||||
"y": 270
|
||||
},
|
||||
"facing=west,half=lower,hinge=right,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom_hinge",
|
||||
"y": 180
|
||||
},
|
||||
"facing=west,half=lower,hinge=right,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_bottom",
|
||||
"y": 90
|
||||
},
|
||||
"facing=west,half=upper,hinge=left,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_top",
|
||||
"y": 180
|
||||
},
|
||||
"facing=west,half=upper,hinge=left,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_top_hinge",
|
||||
"y": 270
|
||||
},
|
||||
"facing=west,half=upper,hinge=right,open=false": {
|
||||
"model": "betterend:pattern/%block%/%block%_top_hinge",
|
||||
"y": 180
|
||||
},
|
||||
"facing=west,half=upper,hinge=right,open=true": {
|
||||
"model": "betterend:pattern/%block%/%block%_top",
|
||||
"y": 90
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"variants": {
|
||||
"": { "model": "betterend:pattern/%block%" }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"parent": "item/generated",
|
||||
"textures": {
|
||||
"layer0": "betterend:item/%texture%"
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue