diff --git a/src/test/java/net/shadowfacts/simplemultipart/test/MultipartTestMod.java b/src/test/java/net/shadowfacts/simplemultipart/test/MultipartTestMod.java index c5ec6d6..f49c8e8 100644 --- a/src/test/java/net/shadowfacts/simplemultipart/test/MultipartTestMod.java +++ b/src/test/java/net/shadowfacts/simplemultipart/test/MultipartTestMod.java @@ -1,10 +1,12 @@ package net.shadowfacts.simplemultipart.test; import net.fabricmc.api.ModInitializer; +import net.minecraft.item.Item; import net.minecraft.util.Identifier; import net.minecraft.util.registry.Registry; import net.shadowfacts.simplemultipart.SimpleMultipart; import net.shadowfacts.simplemultipart.item.ItemMultipart; +import net.shadowfacts.simplemultipart.multipart.Multipart; /** * @author shadowfacts @@ -14,12 +16,24 @@ public class MultipartTestMod implements ModInitializer { public static final String MODID = "multipart_test"; public static final TestMultipart testPart = new TestMultipart(); + public static final SlabMultipart ironSlab = new SlabMultipart(); + public static final SlabMultipart goldSlab = new SlabMultipart(); + public static final ItemMultipart testItem = new ItemMultipart(testPart); + public static final ItemMultipart ironSlabItem = new ItemMultipart(ironSlab); + public static final ItemMultipart goldSlabItem = new ItemMultipart(goldSlab); @Override public void onInitialize() { - Registry.register(SimpleMultipart.MULTIPART, new Identifier(MODID, "test_part"), testPart); - Registry.register(Registry.ITEM, new Identifier(MODID, "test_part"), testItem); + registerPartAndItem("test_part", testPart, testItem); + registerPartAndItem("iron_slab", ironSlab, ironSlabItem); + registerPartAndItem("gold_slab", goldSlab, goldSlabItem); + } + + private void registerPartAndItem(String name, Multipart part, Item item) { + Identifier id = new Identifier(MODID, name); + Registry.register(SimpleMultipart.MULTIPART, id, part); + Registry.register(Registry.ITEM, id, item); } } diff --git a/src/test/java/net/shadowfacts/simplemultipart/test/SlabMultipart.java b/src/test/java/net/shadowfacts/simplemultipart/test/SlabMultipart.java new file mode 100644 index 0000000..0b27108 --- /dev/null +++ b/src/test/java/net/shadowfacts/simplemultipart/test/SlabMultipart.java @@ -0,0 +1,70 @@ +package net.shadowfacts.simplemultipart.test; + +import net.minecraft.block.enums.BlockHalf; +import net.minecraft.state.StateFactory; +import net.minecraft.state.property.EnumProperty; +import net.minecraft.util.math.Direction; +import net.minecraft.util.shape.VoxelShape; +import net.minecraft.util.shape.VoxelShapes; +import net.shadowfacts.simplemultipart.container.MultipartContainerBlockEntity; +import net.shadowfacts.simplemultipart.multipart.Multipart; +import net.shadowfacts.simplemultipart.multipart.MultipartState; +import net.shadowfacts.simplemultipart.util.MultipartPlacementContext; + +/** + * @author shadowfacts + */ +public class SlabMultipart extends Multipart { + + public static final EnumProperty HALF = EnumProperty.create("half", BlockHalf.class); + + private static final VoxelShape LOWER_BOX = VoxelShapes.cube(0, 0, 0, 1, 0.5f, 1); + private static final VoxelShape UPPER_BOX = VoxelShapes.cube(0, 0.5f, 0, 1, 1, 1); + + public SlabMultipart() { + setDefaultState(getDefaultState().with(HALF, BlockHalf.LOWER)); + } + + @Override + protected void appendProperties(StateFactory.Builder builder) { + super.appendProperties(builder); + builder.with(HALF); + } + + @Override + public MultipartState getPlacementState(MultipartPlacementContext context) { + Direction hitSide = context.getFacing(); + BlockHalf half; + + if (hitSide == Direction.DOWN) { + half = context.getHitY() >= 0.5f ? BlockHalf.LOWER : BlockHalf.UPPER; + } else if (hitSide == Direction.UP) { + half = 0.5f <= context.getHitY() && context.getHitY() < 1 ? BlockHalf.UPPER : BlockHalf.LOWER; + } else { + half = context.getHitY() >= 0.5f ? BlockHalf.UPPER : BlockHalf.LOWER; + } + +// if (hitSide == Direction.DOWN || (0.5f < context.getHitY() && context.getHitY() < 1)) { +// half = BlockHalf.UPPER; +// } else { +// half = BlockHalf.LOWER; +// } + +// switch (hitSide) { +// case UP: +// half = BlockHalf.LOWER; +// break; +// case DOWN: +// half = BlockHalf.UPPER; +// break; +// default: +// half = context.getHitY() > 0.5f ? BlockHalf.UPPER : BlockHalf.LOWER; +// } + return getDefaultState().with(HALF, half); + } + + @Override + public VoxelShape getBoundingShape(MultipartState state, MultipartContainerBlockEntity container) { + return state.get(HALF) == BlockHalf.UPPER ? UPPER_BOX : LOWER_BOX; + } +} diff --git a/src/test/resources/assets/multipart_test/models/multipart/slab/gold/lower.json b/src/test/resources/assets/multipart_test/models/multipart/slab/gold/lower.json new file mode 100644 index 0000000..96af681 --- /dev/null +++ b/src/test/resources/assets/multipart_test/models/multipart/slab/gold/lower.json @@ -0,0 +1,6 @@ +{ + "parent": "multipart_test:multipart/slab/lower", + "textures": { + "texture": "block/gold_block" + } +} \ No newline at end of file diff --git a/src/test/resources/assets/multipart_test/models/multipart/slab/gold/upper.json b/src/test/resources/assets/multipart_test/models/multipart/slab/gold/upper.json new file mode 100644 index 0000000..01dc25b --- /dev/null +++ b/src/test/resources/assets/multipart_test/models/multipart/slab/gold/upper.json @@ -0,0 +1,6 @@ +{ + "parent": "multipart_test:multipart/slab/upper", + "textures": { + "texture": "block/gold_block" + } +} \ No newline at end of file diff --git a/src/test/resources/assets/multipart_test/models/multipart/slab/iron/lower.json b/src/test/resources/assets/multipart_test/models/multipart/slab/iron/lower.json new file mode 100644 index 0000000..2efb1f6 --- /dev/null +++ b/src/test/resources/assets/multipart_test/models/multipart/slab/iron/lower.json @@ -0,0 +1,6 @@ +{ + "parent": "multipart_test:multipart/slab/lower", + "textures": { + "texture": "block/iron_block" + } +} \ No newline at end of file diff --git a/src/test/resources/assets/multipart_test/models/multipart/slab/iron/upper.json b/src/test/resources/assets/multipart_test/models/multipart/slab/iron/upper.json new file mode 100644 index 0000000..f6b25b5 --- /dev/null +++ b/src/test/resources/assets/multipart_test/models/multipart/slab/iron/upper.json @@ -0,0 +1,6 @@ +{ + "parent": "multipart_test:multipart/slab/upper", + "textures": { + "texture": "block/iron_block" + } +} \ No newline at end of file diff --git a/src/test/resources/assets/multipart_test/models/multipart/slab/lower.json b/src/test/resources/assets/multipart_test/models/multipart/slab/lower.json new file mode 100644 index 0000000..92f55e8 --- /dev/null +++ b/src/test/resources/assets/multipart_test/models/multipart/slab/lower.json @@ -0,0 +1,17 @@ +{ + "parent": "simplemultipart:multipart/multipart", + "elements": [ + { + "from": [0, 0, 0], + "to": [16, 8, 16], + "faces": { + "down": { "texture": "#texture", "cullface": "down" }, + "up": { "texture": "#texture" }, + "north": { "texture": "#texture", "cullface": "north" }, + "south": { "texture": "#texture", "cullface": "south" }, + "west": { "texture": "#texture", "cullface": "west" }, + "east": { "texture": "#texture", "cullface": "east" } + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/assets/multipart_test/models/multipart/slab/upper.json b/src/test/resources/assets/multipart_test/models/multipart/slab/upper.json new file mode 100644 index 0000000..c344b9e --- /dev/null +++ b/src/test/resources/assets/multipart_test/models/multipart/slab/upper.json @@ -0,0 +1,17 @@ +{ + "parent": "simplemultipart:multipart/multipart", + "elements": [ + { + "from": [0, 8, 0], + "to": [16, 16, 16], + "faces": { + "down": { "texture": "#texture" }, + "up": { "texture": "#texture", "cullface": "up" }, + "north": { "texture": "#texture", "cullface": "north" }, + "south": { "texture": "#texture", "cullface": "south" }, + "west": { "texture": "#texture", "cullface": "west" }, + "east": { "texture": "#texture", "cullface": "east" } + } + } + ] +} \ No newline at end of file diff --git a/src/test/resources/assets/multipart_test/multipartstates/gold_slab.json b/src/test/resources/assets/multipart_test/multipartstates/gold_slab.json new file mode 100644 index 0000000..212e247 --- /dev/null +++ b/src/test/resources/assets/multipart_test/multipartstates/gold_slab.json @@ -0,0 +1,7 @@ +{ + "variants": { + "half=upper": { "model": "multipart_test:multipart/slab/gold/upper" }, + "half=lower": { "model": "multipart_test:multipart/slab/gold/lower" }, + "inventory": { "model": "multipart_test:multipart/slab/gold/lower" } + } +} \ No newline at end of file diff --git a/src/test/resources/assets/multipart_test/multipartstates/iron_slab.json b/src/test/resources/assets/multipart_test/multipartstates/iron_slab.json new file mode 100644 index 0000000..d1285b6 --- /dev/null +++ b/src/test/resources/assets/multipart_test/multipartstates/iron_slab.json @@ -0,0 +1,7 @@ +{ + "variants": { + "half=upper": { "model": "multipart_test:multipart/slab/iron/upper" }, + "half=lower": { "model": "multipart_test:multipart/slab/iron/lower" }, + "inventory": { "model": "multipart_test:multipart/slab/iron/lower" } + } +} \ No newline at end of file