Skip to content

Commit

Permalink
Preliminary tardis model and polish™
Browse files Browse the repository at this point in the history
  • Loading branch information
enjarai committed Nov 16, 2023
1 parent 953eac1 commit 918bbe6
Show file tree
Hide file tree
Showing 12 changed files with 381 additions and 12 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ dependencies {

modImplementation include("eu.pb4:polymer-core:${property('deps.polymer')}")
modImplementation include("eu.pb4:polymer-virtual-entity:${property('deps.polymer')}")
modImplementation include("eu.pb4:polymer-resource-pack:${property('deps.polymer')}")
modRuntimeOnly("eu.pb4:polymer-autohost:${property('deps.polymer')}")
include(implementation(annotationProcessor("com.github.llamalad7.mixinextras:mixinextras-fabric:${property('deps.mixin_extras')}")))
modImplementation include("xyz.nucleoid:server-translations-api:${property('deps.server_translations_api')}")
include(modImplementation("me.lucko:fabric-permissions-api:${property('deps.permissions_api')}"))
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/dev/enjarai/minitardis/MiniTardis.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import dev.enjarai.minitardis.component.Tardis;
import dev.enjarai.minitardis.data.TardisInteriorManager;
import dev.enjarai.minitardis.item.ModItems;
import dev.enjarai.minitardis.item.PolymerModels;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
Expand Down Expand Up @@ -42,6 +44,9 @@ public void onInitialize() {

ModBlocks.load();
ModItems.load();

PolymerResourcePackUtils.addModAssets(MOD_ID);
PolymerModels.load();
}

@Nullable
Expand Down
51 changes: 49 additions & 2 deletions src/main/java/dev/enjarai/minitardis/block/InteriorDoorBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,55 @@

import eu.pb4.polymer.core.api.block.PolymerBlock;
import net.minecraft.block.*;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.EnumProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
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 static final EnumProperty<DoubleBlockHalf> HALF = Properties.DOUBLE_BLOCK_HALF;

protected InteriorDoorBlock(Settings settings) {
super(settings);
setDefaultState(getStateManager().getDefaultState().with(FACING, Direction.NORTH));
setDefaultState(getStateManager().getDefaultState().with(FACING, Direction.NORTH).with(HALF, DoubleBlockHalf.LOWER));
}

@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
BlockPos blockPos = ctx.getBlockPos();
World world = ctx.getWorld();
if (blockPos.getY() < world.getTopY() - 1 && world.getBlockState(blockPos.up()).canReplace(ctx)) {
return this.getDefaultState()
.with(FACING, ctx.getHorizontalPlayerFacing().getOpposite())
.with(HALF, DoubleBlockHalf.LOWER);
} else {
return null;
}
}

@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
var ownHalf = state.get(HALF);
var checkDirection = ownHalf == DoubleBlockHalf.UPPER ? Direction.DOWN : Direction.UP;
if (direction == checkDirection) {
return neighborState.isOf(this) && neighborState.get(HALF) != ownHalf ? state : Blocks.AIR.getDefaultState();
}
return state;
}

@Override
Expand All @@ -24,9 +59,21 @@ public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEnt
return ActionResult.SUCCESS;
}

@Override
public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
world.setBlockState(pos.up(), state.with(HALF, DoubleBlockHalf.UPPER), Block.NOTIFY_ALL);
}

@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockPos blockPos = pos.down();
BlockState blockState = world.getBlockState(blockPos);
return state.get(HALF) == DoubleBlockHalf.LOWER || blockState.isOf(this);
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
builder.add(FACING, HALF);
}

@Override
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/dev/enjarai/minitardis/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,37 @@
import net.fabricmc.fabric.api.object.builder.v1.world.poi.PointOfInterestHelper;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.MapColor;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.enums.Instrument;
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.math.Direction;
import net.minecraft.world.poi.PointOfInterestType;

import java.util.Arrays;
import java.util.List;
import java.util.Set;

