mirror of
https://github.com/TeamMidnightDust/Decorative.git
synced 2025-12-15 12:35:10 +01:00
feat: improve sliding doors
This commit is contained in:
@@ -3,13 +3,10 @@ package eu.midnightdust.motschen.decorative.block;
|
||||
import eu.midnightdust.motschen.decorative.polymer.model.ItemDisplaySlidingDoorModel;
|
||||
import eu.pb4.factorytools.api.block.FactoryBlock;
|
||||
import eu.pb4.polymer.virtualentity.api.ElementHolder;
|
||||
import net.minecraft.block.AbstractBlock;
|
||||
import net.minecraft.block.BlockSetType;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.DoorBlock;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.enums.DoorHinge;
|
||||
import net.minecraft.block.enums.DoubleBlockHalf;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
@@ -24,6 +21,7 @@ import net.minecraft.util.shape.VoxelShape;
|
||||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.event.GameEvent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class SlidingDoor extends DoorBlock implements FactoryBlock {
|
||||
@@ -38,26 +36,59 @@ public class SlidingDoor extends DoorBlock implements FactoryBlock {
|
||||
private static final VoxelShape WEST_SHAPE_OPEN;
|
||||
|
||||
public SlidingDoor() {
|
||||
super(new BlockSetType("white_concrete"), AbstractBlock.Settings.copy(Blocks.WHITE_CONCRETE).nonOpaque().sounds(BlockSoundGroup.STONE));
|
||||
super(new BlockSetType("sliding_door", true, true, true, BlockSetType.ActivationRule.EVERYTHING, BlockSoundGroup.GLASS, SoundEvents.BLOCK_BARREL_CLOSE, SoundEvents.BLOCK_BARREL_OPEN, SoundEvents.BLOCK_WOODEN_TRAPDOOR_CLOSE, SoundEvents.BLOCK_WOODEN_TRAPDOOR_OPEN, SoundEvents.BLOCK_WOODEN_PRESSURE_PLATE_CLICK_OFF, SoundEvents.BLOCK_WOODEN_PRESSURE_PLATE_CLICK_ON, SoundEvents.BLOCK_WOODEN_BUTTON_CLICK_OFF, SoundEvents.BLOCK_WOODEN_BUTTON_CLICK_ON),
|
||||
AbstractBlock.Settings.copy(Blocks.WHITE_CONCRETE).nonOpaque().sounds(BlockSoundGroup.STONE));
|
||||
}
|
||||
protected void playOpenCloseSound(World world, BlockPos pos, boolean open) {
|
||||
world.playSound(null, pos, open ? SoundEvents.BLOCK_BARREL_OPEN : SoundEvents.BLOCK_BARREL_CLOSE, SoundCategory.BLOCKS, 1.0F, world.getRandom().nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
|
||||
state = state.cycle(OPEN);
|
||||
world.setBlockState(pos, state, 10);
|
||||
world.playSound(player, pos, SoundEvents.BLOCK_IRON_DOOR_OPEN, SoundCategory.BLOCKS, 0.1f, 1.2f);
|
||||
setOpen(player, world, state, pos, !state.get(OPEN));
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
|
||||
boolean bl = world.isReceivingRedstonePower(pos) || world.isReceivingRedstonePower(pos.offset(state.get(HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN));
|
||||
if (!this.getDefaultState().isOf(sourceBlock) && bl != state.get(POWERED)) {
|
||||
if (bl != state.get(OPEN)) {
|
||||
world.emitGameEvent(null, bl ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE, pos);
|
||||
}
|
||||
|
||||
world.setBlockState(pos, state.with(POWERED, bl));
|
||||
setOpen(null, world, state, pos, bl);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOpen(@Nullable Entity entity, World world, BlockState state, BlockPos pos, boolean open) {
|
||||
if (state.isOf(this) && state.get(OPEN) != open) {
|
||||
world.setBlockState(pos, state.with(OPEN, open), 10);
|
||||
this.playOpenCloseSound(world, pos, open);
|
||||
world.emitGameEvent(entity, open ? GameEvent.BLOCK_OPEN : GameEvent.BLOCK_CLOSE, pos);
|
||||
|
||||
for (Direction dir : new Direction[]{Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST}) {
|
||||
BlockState neighbourState = world.getBlockState(pos.offset(dir));
|
||||
if (neighbourState.isOf(this)) {
|
||||
world.setBlockState(pos.offset(dir), neighbourState.with(OPEN, open), 10);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
state.get(FACING);
|
||||
boolean bl = !state.get(OPEN);
|
||||
boolean bl2 = state.get(HINGE) == DoorHinge.RIGHT;
|
||||
return switch (state.get(FACING)) {
|
||||
default -> bl ? WEST_SHAPE : (bl2 ? EAST_SHAPE_OPEN : WEST_SHAPE_OPEN);
|
||||
case NORTH -> bl ? NORTH_SHAPE : (bl2 ? SOUTH_SHAPE_OPEN : NORTH_SHAPE_OPEN);
|
||||
case EAST -> bl ? EAST_SHAPE : (bl2 ? WEST_SHAPE_OPEN : EAST_SHAPE_OPEN);
|
||||
case SOUTH -> bl ? SOUTH_SHAPE : (bl2 ? NORTH_SHAPE_OPEN : SOUTH_SHAPE_OPEN);
|
||||
default -> bl ? WEST_SHAPE : (bl2 ? EAST_SHAPE_OPEN : WEST_SHAPE_OPEN);
|
||||
};
|
||||
}
|
||||
static {
|
||||
|
||||
@@ -55,7 +55,7 @@ public class ItemDisplaySlidingDoorModel extends BlockModel {
|
||||
var slidingDirection = state.get(SlidingDoor.HINGE) == DoorHinge.RIGHT ?
|
||||
state.get(SlidingDoor.FACING).rotateYClockwise() :
|
||||
state.get(SlidingDoor.FACING).rotateYCounterclockwise();
|
||||
this.main.setOffset(Vec3d.of(slidingDirection.getVector()));
|
||||
this.main.setOffset(Vec3d.of(slidingDirection.getVector()).multiply(0.9d));
|
||||
}
|
||||
else this.main.setOffset(Vec3d.ZERO);
|
||||
}
|
||||
|
||||
@@ -6,42 +6,19 @@ import java.time.LocalTime;
|
||||
|
||||
public class TimeUtil {
|
||||
public static int getHour12hFormat() {
|
||||
int hour;
|
||||
hour = LocalTime.now().getHour();
|
||||
if (hour > 12) {
|
||||
hour = hour - 12;
|
||||
}
|
||||
int hour = LocalTime.now().getHour();
|
||||
if (hour > 12)
|
||||
hour -= 12;
|
||||
return hour;
|
||||
}
|
||||
|
||||
public static String getTime() {
|
||||
String hour;
|
||||
String minute;
|
||||
String hour = switch (DecorativeConfig.timeFormat) {
|
||||
case h12 -> (getHour12hFormat() <= 9 ? "0" : "") + getHour12hFormat();
|
||||
default -> (LocalTime.now().getHour() <= 9 ? "0" : "") + LocalTime.now().getHour();
|
||||
};
|
||||
String minute = (LocalTime.now().getMinute() <= 9 ? "0" : "") + LocalTime.now().getMinute();
|
||||
|
||||
// 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;
|
||||
return hour+":"+minute;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user