mirror of
https://github.com/TeamMidnightDust/Decorative.git
synced 2025-12-15 12:35:10 +01:00
The clock is ticking
- Wall clocks are now working on Polymer!
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<WallClockBlockEntity> {
|
||||
private final WallClockHandsModel handsModel;
|
||||
@@ -22,15 +24,6 @@ public class WallClockRenderer implements BlockEntityRenderer<WallClockBlockEnti
|
||||
handsModel = new WallClockHandsModel(ctx.getLayerModelPart(WallClockHandsModel.CLOCK_HANDS_MODEL_LAYER));
|
||||
}
|
||||
|
||||
private int getHour12hFormat() {
|
||||
int hour;
|
||||
hour = LocalTime.now().getHour();
|
||||
if (hour >= 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")));
|
||||
|
||||
@@ -17,5 +17,6 @@ public class PolymerSupport {
|
||||
ItemDisplayPoolWallModel.initModels();
|
||||
ItemDisplaySlidingDoorModel.initModels();
|
||||
ItemDisplaySpringboardModel.initModels();
|
||||
ItemDisplayWallClockModel.initModels();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Float, Float> 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<Float, Float> 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);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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"}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -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"}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user