Skip to content

Commit

Permalink
Interior door
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Nov 16, 2023
1 parent dcd8bef commit 5dcef9b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/main/java/dev/enjarai/minitardis/block/InteriorDoorBlock.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
package dev.enjarai.minitardis.block;

import dev.enjarai.minitardis.item.PolymerModels;
import eu.pb4.polymer.core.api.block.PolymerBlock;
import eu.pb4.polymer.virtualentity.api.BlockWithElementHolder;
import eu.pb4.polymer.virtualentity.api.ElementHolder;
import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement;
import net.minecraft.block.*;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.decoration.Brightness;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
Expand All @@ -15,13 +21,15 @@
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.RotationAxis;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("deprecation")
public class InteriorDoorBlock extends FacingBlock implements PolymerBlock, TardisAware {
public class InteriorDoorBlock extends FacingBlock implements PolymerBlock, TardisAware, BlockWithElementHolder {
public static final EnumProperty<DoubleBlockHalf> HALF = Properties.DOUBLE_BLOCK_HALF;

protected InteriorDoorBlock(Settings settings) {
Expand Down Expand Up @@ -78,11 +86,22 @@ protected void appendProperties(StateManager.Builder<Block, BlockState> builder)

@Override
public Block getPolymerBlock(BlockState state) {
return Blocks.PISTON;
return Blocks.BARRIER;
}

@Override
public BlockState getPolymerBlockState(BlockState state) {
return Blocks.PISTON.getDefaultState().with(FACING, state.get(FACING));
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
if (initialBlockState.get(HALF) == DoubleBlockHalf.LOWER) {
var exteriorElement = new ItemDisplayElement();
exteriorElement.setItem(PolymerModels.getStack(PolymerModels.INTERIOR_DOOR));
exteriorElement.setOffset(new Vec3d(0, 1, 0));
exteriorElement.setBrightness(Brightness.FULL);
exteriorElement.setRightRotation(RotationAxis.NEGATIVE_Y.rotationDegrees(initialBlockState.get(FACING).asRotation()));

return new ElementHolder() {{
addElement(exteriorElement);
}};
}
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

public class PolymerModels {
public static final PolymerModelData TARDIS = get("item/tardis");
public static final PolymerModelData INTERIOR_DOOR = get("item/interior_door");

private static PolymerModelData get(String modelPath) {
return PolymerResourcePackUtils.requestModel(Items.LAPIS_LAZULI, MiniTardis.id(modelPath));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
{
"credit": "Made with Blockbench",
"texture_size": [128, 128],
"textures": {
"0": "mini_tardis:item/interior_door",
"particle": "mini_tardis:item/interior_door"
},
"elements": [
{
"from": [0, -16, 0],
"to": [16, 16, 16],
"faces": {
"north": {"uv": [0, 0, 2, 4], "texture": "#0"},
"east": {"uv": [2, 0, 4, 4], "texture": "#0"},
"south": {"uv": [2, 0, 4, 4], "texture": "#0"},
"west": {"uv": [2, 0, 4, 4], "texture": "#0"}
}
},
{
"from": [15, -15, -1],
"to": [17, 16, 1],
"faces": {
"north": {"uv": [4.25, 0, 4.5, 3.875], "texture": "#0"},
"east": {"uv": [4, 0, 4.25, 3.875], "texture": "#0"},
"south": {"uv": [4.75, 0, 5, 3.875], "texture": "#0"},
"west": {"uv": [4.5, 0, 4.75, 3.875], "texture": "#0"}
}
},
{
"from": [-1, -15, -1],
"to": [1, 16, 1],
"faces": {
"north": {"uv": [4.25, 0, 4.5, 3.875], "texture": "#0"},
"east": {"uv": [4, 0, 4.25, 3.875], "texture": "#0"},
"south": {"uv": [4.75, 0, 5, 3.875], "texture": "#0"},
"west": {"uv": [4.5, 0, 4.75, 3.875], "texture": "#0"}
}
},
{
"from": [-1, -15, 15],
"to": [1, 16, 17],
"faces": {
"north": {"uv": [4.25, 0, 4.5, 3.875], "texture": "#0"},
"east": {"uv": [4, 0, 4.25, 3.875], "texture": "#0"},
"south": {"uv": [4.75, 0, 5, 3.875], "texture": "#0"},
"west": {"uv": [4.5, 0, 4.75, 3.875], "texture": "#0"}
}
},
{
"from": [15, -15, 15],
"to": [17, 16, 17],
"faces": {
"north": {"uv": [4.25, 0, 4.5, 3.875], "texture": "#0"},
"east": {"uv": [4, 0, 4.25, 3.875], "texture": "#0"},
"south": {"uv": [4.75, 0, 5, 3.875], "texture": "#0"},
"west": {"uv": [4.5, 0, 4.75, 3.875], "texture": "#0"}
}
},
{
"from": [-1, -16, -1],
"to": [17, -15, 17],
"faces": {
"north": {"uv": [0, 6.25, 2.25, 6.375], "texture": "#0"},
"east": {"uv": [0, 6.25, 2.25, 6.375], "texture": "#0"},
"south": {"uv": [0, 6.25, 2.25, 6.375], "texture": "#0"},
"west": {"uv": [0, 6.25, 2.25, 6.375], "texture": "#0"},
"up": {"uv": [0, 4, 2.25, 6.25], "texture": "#0"},
"down": {"uv": [0, 4, 2.25, 6.25], "texture": "#0"}
}
},
{
"from": [-1, 16, -1],
"to": [17, 17, 17],
"faces": {
"north": {"uv": [0, 6.25, 2.25, 6.375], "texture": "#0"},
"east": {"uv": [0, 6.25, 2.25, 6.375], "texture": "#0"},
"south": {"uv": [0, 6.25, 2.25, 6.375], "texture": "#0"},
"west": {"uv": [0, 6.25, 2.25, 6.375], "texture": "#0"},
"up": {"uv": [0, 4, 2.25, 6.25], "texture": "#0"},
"down": {"uv": [0, 4, 2.25, 6.25], "texture": "#0"}
}
}
]
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5dcef9b

Please sign in to comment.