Skip to content

Commit 091f3de

Browse files
committed
moisture detector extra state
1 parent d66fdfb commit 091f3de

File tree

10 files changed

+97
-22
lines changed

10 files changed

+97
-22
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
{
22
"variants": {
3-
"": {
3+
"check_level=false": {
44
"model": "rounded:block/moisture_detector"
5+
},
6+
"check_level=true": {
7+
"model": "rounded:block/moisture_detector_level"
58
}
69
}
710
}

src/client/resources/assets/rounded/lang/en_us.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,9 @@
3030

3131
"tag.worldgen.biome.rounded.has_lustershrooms": "Has lustershrooms",
3232
"tag.worldgen.biome.rounded.has_more_lustershrooms": "Has more lustershrooms",
33-
"tag.worldgen.biome.rounded.has_smooth_basalt_sea_rocks": "Has Smooth Basalt sea rocks",
33+
"tag.worldgen.biome.rounded.has_smooth_basalt_sea_rocks": "Has smooth basalt sea rocks",
3434
"tag.worldgen.biome.rounded.has_andesite_sea_rocks": "Has andesite sea rocks",
3535
"tag.worldgen.biome.rounded.has_diorite_sea_rocks": "Has diorite sea rocks",
36-
"tag.worldgen.biome.rounded.has_sea_copper_deposits": "Has sea copper deposits",
3736
"tag.worldgen.biome.rounded.has_bladderwrack": "Has bladderwrack",
3837
"tag.item.rounded.trough_feed": "Trough Feed",
3938
"tag.item.rounded.treated_planks": "Treated Planks",

src/client/resources/assets/rounded/lang/pl_pl.json

+13
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,26 @@
1414
"block.rounded.lustershroom_block": "Blok lśniącogrzybu",
1515
"block.rounded.luster_cluster": "Skupiony lśniącogrzyb",
1616
"block.rounded.trough": "Koryto",
17+
"block.rounded.smooth_prismarine": "Gładki pryzmaryn",
18+
"block.rounded.smooth_prismarine_slab": "Gładka pryzmarynowa płyta",
19+
"block.rounded.chiseled_prismarine_bricks": "Rzeźbione pryzmarynowe cegły",
20+
"block.rounded.prismarine_lantern": "Pryzmarynowa latarenka",
21+
"block.rounded.dead_bladderwrack": "Martwy morszczyn",
22+
"block.rounded.bladderwrack": "Morszczyn",
23+
"block.rounded.dead_bladderwrack_block": "Blok martwego morszczynu",
24+
"block.rounded.bladderwrack_block": "Blok morszczynu",
25+
"block.rounded.moisture_detector": "Detektor wilgoci",
1726

1827
"subtitles.rounded.block.trough_fill": "Napełniono koryto",
1928
"subtitles.rounded.block.trough_consume": "Opróżniono koryto",
2029
"subtitles.rounded.block.trough_rustle": "Pasza szeleści",
2130

2231
"tag.worldgen.biome.rounded.has_lustershrooms": "Ma lśniącogrzyby",
2332
"tag.worldgen.biome.rounded.has_more_lustershrooms": "Ma więcej lśniącogrzybów",
33+
"tag.worldgen.biome.rounded.has_smooth_basalt_sea_rocks": "Ma gładko-bazaltowe głazy morskie",
34+
"tag.worldgen.biome.rounded.has_andesite_sea_rocks": "Ma andezytowe głazy morskie",
35+
"tag.worldgen.biome.rounded.has_diorite_sea_rocks": "Ma diorytowe głazy morskie",
36+
"tag.worldgen.biome.rounded.has_bladderwrack": "Ma morszczyn",
2437
"tag.item.rounded.trough_feed": "Pasza",
2538
"tag.item.rounded.treated_planks": "Impregnowane deski",
2639
"tag.item.c.grain": "Zboże",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"parent": "block/cube_bottom_top",
3+
"textures": {
4+
"top": "rounded:block/moisture_detector_top_level",
5+
"side": "rounded:block/moisture_detector_side",
6+
"bottom": "rounded:block/smooth_prismarine"
7+
}
8+
}
Loading
Loading

