mirror of
https://github.com/TeamMidnightDust/Decorative.git
synced 2025-12-15 12:35:10 +01:00
Even more polymer progress!
This commit is contained in:
@@ -92,7 +92,7 @@ public class ChoppingLog extends BlockWithEntity implements BlockEntityProvider,
|
||||
}
|
||||
@Override
|
||||
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
|
||||
return Blocks.STONE_BUTTON.getDefaultState().with(Properties.BLOCK_FACE, BlockFace.FLOOR);
|
||||
return getPolymerBlockState(state);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package eu.midnightdust.motschen.decorative.block;
|
||||
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayChristmasLightsModel;
|
||||
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.BlockState;
|
||||
@@ -11,6 +13,8 @@ import net.minecraft.block.RedstoneLampBlock;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
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.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
@@ -26,6 +30,7 @@ import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldView;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ChristmasLights extends HorizontalFacingBlock implements FactoryBlock {
|
||||
|
||||
@@ -40,7 +45,8 @@ public class ChristmasLights extends HorizontalFacingBlock implements FactoryBlo
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH).with(LIT, Boolean.FALSE));
|
||||
}
|
||||
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
||||
world.setBlockState(pos, state.with(LIT, !state.get(LIT)));
|
||||
world.playSound(player, pos, SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON, SoundCategory.BLOCKS, 0.2f, 0.5f);
|
||||
return ActionResult.SUCCESS;
|
||||
@@ -102,4 +108,13 @@ public class ChristmasLights extends HorizontalFacingBlock implements FactoryBlo
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return Blocks.BARRIER.getDefaultState();
|
||||
}
|
||||
@Override
|
||||
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
|
||||
return Blocks.BLACK_CONCRETE.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
|
||||
return new ItemDisplayChristmasLightsModel(initialBlockState, pos, world);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
package eu.midnightdust.motschen.decorative.block;
|
||||
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayChristmasTreeModel;
|
||||
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.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.WorldView;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ChristmasTree extends Block implements FactoryBlock {
|
||||
private static final VoxelShape SHAPE;
|
||||
@@ -36,5 +41,14 @@ public class ChristmasTree extends Block implements FactoryBlock {
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return Blocks.BARRIER.getDefaultState();
|
||||
}
|
||||
@Override
|
||||
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
|
||||
return Blocks.SPRUCE_LEAVES.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
|
||||
return new ItemDisplayChristmasTreeModel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,7 +3,10 @@ package eu.midnightdust.motschen.decorative.block;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import eu.midnightdust.motschen.decorative.block.blockentity.DigitalClockBlockEntity;
|
||||
import eu.midnightdust.motschen.decorative.init.BlockEntities;
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayChristmasTreeModel;
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayDigitalClockModel;
|
||||
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 +20,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;
|
||||
@@ -29,7 +34,7 @@ import net.minecraft.world.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class DigitalClock extends BlockWithEntity implements BlockEntityProvider, FactoryBlock {
|
||||
private static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
|
||||
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING;
|
||||
private static final VoxelShape NORTH_SHAPE;
|
||||
private static final VoxelShape EAST_SHAPE;
|
||||
private static final VoxelShape SOUTH_SHAPE;
|
||||
@@ -106,4 +111,17 @@ public class DigitalClock extends BlockWithEntity implements BlockEntityProvider
|
||||
public BlockState getPolymerBlockState(BlockState state) {
|
||||
return Blocks.BARRIER.getDefaultState();
|
||||
}
|
||||
@Override
|
||||
public BlockState getPolymerBreakEventBlockState(BlockState state, ServerPlayerEntity player) {
|
||||
return Blocks.WHITE_CONCRETE.getDefaultState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
|
||||
return new ItemDisplayDigitalClockModel(initialBlockState);
|
||||
}
|
||||
@Override
|
||||
public boolean tickElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package eu.midnightdust.motschen.decorative.block.render;
|
||||
|
||||
import eu.midnightdust.motschen.decorative.block.blockentity.DigitalClockBlockEntity;
|
||||
import eu.midnightdust.motschen.decorative.config.DecorativeConfig;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.font.TextRenderer;
|
||||
@@ -11,7 +10,7 @@ import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
|
||||
import java.time.LocalTime;
|
||||
import static eu.midnightdust.motschen.decorative.util.TimeUtil.getTime;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class DigitalClockRenderer implements BlockEntityRenderer<DigitalClockBlockEntity> {
|
||||
@@ -21,45 +20,6 @@ public class DigitalClockRenderer implements BlockEntityRenderer<DigitalClockBlo
|
||||
textRenderer = ctx.getTextRenderer();
|
||||
}
|
||||
|
||||
private int getHour12hFormat() {
|
||||
int hour;
|
||||
hour = LocalTime.now().getHour();
|
||||
if (hour > 12) {
|
||||
hour = hour - 12;
|
||||
}
|
||||
return hour;
|
||||
}
|
||||
private String getTime() {
|
||||
String hour;
|
||||
String minute;
|
||||
|
||||
// Hour
|
||||
if (DecorativeConfig.timeFormat.equals(DecorativeConfig.TimeFormat.h12)) {
|
||||
if (getHour12hFormat() <= 9) {
|
||||
hour = "0" + getHour12hFormat();
|
||||
} else {
|
||||
hour = "" + getHour12hFormat();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (LocalTime.now().getHour() <= 9) {
|
||||
hour = "0" + LocalTime.now().getHour();
|
||||
} else {
|
||||
hour = "" + LocalTime.now().getHour();
|
||||
}
|
||||
}
|
||||
|
||||
// Minute
|
||||
if (LocalTime.now().getMinute() <= 9) {
|
||||
minute = "0" + LocalTime.now().getMinute();
|
||||
}
|
||||
else {
|
||||
minute = "" + LocalTime.now().getMinute();
|
||||
}
|
||||
|
||||
return hour +":"+ minute;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void render(DigitalClockBlockEntity blockEntity, float tickDelta, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay) {
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package eu.midnightdust.motschen.decorative.polymer;
|
||||
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayBirdBathModel;
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayChristmasLightsModel;
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayChristmasTreeModel;
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplayDigitalClockModel;
|
||||
|
||||
public class PolymerSupport {
|
||||
public static void init() {
|
||||
ItemDisplayBirdBathModel.initModels();
|
||||
ItemDisplayChristmasLightsModel.initModels();
|
||||
ItemDisplayChristmasTreeModel.initModels();
|
||||
ItemDisplayDigitalClockModel.initModels();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
package eu.midnightdust.motschen.decorative.polymer.model;
|
||||
|
||||
public class ItemDisplayCeilingFanModel {
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package eu.midnightdust.motschen.decorative.polymer.model;
|
||||
|
||||
import eu.midnightdust.motschen.decorative.block.ChristmasLights;
|
||||
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.item.ItemStack;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import static eu.midnightdust.motschen.decorative.DecorativeMain.id;
|
||||
|
||||
public class ItemDisplayChristmasLightsModel extends BlockModel {
|
||||
private final ItemDisplayElement main;
|
||||
public static ItemStack OFF;
|
||||
public static ItemStack ON;
|
||||
|
||||
public static void initModels() {
|
||||
OFF = BaseItemProvider.requestModel(id("block/christmas_lights_off"));
|
||||
ON = BaseItemProvider.requestModel(id("block/christmas_lights_off"));
|
||||
}
|
||||
|
||||
public ItemDisplayChristmasLightsModel(BlockState state, BlockPos pos, ServerWorld world) {
|
||||
this.main = ItemDisplayElementUtil.createSimple(state.get(ChristmasLights.LIT) ? ON : OFF);
|
||||
this.main.setDisplaySize(1, 1);
|
||||
this.main.setScale(new Vector3f(2));
|
||||
this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(state.get(ChristmasLights.FACING).asRotation()));
|
||||
this.main.setViewRange(0.75f * (DecorativeConfig.viewDistance / 100f));
|
||||
this.addElement(this.main);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyUpdate(HolderAttachment.UpdateType updateType) {
|
||||
if (updateType == BlockAwareAttachment.BLOCK_STATE_UPDATE) {
|
||||
var state = this.blockState();
|
||||
this.main.setItem(state.get(ChristmasLights.LIT) ? ON : OFF);
|
||||
this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(state.get(ChristmasLights.FACING).asRotation()));
|
||||
|
||||
this.tick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package eu.midnightdust.motschen.decorative.polymer.model;
|
||||
|
||||
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.elements.ItemDisplayElement;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import static eu.midnightdust.motschen.decorative.DecorativeMain.id;
|
||||
|
||||
public class ItemDisplayChristmasTreeModel extends BlockModel {
|
||||
public static ItemStack TREE;
|
||||
|
||||
public static void initModels() {
|
||||
TREE = BaseItemProvider.requestModel(id("block/christmas_tree"));
|
||||
}
|
||||
|
||||
public ItemDisplayChristmasTreeModel() {
|
||||
ItemDisplayElement main = ItemDisplayElementUtil.createSimple(TREE);
|
||||
main.setDisplaySize(1, 1);
|
||||
main.setScale(new Vector3f(2));
|
||||
main.setOffset(new Vec3d(0, 0.4d, 0));
|
||||
main.setViewRange(DecorativeConfig.viewDistance / 100f);
|
||||
this.addElement(main);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
package eu.midnightdust.motschen.decorative.polymer.model;
|
||||
|
||||
import eu.midnightdust.motschen.decorative.block.DigitalClock;
|
||||
import eu.midnightdust.motschen.decorative.config.DecorativeConfig;
|
||||
import eu.midnightdust.motschen.decorative.util.ColorUtil;
|
||||
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 eu.pb4.polymer.virtualentity.api.elements.TextDisplayElement;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.HorizontalFacingBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Pair;
|
||||
import net.minecraft.util.math.RotationAxis;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static eu.midnightdust.motschen.decorative.DecorativeMain.id;
|
||||
import static eu.midnightdust.motschen.decorative.util.TimeUtil.getTime;
|
||||
|
||||
public class ItemDisplayDigitalClockModel extends BlockModel {
|
||||
private final ItemDisplayElement main;
|
||||
private final TextDisplayElement text;
|
||||
private static final Map<String, ItemStack> models = new HashMap<>();
|
||||
|
||||
public static void initModels() {
|
||||
for (int i = 0; i < ColorUtil.VanillaColor.length(); i++) {
|
||||
String color = ColorUtil.VanillaColor.byNumber(i).getName();
|
||||
models.put(color, BaseItemProvider.requestModel(id("block/"+color+"_digital_clock")));
|
||||
}
|
||||
}
|
||||
|
||||
public ItemDisplayDigitalClockModel(BlockState state) {
|
||||
this.main = ItemDisplayElementUtil.createSimple(getModel(state));
|
||||
this.main.setDisplaySize(1, 1);
|
||||
this.main.setScale(new Vector3f(2));
|
||||
this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(getRotation(state)));
|
||||
this.main.setViewRange(0.75f * (DecorativeConfig.viewDistance / 100f));
|
||||
this.addElement(this.main);
|
||||
this.text = new TextDisplayElement(Text.of(getTime()));
|
||||
this.text.setDisplaySize(1, 1);
|
||||
this.text.setScale(new Vector3f(1));
|
||||
var offset = getOffset(state);
|
||||
this.text.setOffset(new Vec3d(offset.getLeft(), -0.4d, offset.getRight()));
|
||||
this.text.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(getRotation(state)));
|
||||
this.text.setBackground(0x0000000);
|
||||
this.text.setShadow(true);
|
||||
this.addElement(this.text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyUpdate(HolderAttachment.UpdateType updateType) {
|
||||
if (updateType == BlockAwareAttachment.BLOCK_STATE_UPDATE) {
|
||||
var state = this.blockState();
|
||||
this.main.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(getRotation(state)));
|
||||
var offset = getOffset(state);
|
||||
this.text.setOffset(new Vec3d(offset.getLeft(), -0.4d, offset.getRight()));
|
||||
this.text.setRightRotation(RotationAxis.POSITIVE_Y.rotationDegrees(getRotation(state)));
|
||||
|
||||
this.tick();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onTick() {
|
||||
this.text.setText(Text.of(getTime()));
|
||||
}
|
||||
public ItemStack getModel(BlockState state) {
|
||||
return models.get(ColorUtil.VanillaColor.fromBlockName(state.getBlock().getTranslationKey()).getName());
|
||||
}
|
||||
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.025f, -0.12599999f);
|
||||
case EAST -> new Pair<>(0.12599999f, 0.025f);
|
||||
case SOUTH -> new Pair<>(-0.025f, 0.12599999f);
|
||||
default -> new Pair<>(-0.12599999f, -0.025f);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package eu.midnightdust.motschen.decorative.util;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ColorUtil {
|
||||
public static int convertRgbToArgb(int rgb) {
|
||||
int red = 0xFF & (rgb >> 16);
|
||||
@@ -16,4 +18,35 @@ public class ColorUtil {
|
||||
var biome = world.getBiome(pos);
|
||||
return biome == null ? 4159204 : biome.value().getWaterColor();
|
||||
}
|
||||
|
||||
public enum VanillaColor {
|
||||
WHITE("white"), ORANGE("orange"), MAGENTA("magenta"), LIGHT_BLUE("light_blue"), YELLOW("yellow"), LIME("lime"),
|
||||
PINK("pink"), GRAY("gray"), LIGHT_GRAY("light_gray"), CYAN("cyan"), PURPLE("purple"), BLUE("blue"),
|
||||
BROWN("brown"), GREEN("green"), RED("red"), BLACK("black");
|
||||
private final String name;
|
||||
private static final VanillaColor[] vals = values();
|
||||
|
||||
VanillaColor(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public VanillaColor next() {
|
||||
return vals[(this.ordinal() + 1) % vals.length];
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public static VanillaColor byNumber(int id) {
|
||||
return vals[id];
|
||||
}
|
||||
public static int length() {
|
||||
return vals.length;
|
||||
}
|
||||
public static VanillaColor fromBlockName(String name) {
|
||||
return Arrays.stream(vals).filter(color -> name
|
||||
.replace("block.decorative.", "")
|
||||
.replace("_digital_clock", "")
|
||||
.equals(color.getName())).findFirst().orElse(VanillaColor.BLACK);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package eu.midnightdust.motschen.decorative.util;
|
||||
|
||||
import eu.midnightdust.motschen.decorative.config.DecorativeConfig;
|
||||
|
||||
import java.time.LocalTime;
|
||||
|
||||
public class TimeUtil {
|
||||
public static int getHour12hFormat() {
|
||||
int hour;
|
||||
hour = LocalTime.now().getHour();
|
||||
if (hour > 12) {
|
||||
hour = hour - 12;
|
||||
}
|
||||
return hour;
|
||||
}
|
||||
|
||||
public static String getTime() {
|
||||
String hour;
|
||||
String minute;
|
||||
|
||||
// Hour
|
||||
if (DecorativeConfig.timeFormat.equals(DecorativeConfig.TimeFormat.h12)) {
|
||||
if (getHour12hFormat() <= 9) {
|
||||
hour = "0" + getHour12hFormat();
|
||||
} else {
|
||||
hour = "" + getHour12hFormat();
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (LocalTime.now().getHour() <= 9) {
|
||||
hour = "0" + LocalTime.now().getHour();
|
||||
} else {
|
||||
hour = "" + LocalTime.now().getHour();
|
||||
}
|
||||
}
|
||||
|
||||
// Minute
|
||||
if (LocalTime.now().getMinute() <= 9) {
|
||||
minute = "0" + LocalTime.now().getMinute();
|
||||
}
|
||||
else {
|
||||
minute = "" + LocalTime.now().getMinute();
|
||||
}
|
||||
|
||||
return hour +":"+ minute;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user