public class ModBlocks {
public static final TardisExteriorBlock TARDIS_EXTERIOR =
register("tardis_exterior", new TardisExteriorBlock(FabricBlockSettings.create()));
register("tardis_exterior", new TardisExteriorBlock(FabricBlockSettings.create()
.mapColor(MapColor.LAPIS_BLUE)
.strength(-1.0F, 3600000.0F)
.dropsNothing()
.allowsSpawning(Blocks::never)));
public static final TardisExteriorExtensionBlock TARDIS_EXTERIOR_EXTENSION =
register("tardis_exterior_extension", new TardisExteriorExtensionBlock(FabricBlockSettings.create()
.mapColor(MapColor.LAPIS_BLUE)
.strength(-1.0F, 3600000.0F)
.dropsNothing()
.allowsSpawning(Blocks::never)));
public static final SimplePolymerBlock TARDIS_PLATING =
register("tardis_plating", new SimplePolymerBlock(FabricBlockSettings.create(), Blocks.DEAD_BRAIN_CORAL_BLOCK));
register("tardis_plating", new SimplePolymerBlock(FabricBlockSettings.create()
.mapColor(MapColor.BLACK)
.requiresTool()
.strength(50.0F, 1200.0F), Blocks.DEAD_BRAIN_CORAL_BLOCK));
public static final InteriorDoorBlock INTERIOR_DOOR =
register("interior_door", new InteriorDoorBlock(FabricBlockSettings.create()));
public static final ConsoleLeverBlock HANDBRAKE =
Expand All @@ -44,7 +62,8 @@ public class ModBlocks {
public static final PointOfInterestType TARDIS_EXTERIOR_POI =
PointOfInterestHelper.register(MiniTardis.id("tardis_exterior"), 0, 1, TARDIS_EXTERIOR);
public static final PointOfInterestType INTERIOR_DOOR_POI =
PointOfInterestHelper.register(MiniTardis.id("interior_door"), 0, 1, INTERIOR_DOOR);
PointOfInterestHelper.register(MiniTardis.id("interior_door"), 0, 1,
Arrays.stream(Direction.values()).map(d -> INTERIOR_DOOR.getDefaultState().with(InteriorDoorBlock.FACING, d)).toList());

public static final List<? extends Block> ITEM_BLOCKS = List.of(
TARDIS_PLATING, INTERIOR_DOOR, HANDBRAKE, CONSOLE_SCREEN,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package dev.enjarai.minitardis.block;

import dev.enjarai.minitardis.item.PolymerModels;
import eu.pb4.polymer.core.api.block.PolymerBlock;
import eu.pb4.polymer.resourcepack.api.PolymerResourcePackUtils;
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.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.BlockWithEntity;
Expand All @@ -10,18 +15,34 @@
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.Entity;
import net.minecraft.entity.decoration.Brightness;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
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 org.jetbrains.annotations.Nullable;

@SuppressWarnings("deprecation")
public class TardisExteriorBlock extends BlockWithEntity implements PolymerBlock {
public class TardisExteriorBlock extends BlockWithEntity implements PolymerBlock, BlockWithElementHolder {
public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING;

protected TardisExteriorBlock(Settings settings) {
super(settings);
setDefaultState(getStateManager().getDefaultState().with(FACING, Direction.NORTH));
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(FACING);
}

@Nullable
Expand All @@ -32,20 +53,40 @@ public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {

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

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient() && world.getBlockEntity(pos) instanceof TardisExteriorBlockEntity blockEntity) {
if (!world.isClient()
&& hit.getSide() == state.get(FACING)
&& world.getBlockEntity(pos) instanceof TardisExteriorBlockEntity blockEntity) {
blockEntity.teleportEntityIn(player);
}
return ActionResult.SUCCESS;
}

@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
world.setBlockState(pos.up(), ModBlocks.TARDIS_EXTERIOR_EXTENSION.getDefaultState());
}

@Nullable
@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
return validateTicker(type, ModBlocks.TARDIS_EXTERIOR_ENTITY, (world1, pos, state1, blockEntity) -> blockEntity.tick(world1, pos, state1));
}

@Override
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
var exteriorElement = new ItemDisplayElement();
exteriorElement.setItem(PolymerModels.getStack(PolymerModels.TARDIS));
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);
}};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.util.UUID;

