Lamps, fans and AIR RAID SIRENS

This commit is contained in:
Andrew-71 2023-07-14 19:47:44 +03:00
parent 99eab1b9ca
commit ee51f94613
53 changed files with 403 additions and 33 deletions

6
TODO
View file

@ -3,4 +3,8 @@
3. Add coconut as easter egg
4. Generate/Write crafting recipes
5. Fix PO2 wall
6. Work on custom blocks and doors, etc.
6. Work on custom blocks and doors, etc.
7. Fix lamp (upside down when placed, too big when hanging, uses voxelshape of a lantern)
8. Better organise industrial and custom texture folders.
9. Possibly make all NSE_<type> into a generic class with inheritance (for registration functions)
10. Decide on block hardness and blast resistance for all block types

View file

@ -12,5 +12,8 @@ public class NewSovietClient implements ClientModInitializer {
@Override
public void onInitializeClient() {
BlockRenderLayerMap.INSTANCE.putBlock(NSE_Blocks.CRATE, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(NSE_Custom.LAMP, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(NSE_Custom.CEILING_FAN, RenderLayer.getCutout());
BlockRenderLayerMap.INSTANCE.putBlock(NSE_Custom.SIREN, RenderLayer.getCutout());
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View 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;
}
}

View 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

View 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));
}
}

View file

@ -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));

View file

@ -0,0 +1,10 @@
{
"variants": {
"lit=true": {
"model": "new_soviet:block/ceiling_fan_on"
},
"lit=false": {
"model": "new_soviet:block/ceiling_fan_off"
}
}
}

View file

@ -0,0 +1,10 @@
{
"variants": {
"hanging=false": {
"model": "new_soviet:block/table_lamp"
},
"hanging=true": {
"model": "new_soviet:block/ceiling_lamp"
}
}
}

View file

@ -0,0 +1,8 @@
{
"variants": {
"facing=north": { "model": "new_soviet:block/siren", "uvlock": true },
"facing=east": { "model": "new_soviet:block/siren", "y": 90, "uvlock": false },
"facing=south": { "model": "new_soviet:block/siren", "y": 180, "uvlock": false },
"facing=west": { "model": "new_soviet:block/siren", "y": 270, "uvlock": false }
}
}

View file

@ -120,5 +120,9 @@
"block.new_soviet.tv": "TV",
"block.new_soviet.red_tv": "Red TV",
"block.new_soviet.brown_tv": "Brown TV",
"block.new_soviet.radio": "Radio"
"block.new_soviet.radio": "Radio",
"block.new_soviet.lamp": "Lamp",
"block.new_soviet.ceiling_fan": "Ceiling Fan",
"block.new_soviet.siren": "Siren"
}

View file

@ -1,7 +1,7 @@
{
"parent": "new_soviet:block/tv",
"textures": {
"0": "new_soviet:block/custom/brown_television",
"particle": "new_soviet:block/custom/brown_television"
"0": "new_soviet:block/custom/electronics/brown_television",
"particle": "new_soviet:block/custom/electronics/brown_television"
}
}

View file