src/main/java/com/lumiscosity/rounded/blocks/MoistureDetectorBlock.java

+49-17
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,28 @@
55
import net.minecraft.block.entity.BlockEntity;
66
import net.minecraft.block.entity.BlockEntityTicker;
77
import net.minecraft.block.entity.BlockEntityType;
8+
import net.minecraft.entity.player.PlayerEntity;
89
import net.minecraft.fluid.FluidState;
910
import net.minecraft.state.StateManager;
11+
import net.minecraft.state.property.BooleanProperty;
1012
import net.minecraft.state.property.IntProperty;
1113
import net.minecraft.state.property.Properties;
14+
import net.minecraft.util.ActionResult;
15+
import net.minecraft.util.hit.BlockHitResult;
1216
import net.minecraft.util.math.BlockPos;
1317
import net.minecraft.util.math.Direction;
1418
import net.minecraft.util.math.MathHelper;
1519
import net.minecraft.world.BlockView;
1620
import net.minecraft.world.World;
21+
import net.minecraft.world.event.GameEvent;
1722
import org.jetbrains.annotations.Nullable;
1823

1924
import static com.lumiscosity.rounded.blocks.RegisterBlocks.MOISTURE_DETECTOR_BE;
2025

2126
public class MoistureDetectorBlock extends BlockWithEntity {
2227
public static final MapCodec<MoistureDetectorBlock> CODEC = createCodec(MoistureDetectorBlock::new);
2328
public static final IntProperty POWER = Properties.POWER;
29+
public static final BooleanProperty CHECK_LEVEL = BooleanProperty.of("check_level");
2430

2531
@Override
2632
public MapCodec<MoistureDetectorBlock> getCodec() {
@@ -29,7 +35,7 @@ public MapCodec<MoistureDetectorBlock> getCodec() {
2935

3036
public MoistureDetectorBlock(AbstractBlock.Settings settings) {
3137
super(settings);
32-
this.setDefaultState(this.stateManager.getDefaultState().with(POWER, 0));
38+
this.setDefaultState(this.stateManager.getDefaultState().with(POWER, 0).with(CHECK_LEVEL, false));
3339
}
3440

3541
@Override
@@ -42,9 +48,31 @@ protected int getWeakRedstonePower(BlockState state, BlockView world, BlockPos p
4248
return state.get(POWER);
4349
}
4450

51+
public static void updateState(BlockState state, World world, BlockPos pos) {
52+
BlockPos check_pos = pos.up();
53+
if (state.get(CHECK_LEVEL)) {
54+
if (world.getBlockState(check_pos).isOf(Blocks.WATER)) {
55+
getWaterLevel(state, world, pos, world.getFluidState(check_pos));
56+
} else if (world.getBlockState(check_pos).contains(Properties.WATERLOGGED) ? world.getBlockState(check_pos).get(Properties.WATERLOGGED) : false) {
57+
if (state.get(POWER) != 9) {
58+
world.setBlockState(pos, state.with(POWER, 9), Block.NOTIFY_ALL);
59+
}
60+
} else {
61+
if (state.get(POWER) != 0) {
62+
world.setBlockState(pos, state.with(POWER, 0), Block.NOTIFY_ALL);
63+
}
64+
}
65+
} else if (world.getBlockState(check_pos).isOf(Blocks.AIR) && world.hasRain(check_pos)) {
66+
getRainLevel(state, world, pos);
67+
} else {
68+
if (state.get(POWER) != 0) {
69+
world.setBlockState(pos, state.with(POWER, 0), Block.NOTIFY_ALL);
70+
}
71+
}
72+
}
73+
4574
public static void getWaterLevel(BlockState state, World world, BlockPos pos, FluidState water) {
4675
int i = water.getLevel();
47-
i = MathHelper.clamp(i, 0, 15);
4876
if (state.get(POWER) != i) {
4977
world.setBlockState(pos, state.with(POWER, i), Block.NOTIFY_ALL);
5078
}
@@ -57,6 +85,23 @@ public static void getRainLevel(BlockState state, World world, BlockPos pos) {
5785
}
5886
}
5987

88+
@Override
89+
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
90+
if (player.canModifyBlocks()) {
91+
if (world.isClient) {
92+
return ActionResult.SUCCESS;
93+
} else {
94+
BlockState blockState = state.cycle(CHECK_LEVEL);
95+
world.setBlockState(pos, blockState, Block.NOTIFY_LISTENERS);
96+
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, blockState));
97+
updateState(blockState, world, pos);
98+
return ActionResult.CONSUME;
99+
}
100+
} else {
101+
return super.onUse(state, world, pos, player, hit);
102+
}
103+
}
104+
60105
@Override
61106
protected boolean emitsRedstonePower(BlockState state) {
62107
return true;
@@ -81,25 +126,12 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, Block
81126

82127
private static void tick(World world, BlockPos pos, BlockState state, MoistureDetectorBlockEntity blockEntity) {
83128
if (world.getTime() % 2L == 0L) {
84-
BlockPos check_pos = pos.up();
85-
if (world.getBlockState(check_pos).isOf(Blocks.WATER)) {
86-
getWaterLevel(state, world, pos, world.getFluidState(check_pos));
87-
} else if (world.getBlockState(check_pos).contains(Properties.WATERLOGGED) ? world.getBlockState(check_pos).get(Properties.WATERLOGGED) : false) {
88-
if (state.get(POWER) != 9) {
89-
world.setBlockState(pos, state.with(POWER, 9), Block.NOTIFY_ALL);
90-
}
91-
} else if (world.getBlockState(check_pos).isOf(Blocks.AIR) && world.hasRain(check_pos)) {
92-
getRainLevel(state, world, pos);
93-
} else {
94-
if (state.get(POWER) != 0) {
95-
world.setBlockState(pos, state.with(POWER, 0), Block.NOTIFY_ALL);
96-
}
97-
}
129+
updateState(state, world, pos);
98130
}
99131
}
100132

101133
@Override
102134
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
103-
builder.add(POWER);
135+
builder.add(POWER, MoistureDetectorBlock.CHECK_LEVEL);
104136
}
105137
}

