Various minor improvements

This commit is contained in:
Andrew-71 2023-09-04 22:32:39 +03:00
parent 466408a67d
commit d2631b7714
8 changed files with 58 additions and 38 deletions

View file

@ -11,6 +11,7 @@ import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
@ -60,7 +61,7 @@ public class LightBulbLampBlock extends LampBlock {
return ActionResult.SUCCESS;
} else {
player.getItemCooldownManager().set(NSE_Items.LIGHT_BULB, 10);
player.sendMessage(Text.translatable("block.new_soviet.light_bulb_block.energized"), true);
player.sendMessage(Text.translatable("block.new_soviet.light_bulb_block.energized").formatted(Formatting.YELLOW), true);
world.playSound((PlayerEntity)null, pos.getX(), pos.getY(), pos.getZ(), NSE_Sounds.ELECTRIC_HIT, SoundCategory.AMBIENT, 0.8f, 1f);
if (!player.isCreative()) {
player.damage(world.getDamageSources().lightningBolt(), NewSoviet.RANDOM.nextBetween(1, 4));
@ -71,7 +72,6 @@ public class LightBulbLampBlock extends LampBlock {
return ActionResult.PASS;
} else {
return super.onUse(state, world, pos, player, hand, hit);
}
}

View file

@ -1,9 +1,7 @@
package su.a71.new_soviet.blocks.lamps.lamp_post;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.*;
import net.minecraft.fluid.FluidState;
import net.minecraft.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
@ -16,19 +14,22 @@ import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldAccess;
public class LampPostBaseBlock extends Block {
// public BooleanProperty is_extension = Properties.ATTACHED;
public class LampPostBaseBlock extends Block implements Waterloggable {
protected static final VoxelShape SHAPE_BASE;
protected static final VoxelShape SHAPE_ATTACHED;
public static final BooleanProperty WATERLOGGED;
public LampPostBaseBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(Properties.ATTACHED, false));
this.setDefaultState(this.stateManager.getDefaultState()
.with(Properties.ATTACHED, false)
.with(WATERLOGGED, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.ATTACHED);
builder.add(Properties.ATTACHED, WATERLOGGED);
}
@Override
@ -37,23 +38,20 @@ public class LampPostBaseBlock extends Block {
return SHAPE_ATTACHED;
};
return SHAPE_BASE;
// Direction dir = state.get(FACING);
// return switch (dir) {
// case NORTH -> SHAPE.north();
// case SOUTH -> SHAPE.south();
// case EAST -> SHAPE.east();
// case WEST -> SHAPE.west();
// default -> VoxelShapes.fullCube();
// };
}
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
return !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state.with(Properties.ATTACHED, world.getBlockState(pos.down()).getBlock() instanceof LampPostBaseBlock), direction, neighborState, world, pos, neighborPos);
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getPlacementState(ctx).with(Properties.ATTACHED, ctx.getWorld().getBlockState(ctx.getBlockPos().down()).getBlock() instanceof LampPostBaseBlock);
return super.getPlacementState(ctx)
.with(Properties.ATTACHED, ctx.getWorld().getBlockState(ctx.getBlockPos().down()).getBlock() instanceof LampPostBaseBlock)
.with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
}
public static VoxelShape getBaseShape(){
@ -65,8 +63,13 @@ public class LampPostBaseBlock extends Block {
return shape;
}
public FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}
static {
SHAPE_ATTACHED = VoxelShapes.cuboid(0.4375, 0, 0.4375, 0.5625, 1, 0.5625);
SHAPE_BASE = getBaseShape();
WATERLOGGED = Properties.WATERLOGGED;
}
}