@ -2,9 +2,9 @@
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"0": "C:/Users/Yura/Desktop/van_animated",
"1": "C:/Users/Yura/Desktop/fan_base",
"particle": "C:/Users/Yura/Desktop/van_animated"
"0": "new_soviet:block/custom/appliances/fan_static",
"1": "new_soviet:block/custom/appliances/fan_base",
"particle": "new_soviet:block/custom/appliances/fan_static"
},
"elements": [
{

View file

@ -0,0 +1,82 @@
{
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"0": "new_soviet:block/custom/appliances/fan_animated",
"1": "new_soviet:block/custom/appliances/fan_base",
"particle": "new_soviet:block/custom/appliances/fan_animated"
},
"elements": [
{
"name": "root",
"from": [6, 13, 6],
"to": [10, 16, 10],
"faces": {
"north": {"uv": [1, 4.25, 2, 5], "texture": "#1"},
"east": {"uv": [0, 4.25, 1, 5], "texture": "#1"},
"south": {"uv": [3, 4.25, 4, 5], "texture": "#1"},
"west": {"uv": [2, 4.25, 3, 5], "texture": "#1"},
"up": {"uv": [2, 4.25, 1, 3.25], "texture": "#1"},
"down": {"uv": [3, 3.25, 2, 4.25], "texture": "#1"}
}
},
{
"name": "root",
"from": [7, 7, 7],
"to": [9, 13, 9],
"faces": {
"north": {"uv": [0.5, 0.5, 1, 2], "texture": "#1"},
"east": {"uv": [0, 0.5, 0.5, 2], "texture": "#1"},
"south": {"uv": [1.5, 0.5, 2, 2], "texture": "#1"},
"west": {"uv": [1, 0.5, 1.5, 2], "texture": "#1"},
"up": {"uv": [1, 0.5, 0.5, 0], "texture": "#1"},
"down": {"uv": [1.5, 0, 1, 0.5], "texture": "#1"}
}
},
{
"name": "root",
"from": [4, 2, 4],
"to": [12, 7, 12],
"faces": {
"north": {"uv": [2, 2, 4, 3.25], "texture": "#1"},
"east": {"uv": [0, 2, 2, 3.25], "texture": "#1"},
"south": {"uv": [6, 2, 8, 3.25], "texture": "#1"},
"west": {"uv": [4, 2, 6, 3.25], "texture": "#1"},
"up": {"uv": [4, 2, 2, 0], "texture": "#1"},
"down": {"uv": [6, 0, 4, 2], "texture": "#1"}
}
},
{
"name": "root",
"from": [6, 0, 6],
"to": [10, 2, 10],
"faces": {
"north": {"uv": [4, 5, 5, 5.5], "texture": "#1"},
"east": {"uv": [3, 5, 4, 5.5], "texture": "#1"},
"south": {"uv": [6, 5, 7, 5.5], "texture": "#1"},
"west": {"uv": [5, 5, 6, 5.5], "texture": "#1"},
"up": {"uv": [5, 5, 4, 4], "texture": "#1"},
"down": {"uv": [6, 4, 5, 5], "texture": "#1"}
}
},
{
"name": "root",
"from": [-8, 1, -8],
"to": [24, 1, 24],
"faces": {
"up": {"uv": [16, 16, 0, 0], "texture": "#0"},
"down": {"uv": [16, 0, 0, 16], "texture": "#0"}
}
}
],
"groups": [
{
"name": "root",
"origin": [0, 0, 0],
"color": 0,
"nbt": "{}",
"armAnimationEnabled": false,
"children": [0, 1, 2, 3, 4]
}
]
}

View file

@ -1,8 +1,8 @@
{
"credit": "Made with Blockbench",
"textures": {
"0": "ceiling_lamp",
"particle": "ceiling_lamp"
"0": "new_soviet:block/custom/furniture/ceiling_lamp",
"particle": "new_soviet:block/custom/furniture/ceiling_lamp"
},
"elements": [
{

View file

@ -2,8 +2,8 @@
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"0": "new_soviet:block/custom/radio",
"particle": "new_soviet:block/custom/radio"
"0": "new_soviet:block/custom/electronics/radio",
"particle": "new_soviet:block/custom/electronics/radio"
},
"elements": [
{

View file

@ -1,7 +1,7 @@
{
"parent": "new_soviet:block/tv",
"textures": {
"0": "new_soviet:block/custom/red_television",
"particle": "new_soviet:block/custom/red_television"
"0": "new_soviet:block/custom/electronics/red_television",
"particle": "new_soviet:block/custom/electronics/red_television"
}
}

View file

@ -2,8 +2,8 @@
"credit": "Made with Blockbench",
"texture_size": [32, 32],
"textures": {
"0": "siren",
"particle": "siren"
"0": "new_soviet:block/custom/electronics/siren",
"particle": "new_soviet:block/custom/electronics/siren"
},
"elements": [
{

View file

@ -1,8 +1,8 @@
{
"credit": "Made with Blockbench",
"textures": {
"0": "custom/furniture/table_lamp",
"particle": "custom/furniture/table_lamp"
"0": "new_soviet:block/custom/furniture/table_lamp",
"particle": "new_soviet:block/custom/furniture/table_lamp"
},
"elements": [
{

View file

@ -2,8 +2,8 @@
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"0": "new_soviet:block/custom/television",
"particle": "new_soviet:block/custom/television"
"0": "new_soviet:block/custom/electronics/television",
"particle": "new_soviet:block/custom/electronics/television"
},
"elements": [
{

View file

@ -0,0 +1,4 @@
{
"parent": "new_soviet:block/ceiling_fan_off"
}

View file

@ -0,0 +1,3 @@
{
"parent": "new_soviet:block/table_lamp"
}

View file

@ -0,0 +1,4 @@
{
"parent": "new_soviet:block/siren"
}

View file

@ -0,0 +1,7 @@
{
"animation": {
"frametime": 1,
"interpolate": false,
"frames": [0, 1, 2, 3]
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 420 B

View file

@ -2,8 +2,8 @@
"credit": "Made with Blockbench",
"texture_size": [64, 64],
"textures": {
"1": "nuke",
"particle": "nuke"
"1": "stove",
"particle": "stove"
},
"elements": [
{

View file

@ -1,8 +1,8 @@
{
"credit": "Made with Blockbench",
"textures": {
"0": "bedside_tabl",
"particle": "bedside_tabl"
"0": "bedside_table",
"particle": "bedside_table"
},
"elements": [
{