src/main/java/com/lumiscosity/rounded/blocks/RegisterBlocks.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -273,8 +273,8 @@ public static void initBlocks() {
273273
});
274274

275275
register_block("moisture_detector", MOISTURE_DETECTOR, MOISTURE_DETECTOR_ITEM);
276-
ItemGroupEvents.modifyEntriesEvent(ItemGroups.FUNCTIONAL).register(content -> {
277-
content.addAfter(Registries.BLOCK.get(Identifier.of("minecraft", "daylight_detector")), BLADDERWRACK_BLOCK_ITEM);
276+
ItemGroupEvents.modifyEntriesEvent(ItemGroups.REDSTONE).register(content -> {
277+
content.addAfter(Registries.BLOCK.get(Identifier.of("minecraft", "daylight_detector")), MOISTURE_DETECTOR_ITEM);
278278
});
279279
}
280280

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.lumiscosity.rounded.mixin;
2+
3+
import com.lumiscosity.rounded.blocks.RegisterBlocks;
4+
import net.minecraft.block.Block;
5+
import net.minecraft.block.Blocks;
6+
import net.minecraft.block.entity.ConduitBlockEntity;
7+
import org.spongepowered.asm.mixin.*;
8+
9+
@Mixin(ConduitBlockEntity.class)
10+
public class ExtraConduitPowerMixin {
11+
@Shadow
12+
@Final
13+
@Mutable
14+
private static Block[] ACTIVATING_BLOCKS;
15+
16+
static {
17+
ACTIVATING_BLOCKS = new Block[]{Blocks.PRISMARINE, Blocks.PRISMARINE_BRICKS, Blocks.SEA_LANTERN, Blocks.DARK_PRISMARINE, RegisterBlocks.CHISELED_PRISMARINE_BRICKS, RegisterBlocks.SMOOTH_PRISMARINE};
18+
}
19+
}

src/main/resources/rounded.mixins.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"package": "com.lumiscosity.rounded.mixin",
44
"compatibilityLevel": "JAVA_21",
55
"mixins": [
6+
"ExtraConduitPowerMixin",
67
"TroughFallCancelMixin"
78
],
89
"injectors": {

0 commit comments

Comments
 (0)