Stop putting lamp posts in my games

This commit is contained in:
Andrew-71 2023-09-04 17:24:07 +03:00
parent be4d1b5af8
commit 466408a67d
20 changed files with 631 additions and 4 deletions

View file

@ -0,0 +1,26 @@
package su.a71.new_soviet.blocks.lamps;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldView;
import su.a71.new_soviet.util.Shapes;
import java.util.List;
public class DevTableLampBlock extends GoldenTableLampBlock {
public DevTableLampBlock(Settings settings) {
super(settings);
SHAPE = new Shapes.HorizontalShape(List.of(
List.of(5.0, 0.0, 5.0, 11.0, 2.0, 11.0),
List.of(7.0, 2.0, 7.0, 9.0, 4.0, 9.0),
List.of(6.0, 4.0, 6.0, 10.0, 5.0, 10.0),
List.of(3.0, 9.0, 3.0, 13.0, 13.0, 7.0)));
}
}

View file

@ -0,0 +1,88 @@
package su.a71.new_soviet.blocks.lamps;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.ShapeContext;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.DirectionProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.WorldView;
import su.a71.new_soviet.util.Shapes;
import java.util.List;
public class GoldenTableLampBlock extends LampBlock {
public static final DirectionProperty FACING;
public Shapes.HorizontalShape SHAPE = new Shapes.HorizontalShape(List.of(
List.of(5.0, 0.0, 5.0, 11.0, 2.0, 11.0),
List.of(7.0, 2.0, 7.0, 9.0, 4.0, 9.0),
List.of(6.0, 4.0, 6.0, 10.0, 5.0, 10.0),
List.of(3.0, 9.0, 3.0, 13.0, 13.0, 7.0)));
public GoldenTableLampBlock(Settings settings) {
super(settings, true, null);
this.setDefaultState(this.stateManager.getDefaultState()
.with(INVERTED, defaultLightState)
.with(WATERLOGGED, false)
.with(ON, false)
.with(Properties.HORIZONTAL_FACING, Direction.NORTH));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.HORIZONTAL_FACING);
super.appendProperties(builder);
}
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
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 boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
Direction direction = Direction.DOWN;
return Block.sideCoversSmallSquare(world, pos.offset(direction), direction.getOpposite());
}
public VoxelShape getStandingShape(){
VoxelShape shape = VoxelShapes.empty();
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.4375, 0.25, 0.4375, 0.5625, 0.875, 0.5625));
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.375, 0, 0.375, 0.625, 0.25, 0.625));
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.25, 0.6875, 0.25, 0.75, 0.9375, 0.75));
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.125, 0.3125, 0.125, 0.875, 0.6875, 0.875));
shape.simplify();
return shape;
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
}
public BlockState rotate(BlockState state, BlockRotation rotation) {
return (BlockState)state.with(FACING, rotation.rotate((Direction)state.get(FACING)));
}
public BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation((Direction)state.get(FACING)));
}
static {
FACING = Properties.HORIZONTAL_FACING;
}
}

View file

@ -60,7 +60,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"));
player.sendMessage(Text.translatable("block.new_soviet.light_bulb_block.energized"), 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));

View file

@ -0,0 +1,72 @@
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.fluid.Fluids;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
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;
protected static final VoxelShape SHAPE_BASE;
protected static final VoxelShape SHAPE_ATTACHED;
public LampPostBaseBlock(Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(Properties.ATTACHED, false));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.ATTACHED);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
if (state.get(Properties.ATTACHED)) {
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) {
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);
}
public static VoxelShape getBaseShape(){
VoxelShape shape = VoxelShapes.empty();
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.4375, 0.3125, 0.4375, 0.5625, 1, 0.5625));
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.375, 0, 0.375, 0.625, 0.3125, 0.625));
shape = VoxelShapes.union(shape, VoxelShapes.cuboid(0.40625, 0.5625, 0.40625, 0.59375, 0.6875, 0.59375));
shape.simplify();
return shape;
}
static {
SHAPE_ATTACHED = VoxelShapes.cuboid(0.4375, 0, 0.4375, 0.5625, 1, 0.5625);
SHAPE_BASE = getBaseShape();
}
}

View file

@ -19,9 +19,11 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.shape.VoxelShapes;
import su.a71.new_soviet.NewSoviet;
import su.a71.new_soviet.blocks.*;
import su.a71.new_soviet.blocks.lamps.GoldenTableLampBlock;
import su.a71.new_soviet.blocks.lamps.LightBulbLampBlock;
import su.a71.new_soviet.blocks.lamps.TableLampBlock;
import su.a71.new_soviet.blocks.lamps.VintageLampBlock;
import su.a71.new_soviet.blocks.lamps.lamp_post.LampPostBaseBlock;
import su.a71.new_soviet.entity.TVBlockEntity;
public class NSE_Custom extends NSE_BaseRegistration {
@ -34,9 +36,12 @@ public class NSE_Custom extends NSE_BaseRegistration {
public static final SwitchBlock SWITCH = new SwitchBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).notSolid().pistonBehavior(PistonBehavior.DESTROY).strength(1f, 2f).mapColor(MapColor.TERRACOTTA_WHITE));
public static final TableLampBlock TABLE_LAMP = new TableLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.WOOD).strength(0.9f, 1.5f).mapColor(MapColor.WHITE));
public static final TableLampBlock VINTAGE_LAMP = new VintageLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(0.9f, 1.5f).mapColor(MapColor.WHITE));
public static final GoldenTableLampBlock GOLDEN_LAMP = new GoldenTableLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(0.9f, 1.5f).mapColor(MapColor.GOLD));
public static final TableLampBlock VINTAGE_LAMP = new VintageLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(0.9f, 1.5f).mapColor(MapColor.TERRACOTTA_BROWN));
public static final LightBulbLampBlock LIGHT_BULB_LAMP = new LightBulbLampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.GLASS).strength(0.9f, 1.5f).mapColor(MapColor.WHITE).requiresTool());
public static final LampPostBaseBlock LAMP_POST_BASE = new LampPostBaseBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(1f, 1.5f).mapColor(MapColor.IRON_GRAY));
public static final CeilingFanBlock CEILING_FAN = new CeilingFanBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(1f, 1.5f).mapColor(MapColor.WHITE));
public static final SirenBlock SIREN = new SirenBlock();
@ -72,8 +77,10 @@ public class NSE_Custom extends NSE_BaseRegistration {
registerBlock("brown_tv", () -> BROWN_TV, NSE_CUSTOM_TAB);
registerBlock("radio_receiver", () -> RADIO_RECEIVER, NSE_CUSTOM_TAB);
registerBlock("table_lamp", () -> TABLE_LAMP, NSE_CUSTOM_TAB);
registerBlock("golden_table_lamp", () -> GOLDEN_LAMP, NSE_CUSTOM_TAB);
registerBlock("vintage_lamp", () -> VINTAGE_LAMP, NSE_CUSTOM_TAB);
registerBlock("light_bulb_lamp", () -> LIGHT_BULB_LAMP, NSE_CUSTOM_TAB);
registerBlock("lamp_post_base", () -> LAMP_POST_BASE, NSE_CUSTOM_TAB);
registerBlock("ceiling_fan", () -> CEILING_FAN, NSE_CUSTOM_TAB);
registerBlock("siren", () -> SIREN, NSE_CUSTOM_TAB);
registerBlock("landmine", () -> LANDMINE, NSE_CUSTOM_TAB);