Lamps, fans and AIR RAID SIRENS
This commit is contained in:
parent
99eab1b9ca
commit
ee51f94613
53 changed files with 403 additions and 33 deletions
|
@ -3,7 +3,7 @@ package su.a71.new_soviet;
|
|||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
|
||||
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemGroup;
|
||||
|
@ -11,10 +11,10 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import su.a71.new_soviet.blocks.RadioBlock;
|
||||
import su.a71.new_soviet.blocks.TVBlock;
|
||||
import su.a71.new_soviet.blocks.*;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Supplier;
|
||||
|
@ -24,8 +24,12 @@ public class NSE_Custom {
|
|||
public static final TVBlock TV = new TVBlock();
|
||||
public static final TVBlock RED_TV = new TVBlock();
|
||||
public static final TVBlock BROWN_TV = new TVBlock();
|
||||
|
||||
public static final RadioBlock RADIO = new RadioBlock();
|
||||
public static final LampBlock LAMP = new LampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.LANTERN));
|
||||
public static final CeilingFanBlock CEILING_FAN = new CeilingFanBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL));
|
||||
|
||||
public static final AirRaidBlock SIREN = new AirRaidBlock();
|
||||
|
||||
|
||||
private static final ItemGroup NSE_CUSTOM_TAB = FabricItemGroup.builder()
|
||||
.icon(() -> new ItemStack(TV))
|
||||
|
@ -50,5 +54,9 @@ public class NSE_Custom {
|
|||
register("red_tv", () -> RED_TV, NSE_CUSTOM_TAB);
|
||||
register("brown_tv", () -> BROWN_TV, NSE_CUSTOM_TAB);
|
||||
register("radio", () -> RADIO, NSE_CUSTOM_TAB);
|
||||
register("lamp", () -> LAMP, NSE_CUSTOM_TAB);
|
||||
register("ceiling_fan", () -> CEILING_FAN, NSE_CUSTOM_TAB);
|
||||
register("siren", () -> SIREN, NSE_CUSTOM_TAB);
|
||||
|
||||
}
|
||||
}
|
|
@ -1,11 +1,58 @@
|
|||
package su.a71.new_soviet.blocks;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.block.piston.PistonBehavior;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
import net.minecraft.state.StateManager;
|
||||
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;
|
||||
|
||||
public class AirRaidBlock extends Block {
|
||||
import net.minecraft.block.TripwireHookBlock;
|
||||
import net.minecraft.world.WorldView;
|
||||
|
||||
public AirRaidBlock(Settings settings) {
|
||||
super(settings);
|
||||
public class AirRaidBlock extends HorizontalFacingBlock {
|
||||
public AirRaidBlock() {
|
||||
super(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).notSolid().pistonBehavior(PistonBehavior.DESTROY));
|
||||
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(Properties.HORIZONTAL_FACING);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext ctx) {
|
||||
Direction dir = state.get(FACING);
|
||||
switch(dir) {
|
||||
case NORTH:
|
||||
return Block.createCuboidShape(3.5, 2, 11, 12.5, 15, 16);
|
||||
case SOUTH:
|
||||
return Block.createCuboidShape(3.5, 2, 0, 12.5, 15, 5);
|
||||
case EAST:
|
||||
return Block.createCuboidShape(0, 2, 3.5, 5, 15, 12.5);
|
||||
case WEST:
|
||||
return Block.createCuboidShape(11, 2, 3.5, 16, 15, 12.5);
|
||||
default:
|
||||
return VoxelShapes.fullCube();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return super.getPlacementState(ctx).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
|
||||
}
|
||||
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
Direction direction = (Direction)state.get(FACING);
|
||||
BlockPos blockPos = pos.offset(direction.getOpposite());
|
||||
BlockState blockState = world.getBlockState(blockPos);
|
||||
return direction.getAxis().isHorizontal() && blockState.isSideSolidFullSquare(world, blockPos, direction);
|
||||
}
|
||||
}
|
75
src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java
Normal file
75
src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java
Normal file
|
@ -0,0 +1,75 @@
|
|||
package su.a71.new_soviet.blocks;
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
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.WorldView;
|
||||
|
||||
import net.minecraft.block.RedstoneLampBlock;
|
||||
import net.minecraft.block.TorchBlock;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CeilingFanBlock extends Block {
|
||||
protected static final VoxelShape SHAPE;
|
||||
public static final BooleanProperty ON;
|
||||
|
||||
public CeilingFanBlock(Block.Settings settings) {
|
||||
super(settings);
|
||||
this.setDefaultState((BlockState)this.getDefaultState().with(ON, false));
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
return (BlockState)this.getDefaultState().with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos()));
|
||||
}
|
||||
|
||||
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
|
||||
if (!world.isClient) {
|
||||
boolean bl = (Boolean)state.get(ON);
|
||||
if (bl != world.isReceivingRedstonePower(pos)) {
|
||||
if (bl) {
|
||||
world.scheduleBlockTick(pos, this, 4);
|
||||
} else {
|
||||
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
|
||||
if ((Boolean)state.get(ON) && !world.isReceivingRedstonePower(pos)) {
|
||||
world.setBlockState(pos, (BlockState)state.cycle(ON), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(new Property[]{ON});
|
||||
}
|
||||
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
return SHAPE;
|
||||
}
|
||||
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
Direction direction = Direction.UP;
|
||||
return Block.sideCoversSmallSquare(world, pos.offset(direction), direction.getOpposite());
|
||||
}
|
||||
|
||||
static {
|
||||
SHAPE = VoxelShapes.union(Block.createCuboidShape(4.0, 2.0, 4.0, 12.0, 7.0, 12.0), Block.createCuboidShape(7.0, 7.0, 7.0, 9.0, 13.0, 9.0), Block.createCuboidShape(6.0, 13.0, 6.0, 10.0, 16.0, 10.0));
|
||||
ON = RedstoneTorchBlock.LIT;
|
||||
}
|
||||
}
|
7
src/main/java/su/a71/new_soviet/blocks/FUNC_IDEAS
Normal file
7
src/main/java/su/a71/new_soviet/blocks/FUNC_IDEAS
Normal file
|
@ -0,0 +1,7 @@
|
|||
Ideas for block functionality
|
||||
|
||||
Radio: Inventory where you can put music disks, and a UI to play, shuffle (and pause?) them. Like a jukebox on steroids
|
||||
TV: CC compatible peripheral which combines a speaker and an 8x8 monitor
|
||||
Crate: Inventory, like a barrel but smaller
|
||||
Air Raid Siren: when powered (?), plays chosen frequency in chosen way at chosen sound. CC Peripheral attached
|
||||
Lamp: Both bedside and ceiling are one block, Lamp, that functions sort of like a lantern
|
92
src/main/java/su/a71/new_soviet/blocks/LampBlock.java
Normal file
92
src/main/java/su/a71/new_soviet/blocks/LampBlock.java
Normal file
|
@ -0,0 +1,92 @@
|
|||
package su.a71.new_soviet.blocks;
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.entity.ai.pathing.NavigationType;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
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.state.property.Property;
|
||||
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;
|
||||
import net.minecraft.world.WorldView;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.function.ToIntFunction;
|
||||
|
||||
public class LampBlock extends Block implements Waterloggable {
|
||||
public static final BooleanProperty HANGING;
|
||||
public static final BooleanProperty WATERLOGGED;
|
||||
protected static final VoxelShape STANDING_SHAPE;
|
||||
protected static final VoxelShape HANGING_SHAPE;
|
||||
|
||||
public LampBlock(AbstractBlock.Settings settings) {
|
||||
super(settings.luminance((BlockState state) -> 12));
|
||||
this.setDefaultState(this.stateManager.getDefaultState().with(HANGING, false).with(WATERLOGGED, false));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BlockState getPlacementState(ItemPlacementContext ctx) {
|
||||
FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos());
|
||||
Direction[] var3 = ctx.getPlacementDirections();
|
||||
int var4 = var3.length;
|
||||
|
||||
for (int var5 = 0; var5 < var4; ++var5) {
|
||||
Direction direction = var3[var5];
|
||||
if (direction.getAxis() == Direction.Axis.Y) {
|
||||
BlockState blockState = this.getDefaultState().with(HANGING, direction == Direction.UP);
|
||||
if (blockState.canPlaceAt(ctx.getWorld(), ctx.getBlockPos())) {
|
||||
return blockState.with(WATERLOGGED, fluidState.getFluid() == Fluids.WATER);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
|
||||
return (Boolean) state.get(HANGING) ? HANGING_SHAPE : STANDING_SHAPE;
|
||||
}
|
||||
|
||||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
|
||||
builder.add(new Property[]{HANGING, WATERLOGGED});
|
||||
}
|
||||
|
||||
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
|
||||
Direction direction = attachedDirection(state).getOpposite();
|
||||
return Block.sideCoversSmallSquare(world, pos.offset(direction), direction.getOpposite());
|
||||
}
|
||||
|
||||
protected static Direction attachedDirection(BlockState state) {
|
||||
return (Boolean) state.get(HANGING) ? Direction.DOWN : Direction.UP;
|
||||
}
|
||||
|
||||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
|
||||
if ((Boolean) state.get(WATERLOGGED)) {
|
||||
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
|
||||
}
|
||||
|
||||
return attachedDirection(state).getOpposite() == direction && !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
|
||||
}
|
||||
|
||||
public FluidState getFluidState(BlockState state) {
|
||||
return (Boolean) state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
|
||||
}
|
||||
|
||||
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static {
|
||||
HANGING = Properties.HANGING;
|
||||
WATERLOGGED = Properties.WATERLOGGED;
|
||||
STANDING_SHAPE = VoxelShapes.union(Block.createCuboidShape(5.0, 0.0, 5.0, 11.0, 7.0, 11.0), Block.createCuboidShape(6.0, 7.0, 6.0, 10.0, 9.0, 10.0));
|
||||
HANGING_SHAPE = VoxelShapes.union(Block.createCuboidShape(5.0, 1.0, 5.0, 11.0, 8.0, 11.0), Block.createCuboidShape(6.0, 8.0, 6.0, 10.0, 10.0, 10.0));
|
||||
}
|
||||
}
|
|
@ -16,6 +16,8 @@ import net.minecraft.util.shape.VoxelShape;
|
|||
import net.minecraft.util.shape.VoxelShapes;
|
||||
import net.minecraft.world.BlockView;
|
||||
|
||||
import net.minecraft.block.SkullBlock;
|
||||
|
||||
public class RadioBlock extends HorizontalFacingBlock {
|
||||
public RadioBlock() {
|
||||
super(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).notSolid().pistonBehavior(PistonBehavior.DESTROY));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue