From 8b1bc49709810ef78e146354e2b2b5e1624fcad8 Mon Sep 17 00:00:00 2001 From: Andrew-71 Date: Sun, 6 Aug 2023 23:01:22 +0300 Subject: [PATCH 1/2] Improve lightbulb and ceiling fan. Nerf siren --- .../new_soviet/blocks/CeilingFanBlock.java | 29 +++++++++++--- .../a71/new_soviet/blocks/LightBulbBlock.java | 40 ++++++++++++++++--- .../su/a71/new_soviet/blocks/SirenBlock.java | 9 ++--- 3 files changed, 63 insertions(+), 15 deletions(-) diff --git a/src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java b/src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java index 1de6289..16f8838 100644 --- a/src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java +++ b/src/main/java/su/a71/new_soviet/blocks/CeilingFanBlock.java @@ -1,10 +1,13 @@ package su.a71.new_soviet.blocks; import net.minecraft.block.*; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; 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.Properties; import net.minecraft.state.property.Property; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -13,25 +16,29 @@ 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.WorldAccess; 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 { +public class CeilingFanBlock extends Block implements Waterloggable { protected static final VoxelShape SHAPE; public static final BooleanProperty ON; + public static final BooleanProperty WATERLOGGED; public CeilingFanBlock(Block.Settings settings) { super(settings); - this.setDefaultState((BlockState)this.getDefaultState().with(ON, false)); + this.setDefaultState((BlockState)this.getDefaultState().with(ON, false).with(WATERLOGGED, false)); } @Nullable public BlockState getPlacementState(ItemPlacementContext ctx) { - return (BlockState)this.getDefaultState().with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())); + return (BlockState)this.getDefaultState() + .with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())) + .with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER); } public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) { @@ -44,10 +51,17 @@ public class CeilingFanBlock extends Block { world.setBlockState(pos, (BlockState)state.cycle(ON), 2); } } - } } + @Override + 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 direction == Direction.UP && !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); + } + 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); @@ -55,13 +69,17 @@ public class CeilingFanBlock extends Block { } protected void appendProperties(StateManager.Builder builder) { - builder.add(new Property[]{ON}); + builder.add(new Property[]{ON, WATERLOGGED}); } public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { return SHAPE; } + public FluidState getFluidState(BlockState state) { + return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); + } + public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { Direction direction = Direction.UP; return Block.sideCoversSmallSquare(world, pos.offset(direction), direction.getOpposite()); @@ -70,5 +88,6 @@ public class CeilingFanBlock extends Block { 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; + WATERLOGGED = Properties.WATERLOGGED; } } \ No newline at end of file diff --git a/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java b/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java index 7e28816..2fe414a 100644 --- a/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java +++ b/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java @@ -3,6 +3,8 @@ package su.a71.new_soviet.blocks; import net.minecraft.block.*; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.fluid.FluidState; +import net.minecraft.fluid.Fluids; import net.minecraft.item.ItemPlacementContext; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; @@ -10,6 +12,8 @@ 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.ActionResult; +import net.minecraft.util.Hand; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Direction; @@ -18,23 +22,28 @@ 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.WorldAccess; import net.minecraft.world.WorldView; import org.jetbrains.annotations.Nullable; import su.a71.new_soviet.registration.NSE_Custom; -public class LightBulbBlock extends Block { +public class LightBulbBlock extends Block implements Waterloggable { protected static final VoxelShape SHAPE; public static final BooleanProperty ON; public static final BooleanProperty BROKEN; + public static final BooleanProperty WATERLOGGED; public LightBulbBlock(Block.Settings settings) { - super(settings); - this.setDefaultState((BlockState)this.getDefaultState().with(ON, false).with(BROKEN, false)); + super(settings.luminance((BlockState state) -> state.get(ON) && !state.get(BROKEN) ? 12 : 0)); + this.setDefaultState((BlockState)this.getDefaultState().with(ON, false).with(BROKEN, false).with(WATERLOGGED, false)); } @Nullable public BlockState getPlacementState(ItemPlacementContext ctx) { - return (BlockState)this.getDefaultState().with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())).with(BROKEN, false); + return (BlockState)this.getDefaultState() + .with(ON, ctx.getWorld().isReceivingRedstonePower(ctx.getBlockPos())) + .with(BROKEN, false) + .with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER); } public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) { @@ -50,6 +59,22 @@ public class LightBulbBlock extends Block { } } + @Override + 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 direction == Direction.UP && !state.canPlaceAt(world, pos) ? Blocks.AIR.getDefaultState() : super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); + } + + @Override + public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { +// if (!world.isClient && !state.get(BROKEN)) { +// world.setBlockState(pos, (BlockState)state.with(ON, !state.get(ON)), 1); +// } + return super.onUse(state, world, pos, player, hand, hit); + } + @Override public void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile) { if (!state.get(BROKEN)) { @@ -66,7 +91,11 @@ public class LightBulbBlock extends Block { } protected void appendProperties(StateManager.Builder builder) { - builder.add(new Property[]{ON, BROKEN}); + builder.add(new Property[]{ON, BROKEN, WATERLOGGED}); + } + + public FluidState getFluidState(BlockState state) { + return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); } public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { @@ -86,5 +115,6 @@ public class LightBulbBlock extends Block { SHAPE = VoxelShapes.union(Block.createCuboidShape(7, 15, 7, 9, 16, 9), Block.createCuboidShape(7, 6, 7, 9, 8, 9)); //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; BROKEN = Properties.CRACKED; + WATERLOGGED = Properties.WATERLOGGED; } } \ No newline at end of file diff --git a/src/main/java/su/a71/new_soviet/blocks/SirenBlock.java b/src/main/java/su/a71/new_soviet/blocks/SirenBlock.java index 9b6a378..9d87d0d 100644 --- a/src/main/java/su/a71/new_soviet/blocks/SirenBlock.java +++ b/src/main/java/su/a71/new_soviet/blocks/SirenBlock.java @@ -90,11 +90,10 @@ public class SirenBlock extends HorizontalFacingBlock { public float getSirenVolume(World world, BlockPos pos) { return switch (world.getReceivedRedstonePower(pos)) { - case 1, 2, 3 -> 2f; - case 4, 5, 6 -> 3f; - case 7, 8, 9 -> 4f; - case 10, 11, 12 -> 5f; - case 13, 14, 15, 16 -> 6f; + case 4, 5, 6 -> 2f; + case 7, 8, 9 -> 3f; + case 10, 11, 12 -> 4f; + case 13, 14, 15, 16 -> 5f; default -> 1f; }; } From cd0ba2f0e2dcd03b46cbd959539b624e6a0dac70 Mon Sep 17 00:00:00 2001 From: Andrew-71 Date: Sun, 6 Aug 2023 23:32:19 +0300 Subject: [PATCH 2/2] Add lightbulb item for fixing lightbulb lamp --- src/main/java/su/a71/new_soviet/blocks/FUNC_IDEAS | 12 ++---------- .../su/a71/new_soviet/blocks/LightBulbBlock.java | 10 +++++++--- .../a71/new_soviet/registration/NSE_Custom.java | 2 +- .../su/a71/new_soviet/registration/NSE_Items.java | 5 +++-- .../resources/assets/new_soviet/lang/en_us.json | 3 ++- .../new_soviet/models/item/light_bulb_item.json | 7 +++++++ .../assets/new_soviet/textures/item/bulb.png | Bin 0 -> 315 bytes 7 files changed, 22 insertions(+), 17 deletions(-) create mode 100644 src/main/resources/assets/new_soviet/models/item/light_bulb_item.json create mode 100644 src/main/resources/assets/new_soviet/textures/item/bulb.png diff --git a/src/main/java/su/a71/new_soviet/blocks/FUNC_IDEAS b/src/main/java/su/a71/new_soviet/blocks/FUNC_IDEAS index 674942b..43672b2 100644 --- a/src/main/java/su/a71/new_soviet/blocks/FUNC_IDEAS +++ b/src/main/java/su/a71/new_soviet/blocks/FUNC_IDEAS @@ -1,13 +1,5 @@ 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 +Radio: Like a jukebox on steroids. Maybe container for disks, maybe a way to connect to real radio. Who knows. 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 - -Landmine: -попали -> кабум -тронули не лопатой -> кабум 80% -тронули лопатой(сломали) -> 25% кабум -обезвредили лопатой (ПКМ задержать) -> не кабум \ No newline at end of file +Crate: Like a shulker box but much smaller (but cheaper!) \ No newline at end of file diff --git a/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java b/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java index 2fe414a..85307c5 100644 --- a/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java +++ b/src/main/java/su/a71/new_soviet/blocks/LightBulbBlock.java @@ -26,6 +26,7 @@ import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldView; import org.jetbrains.annotations.Nullable; import su.a71.new_soviet.registration.NSE_Custom; +import su.a71.new_soviet.registration.NSE_Items; public class LightBulbBlock extends Block implements Waterloggable { protected static final VoxelShape SHAPE; @@ -69,9 +70,12 @@ public class LightBulbBlock extends Block implements Waterloggable { @Override public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { -// if (!world.isClient && !state.get(BROKEN)) { -// world.setBlockState(pos, (BlockState)state.with(ON, !state.get(ON)), 1); -// } + if (!world.isClient && state.get(BROKEN) && player.getInventory().getMainHandStack().getItem() == NSE_Items.LIGHT_BULB) { + if (!player.isCreative()) + player.getInventory().getMainHandStack().decrement(1); + world.setBlockState(pos, (BlockState)state.with(BROKEN, false) + .with(ON, world.isReceivingRedstonePower(pos)), 2); + } return super.onUse(state, world, pos, player, hand, hit); } diff --git a/src/main/java/su/a71/new_soviet/registration/NSE_Custom.java b/src/main/java/su/a71/new_soviet/registration/NSE_Custom.java index aeccdde..22a08de 100644 --- a/src/main/java/su/a71/new_soviet/registration/NSE_Custom.java +++ b/src/main/java/su/a71/new_soviet/registration/NSE_Custom.java @@ -29,7 +29,7 @@ public class NSE_Custom { public static final TVBlock BROWN_TV = new TVBlock(FabricBlockSettings.create().mapColor(MapColor.TERRACOTTA_BROWN)); public static final RadioBlock RADIO = new RadioBlock(); public static final LampBlock LAMP = new LampBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.LANTERN).strength(1f, 1.5f).mapColor(MapColor.WHITE)); - public static final LightBulbBlock LIGHT_BULB = new LightBulbBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.LANTERN).strength(1f, 1.5f).mapColor(MapColor.WHITE)); + public static final LightBulbBlock LIGHT_BULB = new LightBulbBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.GLASS).strength(1f, 1.5f).mapColor(MapColor.WHITE)); public static final SoundEvent LIGHT_BULB_BROKEN_SOUND = SoundEvent.of(new Identifier("new_soviet", "light_bulb_broken_sound")); public static final CeilingFanBlock CEILING_FAN = new CeilingFanBlock(FabricBlockSettings.create().sounds(BlockSoundGroup.METAL).strength(1f, 1.5f).mapColor(MapColor.WHITE)); diff --git a/src/main/java/su/a71/new_soviet/registration/NSE_Items.java b/src/main/java/su/a71/new_soviet/registration/NSE_Items.java index ee923f4..434f549 100644 --- a/src/main/java/su/a71/new_soviet/registration/NSE_Items.java +++ b/src/main/java/su/a71/new_soviet/registration/NSE_Items.java @@ -28,16 +28,16 @@ public class NSE_Items { // Like an iron axe but a hoe and slightly faster (-2.8f vs -3.1f) and a bit weaker (6 vs 6.5 damage) public static final ToolItem SICKLE = new HoeItem(ToolMaterials.IRON, 6, -2.8F, new Item.Settings()); - // TODO: Currently same as golden apple public static final FoodComponent COCONUT_FC = (new FoodComponent.Builder()).hunger(4).saturationModifier(1.2F).statusEffect(new StatusEffectInstance(StatusEffects.REGENERATION, 100, 1), 1.0F).statusEffect(new StatusEffectInstance(StatusEffects.ABSORPTION, 2400, 0), 1.0F).alwaysEdible().build(); public static final Item COCONUT = new Item(new Item.Settings().food(COCONUT_FC).rarity(Rarity.EPIC)); public static final DiceItem DICE_D6 = new DiceItem(new Item.Settings().maxCount(6)); public static final DiceD4Item DICE_D4 = new DiceD4Item(new Item.Settings().maxCount(6)); public static final DiceD20Item DICE_D20 = new DiceD20Item(new Item.Settings().maxCount(6)); - public static final SoundEvent DICE_SOUND = SoundEvent.of(new Identifier("new_soviet", "dice_sound")); + public static final Item LIGHT_BULB = new Item(new Item.Settings()); + private static final ItemGroup NSE_ITEMS_TAB = FabricItemGroup.builder() .icon(() -> new ItemStack(SICKLE)) .displayName(Text.translatable("itemGroup.new_soviet.items")) @@ -60,6 +60,7 @@ public class NSE_Items { register("dice_d6", () -> DICE_D6, NSE_ITEMS_TAB); register("dice_d4", () -> DICE_D4, NSE_ITEMS_TAB); register("dice_d20", () -> DICE_D20, NSE_ITEMS_TAB); + register("light_bulb_item", () -> LIGHT_BULB, NSE_ITEMS_TAB); Registry.register(Registries.SOUND_EVENT, new Identifier("new_soviet", "dice_sound"), DICE_SOUND); } diff --git a/src/main/resources/assets/new_soviet/lang/en_us.json b/src/main/resources/assets/new_soviet/lang/en_us.json index 69ffd03..850aa9e 100644 --- a/src/main/resources/assets/new_soviet/lang/en_us.json +++ b/src/main/resources/assets/new_soviet/lang/en_us.json @@ -150,5 +150,6 @@ "block.new_soviet.blue_concrete_with_bars": "Blue Concrete With Bars", "block.new_soviet.red_concrete_with_bars": "Red Concrete With Bars", "subtitles.new_soviet.light_bulb_broken": "Light bulb breaks", - "block.new_soviet.light_bulb": "Light Bulb" + "block.new_soviet.light_bulb": "Light Bulb Lamp", + "item.new_soviet.light_bulb_item": "Light Bulb" } \ No newline at end of file diff --git a/src/main/resources/assets/new_soviet/models/item/light_bulb_item.json b/src/main/resources/assets/new_soviet/models/item/light_bulb_item.json new file mode 100644 index 0000000..d12d23a --- /dev/null +++ b/src/main/resources/assets/new_soviet/models/item/light_bulb_item.json @@ -0,0 +1,7 @@ +{ + "credit": "Karoter2", + "parent": "item/generated", + "textures": { + "layer0": "new_soviet:item/bulb" + } +} \ No newline at end of file diff --git a/src/main/resources/assets/new_soviet/textures/item/bulb.png b/src/main/resources/assets/new_soviet/textures/item/bulb.png new file mode 100644 index 0000000000000000000000000000000000000000..fa266fda0b714e70b89d2ceebaf14f53b2f8f41d GIT binary patch literal 315 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|ZhN{ohFJ6_ zCrD%*=9KdeuKni$0s|@O1236C!tVLuBC|3WKBt%0zOI)@ zOGrpq5w~6Tu&Tx4rN1BC{4alRU($~4Rf5ey88Xa3;G8`{z3}3R0|yQWNJ{?ve`aOy z|MPRKzV6?>@9X}hz0B7N5)P)H__ubq>FVdQ&MBb@0Lln{ AZvX%Q literal 0 HcmV?d00001