diff --git a/gradle.properties b/gradle.properties index 1362caf..d3fee91 100755 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx2G loader_version=0.15.11 # Mod Properties - mod_version = 4.3.0 + mod_version = 5.0.0-pre.1 maven_group = eu.midnightdust.motschen archives_base_name = decorative diff --git a/src/main/java/eu/midnightdust/motschen/decorative/block/WallClock.java b/src/main/java/eu/midnightdust/motschen/decorative/block/WallClock.java index d2aa4b1..bdc0404 100755 --- a/src/main/java/eu/midnightdust/motschen/decorative/block/WallClock.java +++ b/src/main/java/eu/midnightdust/motschen/decorative/block/WallClock.java @@ -3,7 +3,9 @@ package eu.midnightdust.motschen.decorative.block; import com.mojang.serialization.MapCodec; import eu.midnightdust.motschen.decorative.block.blockentity.WallClockBlockEntity; import eu.midnightdust.motschen.decorative.init.BlockEntities; +import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayWallClockModel; import eu.pb4.factorytools.api.block.FactoryBlock; +import eu.pb4.polymer.virtualentity.api.ElementHolder; import net.minecraft.block.AbstractBlock; import net.minecraft.block.Block; import net.minecraft.block.BlockEntityProvider; @@ -17,6 +19,8 @@ import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityTicker; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.item.ItemPlacementContext; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.BlockSoundGroup; import net.minecraft.state.StateManager; import net.minecraft.state.property.DirectionProperty; @@ -28,8 +32,6 @@ import net.minecraft.world.BlockView; import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; -import java.util.Objects; - public class WallClock extends BlockWithEntity implements BlockEntityProvider, FactoryBlock { private static final DirectionProperty FACING = HorizontalFacingBlock.FACING; private static final VoxelShape NORTH_SHAPE; @@ -106,6 +108,19 @@ public class WallClock extends BlockWithEntity implements BlockEntityProvider, F // Polymer @Override public BlockState getPolymerBlockState(BlockState state) { - return Blocks.BARRIER.getDefaultState(); + return Blocks.STRUCTURE_VOID.getDefaultState(); + } + @Override + public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) { + return Blocks.QUARTZ_BLOCK.getDefaultState(); + } + + @Override + public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) { + return new ItemDisplayWallClockModel(initialBlockState); + } + @Override + public boolean tickElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) { + return true; } } diff --git a/src/main/java/eu/midnightdust/motschen/decorative/block/render/WallClockRenderer.java b/src/main/java/eu/midnightdust/motschen/decorative/block/render/WallClockRenderer.java index 5e09cdc..d44ca86 100755 --- a/src/main/java/eu/midnightdust/motschen/decorative/block/render/WallClockRenderer.java +++ b/src/main/java/eu/midnightdust/motschen/decorative/block/render/WallClockRenderer.java @@ -14,6 +14,8 @@ import net.minecraft.util.math.RotationAxis; import java.time.LocalTime; +import static eu.midnightdust.motschen.decorative.util.TimeUtil.getHour12hFormat; + @Environment(EnvType.CLIENT) public class WallClockRenderer implements BlockEntityRenderer { private final WallClockHandsModel handsModel; @@ -22,15 +24,6 @@ public class WallClockRenderer implements BlockEntityRenderer= 12) { - hour = hour - 12; - } - return hour; - } - @Override public void render(WallClockBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) { VertexConsumer vertex = vertexConsumers.getBuffer(RenderLayer.getEntityCutoutNoCull(Identifier.ofVanilla("textures/block/red_concrete.png"))); diff --git a/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java b/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java index 31d0818..2c59ee8 100644 --- a/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java +++ b/src/main/java/eu/midnightdust/motschen/decorative/polymer/PolymerSupport.java @@ -17,5 +17,6 @@ public class PolymerSupport { ItemDisplayPoolWallModel.initModels(); ItemDisplaySlidingDoorModel.initModels(); ItemDisplaySpringboardModel.initModels(); + ItemDisplayWallClockModel.initModels(); } } diff --git a/src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplayWallClockModel.java b/src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplayWallClockModel.java new file mode 100644 index 0000000..d28f5ed --- /dev/null +++ b/src/main/java/eu/midnightdust/motschen/decorative/polymer/model/ItemDisplayWallClockModel.java @@ -0,0 +1,110 @@ +package eu.midnightdust.motschen.decorative.polymer.model; + +import eu.midnightdust.motschen.decorative.block.DigitalClock; +import eu.midnightdust.motschen.decorative.config.DecorativeConfig; +import eu.pb4.factorytools.api.resourcepack.BaseItemProvider; +import eu.pb4.factorytools.api.virtualentity.BlockModel; +import eu.pb4.factorytools.api.virtualentity.ItemDisplayElementUtil; +import eu.pb4.polymer.virtualentity.api.attachment.BlockAwareAttachment; +import eu.pb4.polymer.virtualentity.api.attachment.HolderAttachment; +import eu.pb4.polymer.virtualentity.api.elements.ItemDisplayElement; +import net.minecraft.block.BlockState; +import net.minecraft.block.HorizontalFacingBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.util.Pair; +import net.minecraft.util.math.RotationAxis; +import net.minecraft.util.math.Vec3d; +import org.joml.Vector3f; + +import java.time.LocalTime; + +import static eu.midnightdust.motschen.decorative.DecorativeMain.id; +import static eu.midnightdust.motschen.decorative.util.TimeUtil.getHour12hFormat; + +public class ItemDisplayWallClockModel extends BlockModel { + private final ItemDisplayElement main; + private final ItemDisplayElement hours; + private final ItemDisplayElement minutes; + private final ItemDisplayElement seconds; + private static ItemStack CASE; + private static ItemStack HAND; + private static ItemStack HAND_RED; + private float yRotation; + private Pair offset; + + public static void initModels() { + CASE = BaseItemProvider.requestModel(id("block/wall_clock")); + HAND = BaseItemProvider.requestModel(id("block/polymer/wall_clock_hand")); + HAND_RED = BaseItemProvider.requestModel(id("block/polymer/wall_clock_hand_red")); + } + + public ItemDisplayWallClockModel(BlockState state) { + this.main = ItemDisplayElementUtil.createSimple(getModel(state)); + this.main.setDisplaySize(1, 1); + this.main.setScale(new Vector3f(1)); + this.yRotation = getRotation(state); + this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(yRotation)); + this.main.setViewRange((DecorativeConfig.viewDistance / 100f)); + offset = getOffset(state); + this.main.setOffset(new Vec3d(offset.getLeft(), 0.0d, offset.getRight())); + this.addElement(this.main); + + this.hours = ItemDisplayElementUtil.createSimple(HAND); + this.hours.setDisplaySize(1, 1); + this.hours.setScale(new Vector3f(0.083333336f, 1.0f, 0.05f)); + this.hours.setOffset(new Vec3d(offset.getLeft(), 0.0d, offset.getRight())); + this.hours.setLeftRotation(RotationAxis.POSITIVE_Y.rotationDegrees(yRotation).rotateZ(-(float) Math.toRadians(getHour12hFormat() * 30d))); + this.hours.setViewRange((DecorativeConfig.viewDistance / 100f)); + this.addElement(hours); + + this.minutes = ItemDisplayElementUtil.createSimple(HAND); + this.minutes.setDisplaySize(1, 1); + this.minutes.setScale(new Vector3f(0.083333336f, 1.3333f, 0.05f)); + this.minutes.setOffset(new Vec3d(offset.getLeft(), 0.0d, offset.getRight())); + this.minutes.setLeftRotation(RotationAxis.POSITIVE_Y.rotationDegrees(yRotation).rotateZ(-(float) Math.toRadians(LocalTime.now().getMinute() * 6d))); + this.minutes.setViewRange((DecorativeConfig.viewDistance / 100f)); + this.addElement(minutes); + + this.seconds = ItemDisplayElementUtil.createSimple(HAND_RED); + this.seconds.setDisplaySize(1, 1); + this.seconds.setScale(new Vector3f(0.041666668f, 1.5f, 0.05f)); + this.seconds.setOffset(new Vec3d(offset.getLeft(), 0, offset.getRight())); + this.seconds.setLeftRotation(RotationAxis.POSITIVE_Y.rotationDegrees(yRotation).rotateZ(-(float) Math.toRadians(LocalTime.now().getSecond() * 6d))); + this.seconds.setViewRange((DecorativeConfig.viewDistance / 100f)); + this.addElement(seconds); + } + + @Override + public void notifyUpdate(HolderAttachment.UpdateType updateType) { + if (updateType == BlockAwareAttachment.BLOCK_STATE_UPDATE) { + var state = this.blockState(); + this.yRotation = getRotation(state); + this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(yRotation)); + offset = getOffset(state); + this.getElements().forEach(e -> e.setOffset(new Vec3d(offset.getLeft(), 0.0d, offset.getRight()))); + + this.tick(); + } + } + @Override + public void onTick() { + this.hours.setLeftRotation(RotationAxis.POSITIVE_Y.rotationDegrees(yRotation).rotateZ(-(float) Math.toRadians(getHour12hFormat() * 30d))); + this.minutes.setLeftRotation(RotationAxis.POSITIVE_Y.rotationDegrees(yRotation).rotateZ(-(float) Math.toRadians(LocalTime.now().getMinute() * 6d))); + this.seconds.setLeftRotation(RotationAxis.POSITIVE_Y.rotationDegrees(yRotation).rotateZ(-(float) Math.toRadians(LocalTime.now().getSecond() * 6d))); + } + public ItemStack getModel(BlockState state) { + return CASE; + } + public float getRotation(BlockState state) { + return state.get(DigitalClock.FACING).getHorizontal() * -90; + } + public Pair getOffset(BlockState state) { + return switch (state.get(HorizontalFacingBlock.FACING)) { + case NORTH -> new Pair<>(0.0f, 0.45f); + case EAST -> new Pair<>(-0.45f, 0.0f); + case SOUTH -> new Pair<>(0.0f, -0.45f); + default -> new Pair<>(0.45f, 0.0f); + }; + } +} + diff --git a/src/main/resources/assets/decorative/models/block/polymer/wall_clock_hand.json b/src/main/resources/assets/decorative/models/block/polymer/wall_clock_hand.json new file mode 100644 index 0000000..002d393 --- /dev/null +++ b/src/main/resources/assets/decorative/models/block/polymer/wall_clock_hand.json @@ -0,0 +1,23 @@ +{ + "credit": "Made with Blockbench", + "parent": "block/block", + "textures": { + "0": "block/black_concrete", + "particle": "block/black_concrete" + }, + "elements": [ + { + "from": [0, 8, 0], + "to": [16, 16, 16], + "rotation": {"angle": 0, "axis": "y", "origin": [6, 0, 0]}, + "faces": { + "north": {"uv": [0, 0, 16, 8], "texture": "#0"}, + "east": {"uv": [0, 0, 16, 8], "texture": "#0"}, + "south": {"uv": [0, 0, 16, 8], "texture": "#0"}, + "west": {"uv": [0, 0, 16, 8], "texture": "#0"}, + "up": {"uv": [0, 0, 16, 16], "texture": "#0"}, + "down": {"uv": [0, 0, 16, 16], "texture": "#0"} + } + } + ] +} \ No newline at end of file diff --git a/src/main/resources/assets/decorative/models/block/polymer/wall_clock_hand_red.json b/src/main/resources/assets/decorative/models/block/polymer/wall_clock_hand_red.json new file mode 100644 index 0000000..b649de8 --- /dev/null +++ b/src/main/resources/assets/decorative/models/block/polymer/wall_clock_hand_red.json @@ -0,0 +1,23 @@ +{ + "credit": "Made with Blockbench", + "parent": "block/block", + "textures": { + "0": "block/red_concrete", + "particle": "block/red_concrete" + }, + "elements": [ + { + "from": [0, 8, 0], + "to": [16, 16, 16], + "rotation": {"angle": 0, "axis": "y", "origin": [6, 0, 0]}, + "faces": { + "north": {"uv": [0, 0, 16, 8], "texture": "#0"}, + "east": {"uv": [0, 0, 16, 8], "texture": "#0"}, + "south": {"uv": [0, 0, 16, 8], "texture": "#0"}, + "west": {"uv": [0, 0, 16, 8], "texture": "#0"}, + "up": {"uv": [0, 0, 16, 16], "texture": "#0"}, + "down": {"uv": [0, 0, 16, 16], "texture": "#0"} + } + } + ] +} \ No newline at end of file