public class TardisExteriorBlockEntity extends BlockEntity {
private UUID tardisUuid;
private UUID tardisUuid = UUID.randomUUID();
@Nullable
private Tardis tardis;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package dev.enjarai.minitardis.block;

import eu.pb4.polymer.core.api.block.PolymerBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;

@SuppressWarnings("deprecation")
public class TardisExteriorExtensionBlock extends Block implements PolymerBlock {
public TardisExteriorExtensionBlock(Settings settings) {
super(settings);
}

@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
return direction == Direction.DOWN && !neighborState.isOf(ModBlocks.TARDIS_EXTERIOR) ? Blocks.AIR.getDefaultState() : state;
}

@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!world.isClient()
&& hit.getSide() == world.getBlockState(pos.down()).get(TardisExteriorBlock.FACING)
&& world.getBlockEntity(pos.down()) instanceof TardisExteriorBlockEntity blockEntity) {
blockEntity.teleportEntityIn(player);
}
return ActionResult.SUCCESS;
}

@Override
public Block getPolymerBlock(BlockState state) {
return Blocks.BARRIER;
}
}
13 changes: 10 additions & 3 deletions src/main/java/dev/enjarai/minitardis/component/Tardis.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import dev.enjarai.minitardis.MiniTardis;
import dev.enjarai.minitardis.block.InteriorDoorBlock;
import dev.enjarai.minitardis.block.ModBlocks;
import dev.enjarai.minitardis.block.TardisExteriorBlockEntity;
import dev.enjarai.minitardis.component.flight.FlightState;
import dev.enjarai.minitardis.component.flight.LandedState;
import net.minecraft.block.FacingBlock;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.entity.Entity;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.registry.RegistryKey;
Expand All @@ -31,6 +33,7 @@

import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;

@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
Expand Down Expand Up @@ -164,7 +167,7 @@ public void teleportEntityIn(Entity entity) {
float yaw = -90;

do {
if (interiorDoorState.isOf(ModBlocks.INTERIOR_DOOR)) {
if (interiorDoorState.isOf(ModBlocks.INTERIOR_DOOR) && interiorDoorState.get(InteriorDoorBlock.HALF) == DoubleBlockHalf.LOWER) {
var facing = interiorDoorState.get(FacingBlock.FACING);
interiorDoorPosition = targetPos;

Expand All @@ -182,7 +185,7 @@ public void teleportEntityIn(Entity entity) {
} while (interiorDoorState.isOf(ModBlocks.INTERIOR_DOOR));

var entityPos = Vec3d.ofBottomCenter(targetPos);
entity.teleport(world, entityPos.getX(), entityPos.getY(), entityPos.getZ(), PositionFlag.VALUES, yaw, 0);
entity.teleport(world, entityPos.getX(), entityPos.getY(), entityPos.getZ(), Set.of(), yaw, 0);
}
}

Expand All @@ -204,13 +207,17 @@ public void teleportEntityOut(Entity entity) {
var exitPos = pos.add(facing.getVector());

var entityPos = Vec3d.ofBottomCenter(exitPos);
entity.teleport(world, entityPos.getX(), entityPos.getY(), entityPos.getZ(), PositionFlag.VALUES, facing.asRotation(), 0);
entity.teleport(world, entityPos.getX(), entityPos.getY(), entityPos.getZ(), Set.of(), facing.asRotation(), 0);
}
});
}
}


public BlockPos getInteriorCenter() {
return INTERIOR_CENTER;
}

public UUID uuid() {
return uuid;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.mojang.serialization.Codec;
import dev.enjarai.minitardis.MiniTardis;
import dev.enjarai.minitardis.component.Tardis;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier;

public class LandedState implements FlightState {
Expand All @@ -11,6 +13,10 @@ public class LandedState implements FlightState {

@Override
public FlightState tick(Tardis tardis) {
var world = tardis.getInteriorWorld();
for (var player : world.getPlayers()) {
world.playSoundFromEntity(null, player, SoundEvents.ENTITY_GUARDIAN_AMBIENT, SoundCategory.AMBIENT, 0.3f, 0f);
}
return this;
}

Expand Down
Loading

0 comments on commit 918bbe6

Please sign in to comment.