Add test slab multiparts

This commit is contained in:
Shadowfacts 2018-12-24 18:25:40 -05:00
parent 3cce66f53e
commit 04c21b644c
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
10 changed files with 158 additions and 2 deletions

View File

@ -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);
}
}

View File

@ -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<BlockHalf> 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<Multipart, MultipartState> 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;
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "multipart_test:multipart/slab/lower",
"textures": {
"texture": "block/gold_block"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "multipart_test:multipart/slab/upper",
"textures": {
"texture": "block/gold_block"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "multipart_test:multipart/slab/lower",
"textures": {
"texture": "block/iron_block"
}
}

View File

@ -0,0 +1,6 @@
{
"parent": "multipart_test:multipart/slab/upper",
"textures": {
"texture": "block/iron_block"
}
}

View File

@ -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" }
}
}
]
}

View File

@ -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" }
}
}
]
}

View File

@ -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" }
}
}

View File

@ -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" }
}
}