diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/chargecollector/ThermoEntry.java b/common/src/main/java/dev/dubhe/anvilcraft/api/chargecollector/ThermoEntry.java index 4592ce158..de6d1feca 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/chargecollector/ThermoEntry.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/chargecollector/ThermoEntry.java @@ -37,7 +37,10 @@ public static ThermoEntry simple(int charge, Block input, Block output, boolean return new Simple(charge, input, output, canIrritated); } - public static ThermoEntry always(int charge, Block block, boolean canIrritated) { + /** + * not really forever + */ + public static ThermoEntry forever(int charge, Block block, boolean canIrritated) { return new Always(charge, block, canIrritated); } diff --git a/common/src/main/java/dev/dubhe/anvilcraft/api/chargecollector/ThermoManager.java b/common/src/main/java/dev/dubhe/anvilcraft/api/chargecollector/ThermoManager.java index 5ce740495..82babca0e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/api/chargecollector/ThermoManager.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/api/chargecollector/ThermoManager.java @@ -2,6 +2,7 @@ import dev.dubhe.anvilcraft.block.entity.ChargeCollectorBlockEntity; import dev.dubhe.anvilcraft.init.ModBlocks; +import lombok.Getter; import net.minecraft.core.BlockPos; import net.minecraft.util.Mth; import net.minecraft.world.level.Level; @@ -9,7 +10,6 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.CampfireBlock; import net.minecraft.world.level.block.state.BlockState; -import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; import java.util.ArrayList; @@ -50,6 +50,16 @@ private void register(ThermoEntry entry) { thermoEntries.add(entry); } + /** + * 移除热方块 + */ + public void removeThermalBlock(BlockPos pos) { + List b = thermoBlocks.stream() + .filter(it -> it.getPos().equals(pos)) + .toList(); + b.forEach(thermoBlocks::remove); + } + /** * 添加新的热方块 */ @@ -77,7 +87,7 @@ public void addThermoBlock(BlockPos blockPos, BlockState state) { register(ThermoEntry.simple(16, ModBlocks.REDHOT_TUNGSTEN.get(), ModBlocks.HEATED_TUNGSTEN.get(), true)); register(ThermoEntry.simple(4, ModBlocks.HEATED_TUNGSTEN.get(), ModBlocks.TUNGSTEN_BLOCK.get(), true)); - register(ThermoEntry.always(2, ModBlocks.URANIUM_BLOCK.get(), false)); + register(ThermoEntry.forever(2, ModBlocks.URANIUM_BLOCK.get(), false)); register(ThermoEntry.simple(4, Blocks.MAGMA_BLOCK, Blocks.NETHERRACK, false)); register(ThermoEntry.simple(4, Blocks.LAVA_CAULDRON, ModBlocks.OBSIDIDAN_CAULDRON.get(), false)); @@ -160,6 +170,7 @@ private void charge(int chargeNum, BlockPos blockPos) { } private static class ThermoBlock { + @Getter private final BlockPos pos; private final Block block; private int ttl; diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/ThermoelectricConverterBlock.java b/common/src/main/java/dev/dubhe/anvilcraft/block/ThermoelectricConverterBlock.java index b28b5ebde..b8a965e3e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/ThermoelectricConverterBlock.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/ThermoelectricConverterBlock.java @@ -17,6 +17,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Arrays; + public class ThermoelectricConverterBlock extends BaseEntityBlock implements IHammerRemovable { public static final Direction[] DIRECTIONS = {Direction.SOUTH, Direction.NORTH, Direction.EAST, Direction.WEST}; @@ -38,6 +40,7 @@ public void neighborChanged( @NotNull BlockPos neighborPos, boolean movedByPiston ) { + ThermoManager.getInstance(level).removeThermalBlock(neighborPos); ThermoManager.getInstance(level).addThermoBlock(neighborPos, level.getBlockState(neighborPos)); } @@ -47,6 +50,18 @@ public BlockEntity newBlockEntity(@NotNull BlockPos pos, @NotNull BlockState sta return new ThermoelectricConverterBlockEntity(ModBlockEntities.THERMOELECTRIC_CONVERTER.get(), pos, state); } + + @Override + public void onRemove( + @NotNull BlockState state, + @NotNull Level level, + @NotNull BlockPos pos, + @NotNull BlockState newState, + boolean movedByPiston + ) { + Arrays.stream(DIRECTIONS).map(pos::relative).forEach(ThermoManager.getInstance(level)::removeThermalBlock); + } + @Nullable @Override public BlockEntityTicker getTicker( diff --git a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/RubyLaserBlockEntity.java b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/RubyLaserBlockEntity.java index e326062d4..8e56931c2 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/block/entity/RubyLaserBlockEntity.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/block/entity/RubyLaserBlockEntity.java @@ -18,12 +18,12 @@ public class RubyLaserBlockEntity extends BaseLaserBlockEntity implements IPower private PowerGrid grid; private RubyLaserBlockEntity(BlockEntityType type, - BlockPos pos, BlockState blockState) { + BlockPos pos, BlockState blockState) { super(type, pos, blockState); } public static @NotNull RubyLaserBlockEntity createBlockEntity( - BlockEntityType type, BlockPos pos, BlockState blockState + BlockEntityType type, BlockPos pos, BlockState blockState ) { return new RubyLaserBlockEntity(type, pos, blockState); } @@ -31,22 +31,22 @@ private RubyLaserBlockEntity(BlockEntityType type, @Override public void tick(@NotNull Level level) { if (getGrid() != null - && getBlockState().getValue(RubyLaserBlock.OVERLOAD) == getGrid().isWork()) + && getBlockState().getValue(RubyLaserBlock.OVERLOAD) == getGrid().isWork()) level.setBlock( - getPos(), - getBlockState() - .setValue(OVERLOAD, !getGrid().isWork()), - 2); + getPos(), + getBlockState() + .setValue(OVERLOAD, !getGrid().isWork()), + 2); if (level.hasNeighborSignal(getBlockPos()) == (getBlockState().getValue(SWITCH) == Switch.ON)) level.setBlock( - getPos(), - getBlockState() - .setValue(SWITCH, level.hasNeighborSignal(getBlockPos()) ? Switch.OFF : Switch.ON), - 2); + getPos(), + getBlockState() + .setValue(SWITCH, level.hasNeighborSignal(getBlockPos()) ? Switch.OFF : Switch.ON), + 2); if (isSwitch()) emitLaser(getDirection()); else { if (irradiateBlockPos != null - && level.getBlockEntity(irradiateBlockPos) instanceof BaseLaserBlockEntity irradiateBlockEntity) + && level.getBlockEntity(irradiateBlockPos) instanceof BaseLaserBlockEntity irradiateBlockEntity) irradiateBlockEntity.onCancelingIrradiation(irradiateBlockEntity); irradiateBlockPos = null; } @@ -56,7 +56,7 @@ && getBlockState().getValue(RubyLaserBlock.OVERLOAD) == getGrid().isWork()) @Override public boolean isSwitch() { return getBlockState().getValue(RubyLaserBlock.SWITCH) == Switch.ON - && !getBlockState().getValue(RubyLaserBlock.OVERLOAD); + && !getBlockState().getValue(RubyLaserBlock.OVERLOAD); } @Override @@ -75,7 +75,8 @@ public Level getCurrentLevel() { @Override public int getInputPower() { - return 16; + if (level == null) return 16; + return getBlockState().getValue(RubyLaserBlock.SWITCH) == Switch.OFF ? 0 : 16; } @Override diff --git a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ActiveSilencerScreen.java b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ActiveSilencerScreen.java index 06db4cfc0..872e15a2e 100644 --- a/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ActiveSilencerScreen.java +++ b/common/src/main/java/dev/dubhe/anvilcraft/client/gui/screen/inventory/ActiveSilencerScreen.java @@ -21,6 +21,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.regex.Pattern; public class ActiveSilencerScreen extends AbstractContainerScreen { @@ -54,16 +55,48 @@ public class ActiveSilencerScreen extends AbstractContainerScreen it.right().getString().contains(filterText)) - .filter(it -> mutedSounds.stream().noneMatch(it1 -> it1.left().equals(it.first()))) - .forEach(filteredSounds::add); + + if (text.startsWith("#")) { + String search = text.replaceFirst("#", ""); + allSounds.stream() + .filter(it -> it.left().toString().contains(search)) + .filter(it -> mutedSounds.stream().noneMatch(it1 -> it1.left().equals(it.first()))) + .forEach(filteredSounds::add); + } else { + if (text.startsWith("~")) { + try { + Pattern search = Pattern.compile(text.replaceFirst("~", "")); + allSounds.stream() + .filter(it -> search.matcher(it.left().toString()).matches()) + .filter(it -> mutedSounds.stream().noneMatch(it1 -> it1.left().equals(it.first()))) + .forEach(filteredSounds::add); + } catch (Exception ignored) { + // intentionally empty + } + } + allSounds.stream() + .filter(it -> it.right().getString().contains(filterText)) + .filter(it -> mutedSounds.stream().noneMatch(it1 -> it1.left().equals(it.first()))) + .forEach(filteredSounds::add); + } + } + + @Override + public boolean keyPressed(int keyCode, int scanCode, int modifiers) { + if (this.minecraft.options.keyInventory.matches(keyCode, scanCode)) { + return this.getFocused() != null && this.getFocused().keyPressed(keyCode, scanCode, modifiers); + } else { + return super.keyPressed(keyCode, scanCode, modifiers); + } } private void refreshSoundList() {