From d7a920247fb73feacffdefd5d2ff38cb31805e03 Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Sun, 9 Jun 2024 17:49:13 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../anvilcraft/block/InductionLightBlock.java | 25 +++++++------ .../entity/InductionLightBlockEntity.java | 36 +++++++++++++++++++ .../anvilcraft/config/AnvilCraftConfig.java | 3 ++ .../assets/anvilcraft/lang/en_ud.json | 1 + .../assets/anvilcraft/lang/en_us.json | 3 +- .../recipes/heating/melt_gem_cauldron.json | 4 +-- .../data/anvilcraft/recipes/zombie.json | 4 +-- .../assets/anvilcraft/lang/en_ud.json | 1 + .../assets/anvilcraft/lang/en_us.json | 1 + .../recipes/heating/melt_gem_cauldron.json | 4 +-- .../data/anvilcraft/recipes/zombie.json | 4 +-- 11 files changed, 66 insertions(+), 20 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java index c34af645a..b5890085a 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java @@ -127,17 +127,20 @@ protected void createBlockStateDefinition(StateDefinition.Builder type, BlockPos pos, BlockState blockState) { super(type, pos, blockState); } @@ -30,6 +38,34 @@ public static InductionLightBlockEntity createBlockEntity( public void tick(Level level1) { flushState(level1, getBlockPos()); + this.cooldown=cooldown>0 ? cooldown-1 : 0; + if (this.cooldown > 0 || + this.getBlockState().getValue(InductionLightBlock.POWERED) || + this.getBlockState().getValue(InductionLightBlock.OVERLOAD)) { + return; + } + boolean done = false; + for (int i = -rangeSize/2; i <= rangeSize/2; i++) { + for (int j = -rangeSize/2; j <= rangeSize/2; j++) { + for (int k = -rangeSize/2; k <= rangeSize/2; k++) { + BlockPos pos = getPos().offset(i, j, k); + BlockState state = level1.getBlockState(pos); + if(state.getBlock() instanceof BonemealableBlock growable && + !growable.getClass().equals(GrassBlock.class) && + !growable.getClass().equals(NyliumBlock.class) + ){ + growable.performBonemeal( + (ServerLevel) level1, + level1.getRandom(), pos, state); + done=true; + } + } + } + } + if(done){ + this.cooldown= AnvilCraft.config.inductionLightBlockRipeningCooldown; + System.out.println("Successfully ripen.Reset counter."); + } } @Override diff --git a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java index d929df988..e69ebc792 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java @@ -112,6 +112,9 @@ public class AnvilCraftConfig implements ConfigData { @ConfigEntry.Gui.Tooltip() public boolean isLaserDoImpactChecking = true; + @ConfigEntry.Gui.Tooltip + public int inductionLightBlockRipeningCooldown = 80; + public static class PowerConverter implements ConfigData { @Comment("The working interval of power converters") @ConfigEntry.Gui.Tooltip diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 6084b1059..6eff68004 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -309,6 +309,7 @@ "text.autoconfig.anvilcraft.option.geodeInterval.@Tooltip": "ǝpoǝb ǝɥʇ ɟo ןɐʌɹǝʇuı ɥɔɹɐǝs ǝɥ⟘", "text.autoconfig.anvilcraft.option.geodeRadius": "snıpɐᴚ ɥɔɹɐǝS ɯnɯıxɐW ǝpoǝ⅁", "text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "ǝpoǝb ǝɥʇ ɟo snıpɐɹ ɥɔɹɐǝs ɯnɯıxɐɯ ǝɥ⟘", + "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "uʍopןooƆ buıuǝdıᴚ ʞɔoןᗺ ʇɥbıꞀ uoıʇɔnpuI", "text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "buıʞɔǝɥƆ ʇɔɐdɯI oᗡ ɹǝsɐꞀ sI", "text.autoconfig.anvilcraft.option.lightningStrikeDepth": "ɥʇdǝᗡ ǝʞıɹʇS buıuʇɥbıꞀ", "text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "ɥɔɐǝɹ uɐɔ ǝʞıɹʇs buıuʇɥbıן ɐ ɥʇdǝp ɯnɯıxɐW", diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json index c2b83f87f..ff3651fef 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -309,6 +309,7 @@ "text.autoconfig.anvilcraft.option.geodeInterval.@Tooltip": "The search interval of the geode", "text.autoconfig.anvilcraft.option.geodeRadius": "Geode Maximum Search Radius", "text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "The maximum search radius of the geode", + "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "Induction Light Block Ripening Cooldown", "text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "Is Laser Do Impact Checking", "text.autoconfig.anvilcraft.option.lightningStrikeDepth": "Lightning Strike Depth", "text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "Maximum depth a lightning strike can reach", @@ -383,4 +384,4 @@ "tooltip.anvilcraft.item.transmission_pole": "Build a power grid with a transmission distance of 8", "tooltip.anvilcraft.jade.power_information": "Power Grid: %d/%d KW", "tooltip.anvilcraft.ruby_prism.power": "Laser level: %d" -} +} \ No newline at end of file diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json b/fabric/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json index 75abfd42d..10bbd9b56 100644 --- a/fabric/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json @@ -54,10 +54,10 @@ "min": 1 }, "items": [ + "minecraft:emerald_block", "anvilcraft:sapphire_block", - "anvilcraft:topaz_block", "anvilcraft:ruby_block", - "minecraft:emerald_block" + "anvilcraft:topaz_block" ] }, "offset": [ diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json b/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json index 47781098d..019a4d6b3 100644 --- a/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json @@ -17,7 +17,7 @@ } ], "transformOptions": [ - "replaceAnvil", - "keepInventory" + "keepInventory", + "replaceAnvil" ] } \ No newline at end of file diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 6084b1059..6eff68004 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -309,6 +309,7 @@ "text.autoconfig.anvilcraft.option.geodeInterval.@Tooltip": "ǝpoǝb ǝɥʇ ɟo ןɐʌɹǝʇuı ɥɔɹɐǝs ǝɥ⟘", "text.autoconfig.anvilcraft.option.geodeRadius": "snıpɐᴚ ɥɔɹɐǝS ɯnɯıxɐW ǝpoǝ⅁", "text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "ǝpoǝb ǝɥʇ ɟo snıpɐɹ ɥɔɹɐǝs ɯnɯıxɐɯ ǝɥ⟘", + "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "uʍopןooƆ buıuǝdıᴚ ʞɔoןᗺ ʇɥbıꞀ uoıʇɔnpuI", "text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "buıʞɔǝɥƆ ʇɔɐdɯI oᗡ ɹǝsɐꞀ sI", "text.autoconfig.anvilcraft.option.lightningStrikeDepth": "ɥʇdǝᗡ ǝʞıɹʇS buıuʇɥbıꞀ", "text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "ɥɔɐǝɹ uɐɔ ǝʞıɹʇs buıuʇɥbıן ɐ ɥʇdǝp ɯnɯıxɐW", diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json index 60bedc5f2..ff3651fef 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -309,6 +309,7 @@ "text.autoconfig.anvilcraft.option.geodeInterval.@Tooltip": "The search interval of the geode", "text.autoconfig.anvilcraft.option.geodeRadius": "Geode Maximum Search Radius", "text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "The maximum search radius of the geode", + "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "Induction Light Block Ripening Cooldown", "text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "Is Laser Do Impact Checking", "text.autoconfig.anvilcraft.option.lightningStrikeDepth": "Lightning Strike Depth", "text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "Maximum depth a lightning strike can reach", diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json b/forge/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json index 75abfd42d..10bbd9b56 100644 --- a/forge/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json +++ b/forge/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json @@ -54,10 +54,10 @@ "min": 1 }, "items": [ + "minecraft:emerald_block", "anvilcraft:sapphire_block", - "anvilcraft:topaz_block", "anvilcraft:ruby_block", - "minecraft:emerald_block" + "anvilcraft:topaz_block" ] }, "offset": [ diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json b/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json index 47781098d..019a4d6b3 100644 --- a/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json +++ b/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json @@ -17,7 +17,7 @@ } ], "transformOptions": [ - "replaceAnvil", - "keepInventory" + "keepInventory", + "replaceAnvil" ] } \ No newline at end of file From b47ac3ff72d153da9f53e718b702ce6a171206f5 Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Sun, 9 Jun 2024 19:51:54 +0800 Subject: [PATCH 02/11] Code Style --- .../anvilcraft/block/InductionLightBlock.java | 2 +- .../entity/InductionLightBlockEntity.java | 26 +++++++++---------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java index b5890085a..63856df92 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java @@ -127,7 +127,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder0 ? cooldown-1 : 0; - if (this.cooldown > 0 || - this.getBlockState().getValue(InductionLightBlock.POWERED) || - this.getBlockState().getValue(InductionLightBlock.OVERLOAD)) { + this.cooldown = cooldown > 0 ? cooldown - 1 : 0; + if (this.cooldown > 0 + || this.getBlockState().getValue(InductionLightBlock.POWERED) + || this.getBlockState().getValue(InductionLightBlock.OVERLOAD)) { return; } boolean done = false; - for (int i = -rangeSize/2; i <= rangeSize/2; i++) { - for (int j = -rangeSize/2; j <= rangeSize/2; j++) { - for (int k = -rangeSize/2; k <= rangeSize/2; k++) { + for (int i = -rangeSize / 2; i <= rangeSize / 2; i++) { + for (int j = -rangeSize / 2; j <= rangeSize / 2; j++) { + for (int k = -rangeSize / 2; k <= rangeSize / 2; k++) { BlockPos pos = getPos().offset(i, j, k); BlockState state = level1.getBlockState(pos); - if(state.getBlock() instanceof BonemealableBlock growable && - !growable.getClass().equals(GrassBlock.class) && - !growable.getClass().equals(NyliumBlock.class) - ){ + if(state.getBlock() instanceof BonemealableBlock growable + && !growable.getClass().equals(GrassBlock.class) + && !growable.getClass().equals(NyliumBlock.class) + ) { growable.performBonemeal( (ServerLevel) level1, level1.getRandom(), pos, state); @@ -62,8 +62,8 @@ public void tick(Level level1) { } } } - if(done){ - this.cooldown= AnvilCraft.config.inductionLightBlockRipeningCooldown; + if (done) { + this.cooldown=AnvilCraft.config.inductionLightBlockRipeningCooldown; System.out.println("Successfully ripen.Reset counter."); } } From 3170babe7ccf9e0532cd6e8fca866c85da520066 Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Sun, 9 Jun 2024 19:56:49 +0800 Subject: [PATCH 03/11] Code Style --- .../anvilcraft/block/entity/InductionLightBlockEntity.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java index 82220cec5..1ed7388f5 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java @@ -57,14 +57,13 @@ public void tick(Level level1) { growable.performBonemeal( (ServerLevel) level1, level1.getRandom(), pos, state); - done=true; + done = true; } } } } if (done) { - this.cooldown=AnvilCraft.config.inductionLightBlockRipeningCooldown; - System.out.println("Successfully ripen.Reset counter."); + this.cooldown = AnvilCraft.config.inductionLightBlockRipeningCooldown; } } From 8ec87e8e3f1a3cef3228c7299a83a489cf8221ea Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Thu, 20 Jun 2024 20:35:34 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=88=9D=E6=AD=A5?= =?UTF-8?q?=E9=87=8D=E5=86=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/api/BonemealManager.java | 10 ++++ .../anvilcraft/block/InductionLightBlock.java | 60 ++++++++++++++----- 2 files changed, 56 insertions(+), 14 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java new file mode 100644 index 000000000..0f20cb008 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java @@ -0,0 +1,10 @@ +package dev.dubhe.anvilcraft.api; + +import net.minecraft.core.BlockPos; + +import java.util.HashSet; + +public class BonemealManager { + public static final HashSet bonemealBlocks = new HashSet<>(); + protected int cooldown = 0; +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java index 63856df92..2feeae56b 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java @@ -13,11 +13,14 @@ import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.Block; +import net.minecraft.world.item.Items; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.SimpleWaterloggedBlock; import net.minecraft.world.level.block.entity.BlockEntity; @@ -40,14 +43,33 @@ public class InductionLightBlock extends BaseEntityBlock implements IHammerRemovable, SimpleWaterloggedBlock { + + + public record ColorType(String name){ + public static final ColorType PRIMARY; + public static final ColorType PINK; + public static final ColorType YELLOW; + public static final ColorType DARK; + + static { + PRIMARY = new ColorType("PRIMARY"); + PINK = new ColorType("PINK"); + YELLOW = new ColorType("YELLOW"); + DARK = new ColorType("DARK"); + } + } + public static final VoxelShape SHAPE_X = Block.box(0, 6, 6, 16, 10, 10); public static final VoxelShape SHAPE_Y = Block.box(6, 0, 6, 10, 16, 10); public static final VoxelShape SHAPE_Z = Block.box(6, 6, 0, 10, 10, 16); + + public static final BooleanProperty POWERED = BlockStateProperties.POWERED; public static final BooleanProperty OVERLOAD = IPowerComponent.OVERLOAD; public static final EnumProperty AXIS = BlockStateProperties.AXIS; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; + public static ColorType COLOR = ColorType.PRIMARY; /** * @@ -127,20 +149,29 @@ protected void createBlockStateDefinition(StateDefinition.Builder Date: Fri, 21 Jun 2024 18:12:24 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E7=94=B5=E7=81=AF=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E4=BA=A4=E4=BA=92+=E9=83=A8=E5=88=86=E5=82=AC=E7=86=9F?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/api/BonemealManager.java | 93 ++++++++++++++++++- .../anvilcraft/block/InductionLightBlock.java | 36 +++---- .../entity/InductionLightBlockEntity.java | 35 ++----- .../anvilcraft/block/state/LightColor.java | 24 +++++ .../anvilcraft/config/AnvilCraftConfig.java | 4 + .../fabric/ServerLifecycleEventListener.java | 2 + .../forge/ServerLifecycleEventListener.java | 2 + 7 files changed, 145 insertions(+), 51 deletions(-) create mode 100644 common/src/main/java/dev/dubhe/anvilcraft/block/state/LightColor.java diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java index 0f20cb008..6adcddab0 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java @@ -1,10 +1,99 @@ package dev.dubhe.anvilcraft.api; +import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.block.InductionLightBlock; +import dev.dubhe.anvilcraft.block.state.LightColor; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; +import net.minecraft.util.Tuple; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.BonemealableBlock; +import net.minecraft.world.level.block.GrassBlock; +import net.minecraft.world.level.block.NyliumBlock; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.HashSet; +import java.util.Set; + public class BonemealManager { - public static final HashSet bonemealBlocks = new HashSet<>(); - protected int cooldown = 0; + private static int cooldown = 0; + private static final Set> lightBlocks = Collections.synchronizedSet(new HashSet<>()); + + private static boolean isLighting(@NotNull BlockState state) { + return state.getValue(InductionLightBlock.POWERED) + || state.getValue(InductionLightBlock.OVERLOAD); + } + + private static boolean canCropGrow(@NotNull BlockState state) { + return state.getValue(InductionLightBlock.COLOR).equals(LightColor.PINK); + } + + private static HashSet> doRipen( + @NotNull Level level, @NotNull BlockPos pos, @NotNull HashSet> set) { + int rangeSize = AnvilCraft.config.inductionLightBlockRipeningRange; + HashSet> ripened = new HashSet<>(); + for (int i = -rangeSize / 2; i <= rangeSize / 2; i++) { + for (int j = -rangeSize / 2; j <= rangeSize / 2; j++) { + for (int k = -rangeSize / 2; k <= rangeSize / 2; k++) { + BlockPos pos1 = pos.offset(i, j, k); + BlockState state = level.getBlockState(pos1); + if (state.getBlock() instanceof BonemealableBlock growable + && !growable.getClass().equals(GrassBlock.class) + && !growable.getClass().equals(NyliumBlock.class) + && !set.contains(new Tuple<>(pos1, level)) + ) { + growable.performBonemeal( + (ServerLevel) level, + level.getRandom(), pos1, state); + ripened.add(new Tuple<>(pos1, level)); + } + } + } + } + return ripened; + } + + /** + * + */ + public static void tick() { + cooldown--; + if (cooldown <= 0 && !lightBlocks.isEmpty()) { + cooldown = AnvilCraft.config.inductionLightBlockRipeningCooldown; + HashSet> ripenedBlocks = new HashSet<>(); + for (Tuple lightBlock : lightBlocks) { + BlockState lightBlockState = lightBlock.getB().getBlockState(lightBlock.getA()); + if (lightBlockState.getBlock() instanceof InductionLightBlock) { + if (isLighting(lightBlockState) && canCropGrow(lightBlockState)) { + HashSet> newRipened = + doRipen(lightBlock.getB(), lightBlock.getA(), ripenedBlocks); + ripenedBlocks.addAll(newRipened); + } else { + lightBlocks.remove(lightBlock); + } + } else { + lightBlocks.remove(lightBlock); + } + } + System.out.println(lightBlocks.size()); + System.out.println(ripenedBlocks.size()); + } + } + + /** + * + */ + public static void addLightBlock(BlockPos pos, Level level) { + if (!lightBlocks.contains(new Tuple<>(pos, level))) { + lightBlocks.add(new Tuple<>(pos, level)); + System.out.println(pos + " at " + level + " size:" + lightBlocks.size()); + } + } + + public static void removeLightBlock(BlockPos pos, Level level) { + lightBlocks.remove(new Tuple<>(pos, level)); + } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java index 2feeae56b..815e72dca 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java @@ -1,19 +1,21 @@ package dev.dubhe.anvilcraft.block; import dev.dubhe.anvilcraft.api.BlockPlaceAssist; +import dev.dubhe.anvilcraft.api.BonemealManager; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.api.power.IPowerComponent; import dev.dubhe.anvilcraft.block.entity.InductionLightBlockEntity; +import dev.dubhe.anvilcraft.block.state.Color; import dev.dubhe.anvilcraft.init.ModBlockEntities; import dev.dubhe.anvilcraft.init.ModBlocks; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; +import net.minecraft.tags.ItemTags; import net.minecraft.util.RandomSource; import net.minecraft.world.InteractionHand; import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.player.Player; -import net.minecraft.world.item.Item; import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.context.BlockPlaceContext; import net.minecraft.world.level.BlockGetter; @@ -38,27 +40,12 @@ import net.minecraft.world.phys.shapes.VoxelShape; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import dev.dubhe.anvilcraft.block.state.LightColor; import javax.annotation.Nonnull; public class InductionLightBlock extends BaseEntityBlock implements IHammerRemovable, SimpleWaterloggedBlock { - - - public record ColorType(String name){ - public static final ColorType PRIMARY; - public static final ColorType PINK; - public static final ColorType YELLOW; - public static final ColorType DARK; - - static { - PRIMARY = new ColorType("PRIMARY"); - PINK = new ColorType("PINK"); - YELLOW = new ColorType("YELLOW"); - DARK = new ColorType("DARK"); - } - } - public static final VoxelShape SHAPE_X = Block.box(0, 6, 6, 16, 10, 10); public static final VoxelShape SHAPE_Y = Block.box(6, 0, 6, 10, 16, 10); public static final VoxelShape SHAPE_Z = Block.box(6, 6, 0, 10, 10, 16); @@ -69,7 +56,7 @@ public record ColorType(String name){ public static final BooleanProperty OVERLOAD = IPowerComponent.OVERLOAD; public static final EnumProperty AXIS = BlockStateProperties.AXIS; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - public static ColorType COLOR = ColorType.PRIMARY; + public static final EnumProperty COLOR = EnumProperty.create("color", LightColor.class); /** * @@ -81,6 +68,7 @@ public InductionLightBlock(Properties properties) { .setValue(OVERLOAD, true) .setValue(AXIS, Direction.Axis.Y) .setValue(WATERLOGGED, false) + .setValue(COLOR, LightColor.PRIMARY) ); } @@ -119,7 +107,8 @@ public BlockState getStateForPlacement(@NotNull BlockPlaceContext context) { .setValue( WATERLOGGED, context.getLevel().getFluidState(context.getClickedPos()).getType() == Fluids.WATER - ); + ) + .setValue(COLOR, LightColor.PRIMARY); } @Nullable @@ -135,7 +124,7 @@ public FluidState getFluidState(BlockState state) { @Override protected void createBlockStateDefinition(StateDefinition.Builder builder) { - builder.add(POWERED).add(OVERLOAD).add(AXIS).add(WATERLOGGED); + builder.add(POWERED).add(OVERLOAD).add(AXIS).add(WATERLOGGED).add(COLOR); } @@ -166,10 +155,15 @@ protected void createBlockStateDefinition(StateDefinition.Builder item.broadcastBreakEvent(hand)); + return InteractionResult.CONSUME_PARTIAL; } return InteractionResult.PASS; } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java index 1ed7388f5..a83ba3bf3 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java @@ -1,9 +1,11 @@ package dev.dubhe.anvilcraft.block.entity; import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.api.BonemealManager; import dev.dubhe.anvilcraft.api.power.IPowerConsumer; import dev.dubhe.anvilcraft.api.power.PowerGrid; import dev.dubhe.anvilcraft.block.InductionLightBlock; +import dev.dubhe.anvilcraft.block.state.LightColor; import net.minecraft.world.level.block.NyliumBlock; import lombok.Getter; import lombok.Setter; @@ -23,8 +25,8 @@ public class InductionLightBlockEntity extends BlockEntity implements IPowerCons private PowerGrid grid; - private int cooldown = 0; private int rangeSize = 5; + private boolean registered = false; public InductionLightBlockEntity(BlockEntityType type, BlockPos pos, BlockState blockState) { super(type, pos, blockState); @@ -38,39 +40,16 @@ public static InductionLightBlockEntity createBlockEntity( public void tick(Level level1) { flushState(level1, getBlockPos()); - this.cooldown = cooldown > 0 ? cooldown - 1 : 0; - if (this.cooldown > 0 - || this.getBlockState().getValue(InductionLightBlock.POWERED) - || this.getBlockState().getValue(InductionLightBlock.OVERLOAD)) { - return; - } - boolean done = false; - for (int i = -rangeSize / 2; i <= rangeSize / 2; i++) { - for (int j = -rangeSize / 2; j <= rangeSize / 2; j++) { - for (int k = -rangeSize / 2; k <= rangeSize / 2; k++) { - BlockPos pos = getPos().offset(i, j, k); - BlockState state = level1.getBlockState(pos); - if(state.getBlock() instanceof BonemealableBlock growable - && !growable.getClass().equals(GrassBlock.class) - && !growable.getClass().equals(NyliumBlock.class) - ) { - growable.performBonemeal( - (ServerLevel) level1, - level1.getRandom(), pos, state); - done = true; - } - } - } - } - if (done) { - this.cooldown = AnvilCraft.config.inductionLightBlockRipeningCooldown; + if(!registered) { + registered = true; + BonemealManager.addLightBlock(getPos(), level); } } @Override public int getInputPower() { if (level == null) return 1; - return getBlockState().getValue(InductionLightBlock.POWERED) ? 0 : 1; + return getBlockState().getValue(InductionLightBlock.POWERED) ? 0 : getBlockState().getValue(InductionLightBlock.COLOR).dissipation; } @Override diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/state/LightColor.java b/common/src/main/java/dev/dubhe/anvilcraft/block/state/LightColor.java new file mode 100644 index 000000000..67bdfeb84 --- /dev/null +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/state/LightColor.java @@ -0,0 +1,24 @@ +package dev.dubhe.anvilcraft.block.state; + +import net.minecraft.util.StringRepresentable; +import org.jetbrains.annotations.NotNull; + +public enum LightColor implements StringRepresentable { + PRIMARY("primary",1), + PINK("pink",16), + DARK("dark",16), + YELLOW("yellow",16) + ; + + public final String name; + public final int dissipation; + LightColor(String name, int dissipation) { + this.name=name; + this.dissipation=dissipation; + } + + @Override + public @NotNull String getSerializedName() { + return this.name; + } +} diff --git a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java index e69ebc792..417c2ce4b 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java @@ -115,6 +115,10 @@ public class AnvilCraftConfig implements ConfigData { @ConfigEntry.Gui.Tooltip public int inductionLightBlockRipeningCooldown = 80; + @ConfigEntry.Gui.Tooltip + @ConfigEntry.BoundedDiscrete(min = 0, max = 100) + public int inductionLightBlockRipeningRange = 5; + public static class PowerConverter implements ConfigData { @Comment("The working interval of power converters") @ConfigEntry.Gui.Tooltip diff --git a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEventListener.java b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEventListener.java index cfb35e8bd..cb9d65ee8 100644 --- a/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEventListener.java +++ b/fabric/src/main/java/dev/dubhe/anvilcraft/event/fabric/ServerLifecycleEventListener.java @@ -1,6 +1,7 @@ package dev.dubhe.anvilcraft.event.fabric; import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.api.BonemealManager; import dev.dubhe.anvilcraft.api.chargecollector.ThermoManager; import dev.dubhe.anvilcraft.api.event.server.ServerEndDataPackReloadEvent; import dev.dubhe.anvilcraft.api.event.server.ServerStartedEvent; @@ -38,6 +39,7 @@ private static void endDataPackReload( private static void startTick(MinecraftServer server) { PowerGrid.tickGrid(); ThermoManager.tick(); + BonemealManager.tick(); RandomChuckTickLoadManager.tick(); } diff --git a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEventListener.java b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEventListener.java index 5e3aac8c2..0849e9f1e 100644 --- a/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEventListener.java +++ b/forge/src/main/java/dev/dubhe/anvilcraft/event/forge/ServerLifecycleEventListener.java @@ -1,6 +1,7 @@ package dev.dubhe.anvilcraft.event.forge; import dev.dubhe.anvilcraft.AnvilCraft; +import dev.dubhe.anvilcraft.api.BonemealManager; import dev.dubhe.anvilcraft.api.chargecollector.ThermoManager; import dev.dubhe.anvilcraft.api.event.forge.DataPackReloadedEvent; import dev.dubhe.anvilcraft.api.event.server.ServerEndDataPackReloadEvent; @@ -43,6 +44,7 @@ public static void onDataPackReloaded(@NotNull DataPackReloadedEvent event) { public static void onTick(@NotNull TickEvent.ServerTickEvent event) { if (event.phase != TickEvent.Phase.START) return; PowerGrid.tickGrid(); + BonemealManager.tick(); ThermoManager.tick(); RandomChuckTickLoadManager.tick(); } From 89033d5737bfae1ba6e6c5e53e2da35f3e5d55bf Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:39:51 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dubhe/anvilcraft/api/BonemealManager.java | 47 ++++++++++++------- .../assets/anvilcraft/lang/en_ud.json | 1 + .../assets/anvilcraft/lang/en_us.json | 1 + .../recipes/heating/melt_gem_cauldron.json | 6 +-- .../data/anvilcraft/recipes/zombie.json | 4 +- .../assets/anvilcraft/lang/en_ud.json | 1 + .../assets/anvilcraft/lang/en_us.json | 1 + .../recipes/heating/melt_gem_cauldron.json | 6 +-- .../data/anvilcraft/recipes/zombie.json | 4 +- 9 files changed, 43 insertions(+), 28 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java index 6adcddab0..af09f6e76 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java @@ -4,33 +4,47 @@ import dev.dubhe.anvilcraft.block.InductionLightBlock; import dev.dubhe.anvilcraft.block.state.LightColor; import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleTypes; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Tuple; import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.GrassBlock; import net.minecraft.world.level.block.NyliumBlock; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; +import java.util.*; public class BonemealManager { private static int cooldown = 0; - private static final Set> lightBlocks = Collections.synchronizedSet(new HashSet<>()); + private static Set> lightBlocks = Collections.synchronizedSet(new HashSet<>()); private static boolean isLighting(@NotNull BlockState state) { - return state.getValue(InductionLightBlock.POWERED) - || state.getValue(InductionLightBlock.OVERLOAD); + return !(state.getValue(InductionLightBlock.POWERED) + || state.getValue(InductionLightBlock.OVERLOAD)); } private static boolean canCropGrow(@NotNull BlockState state) { return state.getValue(InductionLightBlock.COLOR).equals(LightColor.PINK); } + private static boolean isInSet(HashSet> set, Tuple item) { + Iterator> it = set.iterator(); + while (it.hasNext()){ + Tuple cur = it.next(); + if( cur.getA().getX()==item.getA().getX() + && cur.getA().getY()==item.getA().getY() + && cur.getA().getZ()==item.getA().getZ() + && cur.getB().dimension()==item.getB().dimension()){ + return true; + } + } + return false; + } + private static HashSet> doRipen( @NotNull Level level, @NotNull BlockPos pos, @NotNull HashSet> set) { int rangeSize = AnvilCraft.config.inductionLightBlockRipeningRange; @@ -43,11 +57,13 @@ private static HashSet> doRipen( if (state.getBlock() instanceof BonemealableBlock growable && !growable.getClass().equals(GrassBlock.class) && !growable.getClass().equals(NyliumBlock.class) - && !set.contains(new Tuple<>(pos1, level)) + && !isInSet(set,new Tuple<>(pos1, level)) + && growable.isValidBonemealTarget(level, pos1, state, false) ) { growable.performBonemeal( (ServerLevel) level, level.getRandom(), pos1, state); + level.addParticle(ParticleTypes.HAPPY_VILLAGER,pos1.getX()+0.5,pos1.getY()+0.5,pos1.getZ()+0.5,0.0,0.0,0.0); ripened.add(new Tuple<>(pos1, level)); } } @@ -61,26 +77,26 @@ private static HashSet> doRipen( */ public static void tick() { cooldown--; + if (cooldown <= 0 && !lightBlocks.isEmpty()) { cooldown = AnvilCraft.config.inductionLightBlockRipeningCooldown; HashSet> ripenedBlocks = new HashSet<>(); - for (Tuple lightBlock : lightBlocks) { + Iterator> it=lightBlocks.iterator(); + while (it.hasNext()) { + Tuple lightBlock= (Tuple) it.next(); BlockState lightBlockState = lightBlock.getB().getBlockState(lightBlock.getA()); if (lightBlockState.getBlock() instanceof InductionLightBlock) { if (isLighting(lightBlockState) && canCropGrow(lightBlockState)) { HashSet> newRipened = doRipen(lightBlock.getB(), lightBlock.getA(), ripenedBlocks); ripenedBlocks.addAll(newRipened); - } else { - lightBlocks.remove(lightBlock); } } else { - lightBlocks.remove(lightBlock); + it.remove(); } } - System.out.println(lightBlocks.size()); - System.out.println(ripenedBlocks.size()); } + } /** @@ -89,11 +105,6 @@ public static void tick() { public static void addLightBlock(BlockPos pos, Level level) { if (!lightBlocks.contains(new Tuple<>(pos, level))) { lightBlocks.add(new Tuple<>(pos, level)); - System.out.println(pos + " at " + level + " size:" + lightBlocks.size()); } } - - public static void removeLightBlock(BlockPos pos, Level level) { - lightBlocks.remove(new Tuple<>(pos, level)); - } } diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 6eff68004..d8b31ea8d 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -310,6 +310,7 @@ "text.autoconfig.anvilcraft.option.geodeRadius": "snıpɐᴚ ɥɔɹɐǝS ɯnɯıxɐW ǝpoǝ⅁", "text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "ǝpoǝb ǝɥʇ ɟo snıpɐɹ ɥɔɹɐǝs ɯnɯıxɐɯ ǝɥ⟘", "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "uʍopןooƆ buıuǝdıᴚ ʞɔoןᗺ ʇɥbıꞀ uoıʇɔnpuI", + "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningRange": "ǝbuɐᴚ buıuǝdıᴚ ʞɔoןᗺ ʇɥbıꞀ uoıʇɔnpuI", "text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "buıʞɔǝɥƆ ʇɔɐdɯI oᗡ ɹǝsɐꞀ sI", "text.autoconfig.anvilcraft.option.lightningStrikeDepth": "ɥʇdǝᗡ ǝʞıɹʇS buıuʇɥbıꞀ", "text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "ɥɔɐǝɹ uɐɔ ǝʞıɹʇs buıuʇɥbıן ɐ ɥʇdǝp ɯnɯıxɐW", diff --git a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json index ff3651fef..3ab171c1d 100644 --- a/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/fabric/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -310,6 +310,7 @@ "text.autoconfig.anvilcraft.option.geodeRadius": "Geode Maximum Search Radius", "text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "The maximum search radius of the geode", "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "Induction Light Block Ripening Cooldown", + "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningRange": "Induction Light Block Ripening Range", "text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "Is Laser Do Impact Checking", "text.autoconfig.anvilcraft.option.lightningStrikeDepth": "Lightning Strike Depth", "text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "Maximum depth a lightning strike can reach", diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json b/fabric/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json index 10bbd9b56..d98103b07 100644 --- a/fabric/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json @@ -54,10 +54,10 @@ "min": 1 }, "items": [ - "minecraft:emerald_block", + "anvilcraft:topaz_block", "anvilcraft:sapphire_block", - "anvilcraft:ruby_block", - "anvilcraft:topaz_block" + "minecraft:emerald_block", + "anvilcraft:ruby_block" ] }, "offset": [ diff --git a/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json b/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json index 019a4d6b3..47781098d 100644 --- a/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json +++ b/fabric/src/generated/resources/data/anvilcraft/recipes/zombie.json @@ -17,7 +17,7 @@ } ], "transformOptions": [ - "keepInventory", - "replaceAnvil" + "replaceAnvil", + "keepInventory" ] } \ No newline at end of file diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json index 6eff68004..d8b31ea8d 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_ud.json @@ -310,6 +310,7 @@ "text.autoconfig.anvilcraft.option.geodeRadius": "snıpɐᴚ ɥɔɹɐǝS ɯnɯıxɐW ǝpoǝ⅁", "text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "ǝpoǝb ǝɥʇ ɟo snıpɐɹ ɥɔɹɐǝs ɯnɯıxɐɯ ǝɥ⟘", "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "uʍopןooƆ buıuǝdıᴚ ʞɔoןᗺ ʇɥbıꞀ uoıʇɔnpuI", + "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningRange": "ǝbuɐᴚ buıuǝdıᴚ ʞɔoןᗺ ʇɥbıꞀ uoıʇɔnpuI", "text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "buıʞɔǝɥƆ ʇɔɐdɯI oᗡ ɹǝsɐꞀ sI", "text.autoconfig.anvilcraft.option.lightningStrikeDepth": "ɥʇdǝᗡ ǝʞıɹʇS buıuʇɥbıꞀ", "text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "ɥɔɐǝɹ uɐɔ ǝʞıɹʇs buıuʇɥbıן ɐ ɥʇdǝp ɯnɯıxɐW", diff --git a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json index ff3651fef..3ab171c1d 100644 --- a/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json +++ b/forge/src/generated/resources/assets/anvilcraft/lang/en_us.json @@ -310,6 +310,7 @@ "text.autoconfig.anvilcraft.option.geodeRadius": "Geode Maximum Search Radius", "text.autoconfig.anvilcraft.option.geodeRadius.@Tooltip": "The maximum search radius of the geode", "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningCooldown": "Induction Light Block Ripening Cooldown", + "text.autoconfig.anvilcraft.option.inductionLightBlockRipeningRange": "Induction Light Block Ripening Range", "text.autoconfig.anvilcraft.option.isLaserDoImpactChecking": "Is Laser Do Impact Checking", "text.autoconfig.anvilcraft.option.lightningStrikeDepth": "Lightning Strike Depth", "text.autoconfig.anvilcraft.option.lightningStrikeDepth.@Tooltip": "Maximum depth a lightning strike can reach", diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json b/forge/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json index 10bbd9b56..d98103b07 100644 --- a/forge/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json +++ b/forge/src/generated/resources/data/anvilcraft/recipes/heating/melt_gem_cauldron.json @@ -54,10 +54,10 @@ "min": 1 }, "items": [ - "minecraft:emerald_block", + "anvilcraft:topaz_block", "anvilcraft:sapphire_block", - "anvilcraft:ruby_block", - "anvilcraft:topaz_block" + "minecraft:emerald_block", + "anvilcraft:ruby_block" ] }, "offset": [ diff --git a/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json b/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json index 019a4d6b3..47781098d 100644 --- a/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json +++ b/forge/src/generated/resources/data/anvilcraft/recipes/zombie.json @@ -17,7 +17,7 @@ } ], "transformOptions": [ - "keepInventory", - "replaceAnvil" + "replaceAnvil", + "keepInventory" ] } \ No newline at end of file From 3249d4c6d3573552b6843ed6d48cd8760f59911a Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Fri, 21 Jun 2024 21:59:09 +0800 Subject: [PATCH 07/11] Code Style --- .../dubhe/anvilcraft/api/BonemealManager.java | 47 +++++++++++++------ .../anvilcraft/block/InductionLightBlock.java | 19 ++++---- .../entity/InductionLightBlockEntity.java | 12 ++--- .../anvilcraft/block/state/LightColor.java | 13 ++--- 4 files changed, 53 insertions(+), 38 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java index af09f6e76..1670981b8 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java @@ -8,19 +8,21 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Tuple; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.Block; import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.GrassBlock; import net.minecraft.world.level.block.NyliumBlock; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; -import java.util.*; +import java.util.Collections; +import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; public class BonemealManager { private static int cooldown = 0; - private static Set> lightBlocks = Collections.synchronizedSet(new HashSet<>()); + private static final Set> lightBlocks = Collections.synchronizedSet(new HashSet<>()); private static boolean isLighting(@NotNull BlockState state) { return !(state.getValue(InductionLightBlock.POWERED) @@ -32,13 +34,23 @@ private static boolean canCropGrow(@NotNull BlockState state) { } private static boolean isInSet(HashSet> set, Tuple item) { - Iterator> it = set.iterator(); - while (it.hasNext()){ - Tuple cur = it.next(); - if( cur.getA().getX()==item.getA().getX() - && cur.getA().getY()==item.getA().getY() - && cur.getA().getZ()==item.getA().getZ() - && cur.getB().dimension()==item.getB().dimension()){ + for (Tuple cur : set) { + if (cur.getA().getX() == item.getA().getX() + && cur.getA().getY() == item.getA().getY() + && cur.getA().getZ() == item.getA().getZ() + && cur.getB().dimension() == item.getB().dimension()) { + return true; + } + } + return false; + } + + private static boolean isInSet(Tuple item) { + for (Tuple cur : BonemealManager.lightBlocks) { + if (cur.getA().getX() == item.getA().getX() + && cur.getA().getY() == item.getA().getY() + && cur.getA().getZ() == item.getA().getZ() + && cur.getB().dimension() == item.getB().dimension()) { return true; } } @@ -57,13 +69,18 @@ private static HashSet> doRipen( if (state.getBlock() instanceof BonemealableBlock growable && !growable.getClass().equals(GrassBlock.class) && !growable.getClass().equals(NyliumBlock.class) - && !isInSet(set,new Tuple<>(pos1, level)) + && !isInSet(set, new Tuple<>(pos1, level)) && growable.isValidBonemealTarget(level, pos1, state, false) ) { growable.performBonemeal( (ServerLevel) level, level.getRandom(), pos1, state); - level.addParticle(ParticleTypes.HAPPY_VILLAGER,pos1.getX()+0.5,pos1.getY()+0.5,pos1.getZ()+0.5,0.0,0.0,0.0); + level.addParticle( + ParticleTypes.HAPPY_VILLAGER, + pos1.getX() + 0.5, + pos1.getY() + 0.5, + pos1.getZ() + 0.5, + 0.0, 0.0, 0.0); ripened.add(new Tuple<>(pos1, level)); } } @@ -81,9 +98,9 @@ public static void tick() { if (cooldown <= 0 && !lightBlocks.isEmpty()) { cooldown = AnvilCraft.config.inductionLightBlockRipeningCooldown; HashSet> ripenedBlocks = new HashSet<>(); - Iterator> it=lightBlocks.iterator(); + Iterator> it = lightBlocks.iterator(); while (it.hasNext()) { - Tuple lightBlock= (Tuple) it.next(); + Tuple lightBlock = it.next(); BlockState lightBlockState = lightBlock.getB().getBlockState(lightBlock.getA()); if (lightBlockState.getBlock() instanceof InductionLightBlock) { if (isLighting(lightBlockState) && canCropGrow(lightBlockState)) { @@ -103,7 +120,7 @@ public static void tick() { * */ public static void addLightBlock(BlockPos pos, Level level) { - if (!lightBlocks.contains(new Tuple<>(pos, level))) { + if (isInSet(new Tuple<>(pos, level))) { lightBlocks.add(new Tuple<>(pos, level)); } } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java index 815e72dca..a16f78dcf 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java @@ -1,11 +1,9 @@ package dev.dubhe.anvilcraft.block; import dev.dubhe.anvilcraft.api.BlockPlaceAssist; -import dev.dubhe.anvilcraft.api.BonemealManager; import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable; import dev.dubhe.anvilcraft.api.power.IPowerComponent; import dev.dubhe.anvilcraft.block.entity.InductionLightBlockEntity; -import dev.dubhe.anvilcraft.block.state.Color; import dev.dubhe.anvilcraft.init.ModBlockEntities; import dev.dubhe.anvilcraft.init.ModBlocks; import net.minecraft.core.BlockPos; @@ -78,7 +76,8 @@ public InductionLightBlock(Properties properties) { } @Override - public VoxelShape getShape( + @SuppressWarnings("deprecation") + public @NotNull VoxelShape getShape( @NotNull BlockState state, @NotNull BlockGetter level, @NotNull BlockPos pos, @@ -118,7 +117,8 @@ public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState sta } @Override - public FluidState getFluidState(BlockState state) { + @SuppressWarnings("deprecation") + public @NotNull FluidState getFluidState(BlockState state) { return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } @@ -130,6 +130,7 @@ protected void createBlockStateDefinition(StateDefinition.Builder item.broadcastBreakEvent(hand)); return InteractionResult.CONSUME_PARTIAL; } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java index a83ba3bf3..6ab3f8c9d 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/InductionLightBlockEntity.java @@ -1,19 +1,13 @@ package dev.dubhe.anvilcraft.block.entity; -import dev.dubhe.anvilcraft.AnvilCraft; import dev.dubhe.anvilcraft.api.BonemealManager; import dev.dubhe.anvilcraft.api.power.IPowerConsumer; import dev.dubhe.anvilcraft.api.power.PowerGrid; import dev.dubhe.anvilcraft.block.InductionLightBlock; -import dev.dubhe.anvilcraft.block.state.LightColor; -import net.minecraft.world.level.block.NyliumBlock; import lombok.Getter; import lombok.Setter; import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.BonemealableBlock; -import net.minecraft.world.level.block.GrassBlock; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; @@ -40,7 +34,7 @@ public static InductionLightBlockEntity createBlockEntity( public void tick(Level level1) { flushState(level1, getBlockPos()); - if(!registered) { + if (!registered) { registered = true; BonemealManager.addLightBlock(getPos(), level); } @@ -49,7 +43,9 @@ public void tick(Level level1) { @Override public int getInputPower() { if (level == null) return 1; - return getBlockState().getValue(InductionLightBlock.POWERED) ? 0 : getBlockState().getValue(InductionLightBlock.COLOR).dissipation; + return getBlockState() + .getValue(InductionLightBlock.POWERED) + ? 0 : getBlockState().getValue(InductionLightBlock.COLOR).dissipation; } @Override diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/state/LightColor.java b/common/src/main/java/dev/dubhe/anvilcraft/block/state/LightColor.java index 67bdfeb84..d07415ce1 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/state/LightColor.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/state/LightColor.java @@ -4,17 +4,18 @@ import org.jetbrains.annotations.NotNull; public enum LightColor implements StringRepresentable { - PRIMARY("primary",1), - PINK("pink",16), - DARK("dark",16), - YELLOW("yellow",16) + PRIMARY("primary", 1), + PINK("pink", 16), + DARK("dark", 16), + YELLOW("yellow", 16) ; public final String name; public final int dissipation; + LightColor(String name, int dissipation) { - this.name=name; - this.dissipation=dissipation; + this.name = name; + this.dissipation = dissipation; } @Override From 84ea7490cc29e57729e131bc1cfb262060c25681 Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Fri, 21 Jun 2024 22:06:18 +0800 Subject: [PATCH 08/11] Bug Fix --- .../dubhe/anvilcraft/api/BonemealManager.java | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java index 1670981b8..77863e57a 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java @@ -45,18 +45,6 @@ private static boolean isInSet(HashSet> set, Tuple item) { - for (Tuple cur : BonemealManager.lightBlocks) { - if (cur.getA().getX() == item.getA().getX() - && cur.getA().getY() == item.getA().getY() - && cur.getA().getZ() == item.getA().getZ() - && cur.getB().dimension() == item.getB().dimension()) { - return true; - } - } - return false; - } - private static HashSet> doRipen( @NotNull Level level, @NotNull BlockPos pos, @NotNull HashSet> set) { int rangeSize = AnvilCraft.config.inductionLightBlockRipeningRange; @@ -120,8 +108,6 @@ public static void tick() { * */ public static void addLightBlock(BlockPos pos, Level level) { - if (isInSet(new Tuple<>(pos, level))) { - lightBlocks.add(new Tuple<>(pos, level)); - } + lightBlocks.add(new Tuple<>(pos, level)); } } From aafefb7226101f1250c5a21f9568922ce3a3184c Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Fri, 21 Jun 2024 22:48:21 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E6=96=B9=E5=9D=97=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=A1=A5=E5=85=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/dev/dubhe/anvilcraft/block/InductionLightBlock.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java index a16f78dcf..e3db9fef2 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/InductionLightBlock.java @@ -6,6 +6,7 @@ import dev.dubhe.anvilcraft.block.entity.InductionLightBlockEntity; import dev.dubhe.anvilcraft.init.ModBlockEntities; import dev.dubhe.anvilcraft.init.ModBlocks; +import dev.dubhe.anvilcraft.init.ModItems; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.level.ServerLevel; @@ -165,6 +166,8 @@ protected void createBlockStateDefinition(StateDefinition.Builder item.broadcastBreakEvent(hand)); return InteractionResult.CONSUME_PARTIAL; + } else if (itemInHand.is(ModItems.VOID_MATTER.asItem())) { + level.setBlockAndUpdate(pos, state.setValue(COLOR, LightColor.DARK)); } return InteractionResult.PASS; } From 5ff1db4d1a37bb5e23c54e18d8eaba71a450fc18 Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Fri, 21 Jun 2024 22:53:21 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=8A=9F=E8=83=BD=E4=BF=AE=E8=A1=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java | 2 ++ .../main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java index 77863e57a..6de55cf0b 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java @@ -8,6 +8,7 @@ import net.minecraft.server.level.ServerLevel; import net.minecraft.util.Tuple; import net.minecraft.world.level.Level; +import net.minecraft.world.level.LightLayer; import net.minecraft.world.level.block.BonemealableBlock; import net.minecraft.world.level.block.GrassBlock; import net.minecraft.world.level.block.NyliumBlock; @@ -59,6 +60,7 @@ private static HashSet> doRipen( && !growable.getClass().equals(NyliumBlock.class) && !isInSet(set, new Tuple<>(pos1, level)) && growable.isValidBonemealTarget(level, pos1, state, false) + && level.getBrightness(LightLayer.BLOCK,pos1) >= 10 ) { growable.performBonemeal( (ServerLevel) level, diff --git a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java index 084ed46d8..41f7dbbcc 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/config/AnvilCraftConfig.java @@ -113,7 +113,7 @@ public class AnvilCraftConfig implements ConfigData { public boolean isLaserDoImpactChecking = true; @ConfigEntry.Gui.Tooltip - public int inductionLightBlockRipeningCooldown = 80; + public int inductionLightBlockRipeningCooldown = 400; @ConfigEntry.Gui.Tooltip @ConfigEntry.BoundedDiscrete(min = 0, max = 100) From fd273bafd27b7870d0cc117bda04189d3deaaa05 Mon Sep 17 00:00:00 2001 From: Bi2Nb9O3 <92721357+Bi2Nb9O3-Studio@users.noreply.github.com> Date: Fri, 21 Jun 2024 22:54:40 +0800 Subject: [PATCH 11/11] Code Style --- .../src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java index 6de55cf0b..08cc5e139 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/BonemealManager.java @@ -60,7 +60,7 @@ private static HashSet> doRipen( && !growable.getClass().equals(NyliumBlock.class) && !isInSet(set, new Tuple<>(pos1, level)) && growable.isValidBonemealTarget(level, pos1, state, false) - && level.getBrightness(LightLayer.BLOCK,pos1) >= 10 + && level.getBrightness(LightLayer.BLOCK, pos1) >= 10 ) { growable.performBonemeal( (ServerLevel) level,