Skip to content

Commit

Permalink
moisture detector extra state
Browse files Browse the repository at this point in the history
  • Loading branch information
lumiscosity committed Jul 31, 2024
1 parent d66fdfb commit 091f3de
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
{
"variants": {
"": {
"check_level=false": {
"model": "rounded:block/moisture_detector"
},
"check_level=true": {
"model": "rounded:block/moisture_detector_level"
}
}
}
3 changes: 1 addition & 2 deletions src/client/resources/assets/rounded/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@

"tag.worldgen.biome.rounded.has_lustershrooms": "Has lustershrooms",
"tag.worldgen.biome.rounded.has_more_lustershrooms": "Has more lustershrooms",
"tag.worldgen.biome.rounded.has_smooth_basalt_sea_rocks": "Has Smooth Basalt sea rocks",
"tag.worldgen.biome.rounded.has_smooth_basalt_sea_rocks": "Has smooth basalt sea rocks",
"tag.worldgen.biome.rounded.has_andesite_sea_rocks": "Has andesite sea rocks",
"tag.worldgen.biome.rounded.has_diorite_sea_rocks": "Has diorite sea rocks",
"tag.worldgen.biome.rounded.has_sea_copper_deposits": "Has sea copper deposits",
"tag.worldgen.biome.rounded.has_bladderwrack": "Has bladderwrack",
"tag.item.rounded.trough_feed": "Trough Feed",
"tag.item.rounded.treated_planks": "Treated Planks",
Expand Down
13 changes: 13 additions & 0 deletions src/client/resources/assets/rounded/lang/pl_pl.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,26 @@
"block.rounded.lustershroom_block": "Blok lśniącogrzybu",
"block.rounded.luster_cluster": "Skupiony lśniącogrzyb",
"block.rounded.trough": "Koryto",
"block.rounded.smooth_prismarine": "Gładki pryzmaryn",
"block.rounded.smooth_prismarine_slab": "Gładka pryzmarynowa płyta",
"block.rounded.chiseled_prismarine_bricks": "Rzeźbione pryzmarynowe cegły",
"block.rounded.prismarine_lantern": "Pryzmarynowa latarenka",
"block.rounded.dead_bladderwrack": "Martwy morszczyn",
"block.rounded.bladderwrack": "Morszczyn",
"block.rounded.dead_bladderwrack_block": "Blok martwego morszczynu",
"block.rounded.bladderwrack_block": "Blok morszczynu",
"block.rounded.moisture_detector": "Detektor wilgoci",

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

"tag.worldgen.biome.rounded.has_lustershrooms": "Ma lśniącogrzyby",
"tag.worldgen.biome.rounded.has_more_lustershrooms": "Ma więcej lśniącogrzybów",
"tag.worldgen.biome.rounded.has_smooth_basalt_sea_rocks": "Ma gładko-bazaltowe głazy morskie",
"tag.worldgen.biome.rounded.has_andesite_sea_rocks": "Ma andezytowe głazy morskie",
"tag.worldgen.biome.rounded.has_diorite_sea_rocks": "Ma diorytowe głazy morskie",
"tag.worldgen.biome.rounded.has_bladderwrack": "Ma morszczyn",
"tag.item.rounded.trough_feed": "Pasza",
"tag.item.rounded.treated_planks": "Impregnowane deski",
"tag.item.c.grain": "Zboże",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parent": "block/cube_bottom_top",
"textures": {
"top": "rounded:block/moisture_detector_top_level",
"side": "rounded:block/moisture_detector_side",
"bottom": "rounded:block/smooth_prismarine"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.fluid.FluidState;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.IntProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.event.GameEvent;
import org.jetbrains.annotations.Nullable;

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

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

@Override
public MapCodec<MoistureDetectorBlock> getCodec() {
Expand All @@ -29,7 +35,7 @@ public MapCodec<MoistureDetectorBlock> getCodec() {

public MoistureDetectorBlock(AbstractBlock.Settings settings) {
super(settings);
this.setDefaultState(this.stateManager.getDefaultState().with(POWER, 0));
this.setDefaultState(this.stateManager.getDefaultState().with(POWER, 0).with(CHECK_LEVEL, false));
}

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

public static void updateState(BlockState state, World world, BlockPos pos) {
BlockPos check_pos = pos.up();
if (state.get(CHECK_LEVEL)) {
if (world.getBlockState(check_pos).isOf(Blocks.WATER)) {
getWaterLevel(state, world, pos, world.getFluidState(check_pos));
} else if (world.getBlockState(check_pos).contains(Properties.WATERLOGGED) ? world.getBlockState(check_pos).get(Properties.WATERLOGGED) : false) {
if (state.get(POWER) != 9) {
world.setBlockState(pos, state.with(POWER, 9), Block.NOTIFY_ALL);
}
} else {
if (state.get(POWER) != 0) {
world.setBlockState(pos, state.with(POWER, 0), Block.NOTIFY_ALL);
}
}
} else if (world.getBlockState(check_pos).isOf(Blocks.AIR) && world.hasRain(check_pos)) {
getRainLevel(state, world, pos);
} else {
if (state.get(POWER) != 0) {
world.setBlockState(pos, state.with(POWER, 0), Block.NOTIFY_ALL);
}
}
}

public static void getWaterLevel(BlockState state, World world, BlockPos pos, FluidState water) {
int i = water.getLevel();
i = MathHelper.clamp(i, 0, 15);
if (state.get(POWER) != i) {
world.setBlockState(pos, state.with(POWER, i), Block.NOTIFY_ALL);
}
Expand All @@ -57,6 +85,23 @@ public static void getRainLevel(BlockState state, World world, BlockPos pos) {
}
}

@Override
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (player.canModifyBlocks()) {
if (world.isClient) {
return ActionResult.SUCCESS;
} else {
BlockState blockState = state.cycle(CHECK_LEVEL);
world.setBlockState(pos, blockState, Block.NOTIFY_LISTENERS);
world.emitGameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Emitter.of(player, blockState));
updateState(blockState, world, pos);
return ActionResult.CONSUME;
}
} else {
return super.onUse(state, world, pos, player, hit);
}
}

@Override
protected boolean emitsRedstonePower(BlockState state) {
return true;
Expand All @@ -81,25 +126,12 @@ public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, Block

private static void tick(World world, BlockPos pos, BlockState state, MoistureDetectorBlockEntity blockEntity) {
if (world.getTime() % 2L == 0L) {
BlockPos check_pos = pos.up();
if (world.getBlockState(check_pos).isOf(Blocks.WATER)) {
getWaterLevel(state, world, pos, world.getFluidState(check_pos));
} else if (world.getBlockState(check_pos).contains(Properties.WATERLOGGED) ? world.getBlockState(check_pos).get(Properties.WATERLOGGED) : false) {
if (state.get(POWER) != 9) {
world.setBlockState(pos, state.with(POWER, 9), Block.NOTIFY_ALL);
}
} else if (world.getBlockState(check_pos).isOf(Blocks.AIR) && world.hasRain(check_pos)) {
getRainLevel(state, world, pos);
} else {
if (state.get(POWER) != 0) {
world.setBlockState(pos, state.with(POWER, 0), Block.NOTIFY_ALL);
}
}
updateState(state, world, pos);
}
}

@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(POWER);
builder.add(POWER, MoistureDetectorBlock.CHECK_LEVEL);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ public static void initBlocks() {
});

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

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.lumiscosity.rounded.mixin;

import com.lumiscosity.rounded.blocks.RegisterBlocks;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.ConduitBlockEntity;
import org.spongepowered.asm.mixin.*;

@Mixin(ConduitBlockEntity.class)
public class ExtraConduitPowerMixin {
@Shadow
@Final
@Mutable
private static Block[] ACTIVATING_BLOCKS;

static {
ACTIVATING_BLOCKS = new Block[]{Blocks.PRISMARINE, Blocks.PRISMARINE_BRICKS, Blocks.SEA_LANTERN, Blocks.DARK_PRISMARINE, RegisterBlocks.CHISELED_PRISMARINE_BRICKS, RegisterBlocks.SMOOTH_PRISMARINE};
}
}
1 change: 1 addition & 0 deletions src/main/resources/rounded.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"package": "com.lumiscosity.rounded.mixin",
"compatibilityLevel": "JAVA_21",
"mixins": [
"ExtraConduitPowerMixin",
"TroughFallCancelMixin"
],
"injectors": {
Expand Down

0 comments on commit 091f3de

Please sign in to comment.