Skip to content

Commit

Permalink
Merge pull request #993 from ZhuRuoLing/dev
Browse files Browse the repository at this point in the history
试图修复热电转换器破坏后铀块仍然会产生电荷   试图修复激光器关闭依然耗电的bug 修改主动静音器搜索逻辑
  • Loading branch information
Gu-ZT authored Jun 30, 2024
2 parents e326579 + c2ce77c commit 9e0d78c
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

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;
import net.minecraft.world.level.block.Block;
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;
Expand Down Expand Up @@ -50,6 +50,16 @@ private void register(ThermoEntry entry) {
thermoEntries.add(entry);
}

/**
* 移除热方块
*/
public void removeThermalBlock(BlockPos pos) {
List<ThermoBlock> b = thermoBlocks.stream()
.filter(it -> it.getPos().equals(pos))
.toList();
b.forEach(thermoBlocks::remove);
}

/**
* 添加新的热方块
*/
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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));
}

Expand All @@ -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 <T extends BlockEntity> BlockEntityTicker<T> getTicker(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,35 @@ 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);
}

@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;
}
Expand All @@ -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
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Pattern;

public class ActiveSilencerScreen extends AbstractContainerScreen<ActiveSilencerMenu> {

Expand Down Expand Up @@ -54,16 +55,48 @@ public class ActiveSilencerScreen extends AbstractContainerScreen<ActiveSilencer

private void onSearchTextChange(String text) {
leftScrollOff = 0;
filteredSounds.clear();
if (text == null || text.isEmpty()) {
this.filterText = "";
filteredSounds.addAll(allSounds);
filteredSounds.removeAll(mutedSounds);
return;
} else {
this.filterText = text;
}
filteredSounds.clear();
allSounds.stream()
.filter(it -> 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() {
Expand Down

0 comments on commit 9e0d78c

Please sign in to comment.