Skip to content

Commit 10a2fb1

Browse files
committed
Bunch of different optimizations and fixes
1 parent 06147bc commit 10a2fb1

31 files changed

+376
-165
lines changed

src/generated/resources/assets/nuclearcraft/lang/en_us.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,8 @@
24462446
"tooltip.nc.hev.desc": "Grants additional protection and passive effects when charged",
24472447
"tooltip.nc.jei.gas_to_fluid.desc": "NC blocks automatically converts Mek Gasses into Fluids during input",
24482448
"tooltip.nc.lightning_rod_charge": "Can charge NC Energy blocks by %s FE",
2449+
"tooltip.nc.link.designs": "Reactor Bots Discord",
2450+
"tooltip.nc.link.designs.descr": "Place where you can generate reactors",
24492451
"tooltip.nc.liquid_capacity": "Capacity: %s",
24502452
"tooltip.nc.liquid_empty": "Stored: 0 of %s",
24512453
"tooltip.nc.liquid_stored": "Stored: %s %s / %s",
@@ -2479,6 +2481,7 @@
24792481
"tooltip.nc.show_recipes": "Show Recipes",
24802482
"tooltip.nc.use_in_leacher": "Item can be used in Leacher",
24812483
"tooltip.nc.use_multitool": "Use Multitool to config sides",
2484+
"tooltip.nc.wiki": "Open WIKI",
24822485
"tooltip.nuclearcraft.particlestack.amount": "Amount: %s",
24832486
"tooltip.nuclearcraft.particlestack.empty": "No Particles",
24842487
"tooltip.nuclearcraft.particlestack.focus": "Focus: %s",
@@ -2495,6 +2498,7 @@
24952498
"turbine.efficiency": "Efficiency: %s%%",
24962499
"turbine.ratio": "Pressure: %s%%",
24972500
"turbine.real_flow": "Real Flow: %smB",
2501+
"validation.structure.asymetric_walls": "Walls are asymetric",
24982502
"validation.structure.incomplete": "Incomplete",
24992503
"validation.structure.no_controller": "No controllers",
25002504
"validation.structure.no_port": "No port found",

src/main/java/igentuman/nc/block/MultiblockBlock.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public boolean skipRendering(@NotNull BlockState state, @NotNull BlockState adja
3737
return adjacentBlockState.getBlock().equals(this) && TRANSPARENT_BLOCKS.matcher(asItem().toString()).matches();
3838
}
3939

40+
@Override
41+
public float getShadeBrightness(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
42+
return TRANSPARENT_BLOCKS.matcher(asItem().toString()).matches() ? 1.0F : super.getShadeBrightness(pState, pLevel, pPos);
43+
}
44+
4045
@Override
4146
public void onNeighborChange(BlockState state, LevelReader level, BlockPos pos, BlockPos neighbor) {
4247
super.onNeighborChange(state, level, pos, neighbor);
@@ -59,6 +64,6 @@ public void onRemove(BlockState state, Level level, BlockPos pos, BlockState new
5964

6065
@Override
6166
public boolean propagatesSkylightDown(BlockState pState, BlockGetter pLevel, BlockPos pPos) {
62-
return asItem().toString().contains("glass");
67+
return TRANSPARENT_BLOCKS.matcher(asItem().toString()).matches();
6368
}
6469
}

src/main/java/igentuman/nc/block/entity/fission/FissionControllerBE.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import igentuman.nc.block.entity.MultiblockControllerBE;
55
import igentuman.nc.compat.cc.SolidFissionReactorPeripheral;
66
import igentuman.nc.compat.oc2.FissionReactorDevice;
7+
import igentuman.nc.handler.event.client.BlockOverlayHandler;
78
import igentuman.nc.handler.sided.SidedContentHandler;
89
import igentuman.nc.handler.sided.SlotModePair;
910
import igentuman.nc.handler.sided.capability.ItemCapabilityHandler;
@@ -29,6 +30,8 @@
2930
import net.minecraft.world.level.block.Block;
3031
import net.minecraft.world.level.block.state.BlockState;
3132
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
33+
import net.minecraft.world.phys.AABB;
34+
import net.minecraft.world.phys.Vec3;
3235
import net.minecraftforge.common.capabilities.Capability;
3336
import net.minecraftforge.common.util.LazyOptional;
3437
import net.minecraftforge.energy.IEnergyStorage;
@@ -54,6 +57,7 @@
5457
import static igentuman.nc.setup.registration.NCSounds.FISSION_REACTOR;
5558
import static igentuman.nc.setup.registration.NcParticleTypes.RADIATION;
5659
import static igentuman.nc.util.ModUtil.*;
60+
import static net.minecraft.core.Direction.UP;
5761
import static net.minecraft.world.item.Items.AIR;
5862
import static net.minecraftforge.common.capabilities.ForgeCapabilities.*;
5963

@@ -360,10 +364,14 @@ public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable D
360364
public void tickClient() {
361365
super.tickClient();
362366
if(!isCasingValid || !isInternalValid) {
367+
BlockOverlayHandler.reactors.remove(this);
363368
stopSound();
364369
return;
365370
}
366371
if(efficiency > 0) {
372+
if(!BlockOverlayHandler.reactors.contains(this)) {
373+
BlockOverlayHandler.reactors.add(this);
374+
}
367375
spawnParticles();
368376
playSound(FISSION_REACTOR, 0.2f);
369377
} else {
@@ -558,10 +566,11 @@ private void spawnParticles() {
558566
if(level.getGameTime() % (level.random.nextInt(10)+5) != 0) {
559567
return;
560568
}
561-
562-
for(BlockPos blockPos: BlockPos.betweenClosed(bottomLeft.offset(1,1,1), topRight.offset(-1, -1, -1))) {
569+
BlockPos topRightInner = topRight.relative(getFacing(), -1).below().relative(getFacing().getClockWise(),1);
570+
BlockPos bottomLeftInner = bottomLeft.relative(getFacing(), 1).above().relative(getFacing().getCounterClockWise(),1);
571+
for(BlockPos blockPos: BlockPos.betweenClosed(bottomLeftInner, topRightInner)) {
563572
if(level.random.nextBoolean()) {
564-
level.addParticle(RADIATION.get(), blockPos.getX()+level.random.nextFloat(), blockPos.getY()+level.random.nextFloat(), blockPos.getZ()+level.random.nextFloat(), 0, -0.05f, 0);
573+
level.addParticle(RADIATION.get(), true, blockPos.getX()+level.random.nextFloat(), blockPos.getY()+level.random.nextFloat(), blockPos.getZ()+level.random.nextFloat(), 0, -0.05f, 0);
565574
}
566575
}
567576
}
@@ -860,6 +869,17 @@ public void drainCoolant(String coolant, int amount) {
860869
}
861870
}
862871

872+
public AABB getGlowAABB() {
873+
if (bottomLeft.equals(BlockPos.ZERO) || topRight.equals(BlockPos.ZERO)) {
874+
return new AABB(0, 0, 0, 0, 0, 0);
875+
}
876+
Vec3 topRightInner = new Vec3(topRight.getX(), topRight.getY(), topRight.getZ());
877+
topRightInner = topRightInner.relative(getFacing(), 0.05D).relative(UP, 0.05D).relative(getFacing().getClockWise(),-0.05D);
878+
Vec3 bottomLeftInner = new Vec3(bottomLeft.getX(), bottomLeft.getY(), bottomLeft.getZ());
879+
bottomLeftInner = bottomLeftInner.relative(getFacing(), 0.95D).relative(UP, 0.95D).relative(getFacing().getCounterClockWise(),0.95D);
880+
return new AABB(bottomLeftInner, topRightInner);
881+
}
882+
863883
public static class Recipe extends NcRecipe {
864884

865885
public Recipe(ResourceLocation id, ItemStackIngredient[] input, ItemStackIngredient[] output, FluidStackIngredient[] inputFluids, FluidStackIngredient[] outputFluids, double timeModifier, double powerModifier, double heatModifier, double rarity) {

src/main/java/igentuman/nc/block/entity/fission/FissionPortBE.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import igentuman.nc.handler.sided.capability.ItemCapabilityHandler;
88
import igentuman.nc.multiblock.AbstractMultiblock;
99
import igentuman.nc.multiblock.MultiblockHandler;
10-
import igentuman.nc.multiblock.fission.FissionReactorRegistration;
1110
import igentuman.nc.multiblock.fission.FissionReactorMultiblock;
11+
import igentuman.nc.multiblock.fission.FissionReactorRegistration;
1212
import igentuman.nc.util.annotation.NBTField;
1313
import net.minecraft.core.BlockPos;
1414
import net.minecraft.core.Direction;
@@ -77,23 +77,24 @@ private boolean updateController() {
7777
controllerPos = new BlockPos(controller.getBlockPos());
7878
result = true;
7979
}
80-
if (isSteamMode != controller().isSteamMode) {
80+
if (controller() != null && isSteamMode != controller().isSteamMode) {
8181
isSteamMode = controller().isSteamMode;
8282
result = true;
8383
}
8484
return result;
8585
}
8686

8787
public void tickServer() {
88-
if (NuclearCraft.instance.isNcBeStopped || isRemoved() || getMultiblock() == null || controller() == null) return;
88+
if (NuclearCraft.instance.isNcBeStopped || isRemoved()) return;
89+
8990
int wasSignal = analogSignal;
9091
boolean wasConnected = connected;
9192
sendOutPower();
9293
boolean updated = updateController();
93-
if(level.getGameTime() % 20 == 0) {
94+
if(level.getGameTime() % 20 == 0 && controller() != null) {
9495
pushPull();
9596
}
96-
if (level.getGameTime() % 10 == 0) {
97+
if (level.getGameTime() % 10 == 0 && controller() != null) {
9798
updateAnalogSignal();
9899

99100
updated = wasSignal != analogSignal || updated;
@@ -102,11 +103,14 @@ public void tickServer() {
102103
case SignalSource.MODERATOR -> controller().adjustModerator(analogSignal);
103104
}
104105
}
105-
connected = getMultiblock().isFormed();
106+
connected = getMultiblock() != null && getMultiblock().isFormed();
106107
if (updated || wasConnected != connected) {
107-
MultiblockHandler.get(level.dimension()).addIgnoreToUpdate(getBlockPos());
108+
if(connected) {
109+
MultiblockHandler.get(level.dimension()).addIgnoreToUpdate(getBlockPos());
110+
}
108111
setChanged();
109112
level.updateNeighborsAt(worldPosition, getBlockState().getBlock());
113+
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
110114
}
111115
}
112116

@@ -226,12 +230,21 @@ protected boolean sendOutPower() {
226230

227231
@Override
228232
public boolean canInvalidateCache() {
229-
return false;
233+
return true;
230234
}
231235

232236
@Override
233237
public void setMultiblock(AbstractMultiblock multiblock) {
238+
if(this.multiblock == multiblock) {
239+
return;
240+
}
234241
this.multiblock = (FissionReactorMultiblock) multiblock;
242+
if (this.multiblock != null) {
243+
controllerPos = this.multiblock.controller().controllerBE().getBlockPos();
244+
controller = (FissionControllerBE) this.multiblock.controller().controllerBE();
245+
setChanged();
246+
level.updateNeighborsAt(worldPosition, getBlockState().getBlock());
247+
}
235248
}
236249

237250
@Override

src/main/java/igentuman/nc/block/entity/kugelblitz/ChamberPortBE.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import igentuman.api.nc.multiblock.MultiblockAttachable;
44
import igentuman.nc.NuclearCraft;
55
import igentuman.nc.block.entity.NuclearCraftBE;
6+
import igentuman.nc.block.entity.fission.FissionControllerBE;
67
import igentuman.nc.handler.sided.capability.FluidCapabilityHandler;
78
import igentuman.nc.multiblock.AbstractMultiblock;
89
import igentuman.nc.multiblock.MultiblockHandler;
@@ -56,7 +57,16 @@ public boolean hasRedstoneSignal() {
5657

5758
@Override
5859
public void setMultiblock(AbstractMultiblock multiblock) {
60+
if(this.multiblock == multiblock) {
61+
return;
62+
}
5963
this.multiblock = (KugelblitzMultiblock) multiblock;
64+
if (this.multiblock != null) {
65+
controllerPos = this.multiblock.controller().controllerBE().getBlockPos();
66+
controller = (ChamberTerminalBE) this.multiblock.controller().controllerBE();
67+
setChanged();
68+
level.updateNeighborsAt(worldPosition, getBlockState().getBlock());
69+
}
6070
}
6171

6272
@Override
@@ -95,13 +105,13 @@ public void tickServer() {
95105
Direction dir = getFacing();
96106

97107
if(fluidHandler() != null) {
98-
//updated = fluidHandler().pushFluids(dir, false, worldPosition) || updated;
99108
updated = fluidHandler().pullFluids(dir, false, worldPosition) || updated;
100109
}
101110

102111
if(updated) {
103112
MultiblockHandler.get(level.dimension()).addIgnoreToUpdate(getBlockPos());
104113
setChanged();
114+
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), Block.UPDATE_CLIENTS);
105115
level.updateNeighborsAt(worldPosition, getBlockState().getBlock());
106116
}
107117
}

src/main/java/igentuman/nc/block/entity/kugelblitz/ChamberTerminalBE.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,7 @@ public void tickServer() {
228228
super.tickServer();
229229
boolean wasEnabled = controllerEnabled;
230230
handleValidation();
231-
controllerEnabled = getMultiblock().isFormed() && hasBlackhole();
232-
233-
fluxRegulators = getMultiblock().fluxRegulators();
234-
transformers = getMultiblock().transformers();
235-
stabilizers = getMultiblock().stabilizers();
231+
controllerEnabled = getMultiblock().getBlackHole() instanceof BlackHoleBE;
236232
if (controllerEnabled) {
237233
trackChanges(contentHandler().tick());
238234
long wasMass = mass;
@@ -244,15 +240,20 @@ public void tickServer() {
244240
if(!isBlackHoleStable()) {
245241
getLevel().gameEvent(null, BLACKHOLE_VIBRATION.get(), getMultiblock().getCenter());
246242
}
243+
} else if(mass > 0) {
244+
mass = 0;
245+
feeding = 0;
246+
evaporation = 0;
247+
energyPerTick = 0;
248+
changed = true;
247249
}
248-
refreshCacheFlag = !getMultiblock().isFormed();
249250
if(wasEnabled != controllerEnabled) {
250251
setChanged();
251252
}
252-
if(refreshCacheFlag || changed) {
253+
if(changed) {
253254
try {
254255
setChanged();
255-
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState().setValue(POWERED, controllerEnabled), Block.UPDATE_NEIGHBORS);
256+
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState().setValue(POWERED, controllerEnabled), Block.UPDATE_CLIENTS);
256257
level.setBlockAndUpdate(worldPosition, getBlockState().setValue(POWERED, controllerEnabled));
257258
} catch (NullPointerException ignored) {}
258259
}

src/main/java/igentuman/nc/block/entity/kugelblitz/EXPLBE.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ protected void sendBeamData(FusionBeamParticleData data, BlockPos from) {
6161
}
6262

6363
protected void renderBeam() {
64-
sendBeamData(new FusionBeamParticleData(getFacing(), KUGELBLITZ_CONFIG.LASER_DISTANCE.get(), (float) (aggregatedEnergy/((double)KUGELBLITZ_CONFIG.EXPL_CHARGE.get()))*0.5f),
64+
sendBeamData(new FusionBeamParticleData(getFacing(), getActualLaserDistance()+1, (float) (aggregatedEnergy/((double)KUGELBLITZ_CONFIG.EXPL_CHARGE.get()))*0.5f),
6565
getBlockPos().relative(getFacing())
6666
);
6767
}
@@ -213,24 +213,35 @@ public void activate() {
213213
}
214214
}
215215

216-
private void transferEnergy() {
217-
if (energyTransfered) return;
218-
energyTransfered = true;
216+
private int getActualLaserDistance() {
219217
for (int i = 4; i <= KUGELBLITZ_CONFIG.LASER_DISTANCE.get()+4; i++) {
220218
BlockPos pos = getBlockPos().relative(getFacing(), i);
221219
BlockEntity be = level.getExistingBlockEntity(pos);
222-
if (be instanceof PhotonConcentratorBE photonConcentrator) {
223-
AbstractMultiblock multiblock = photonConcentrator.getMultiblock();
224-
if (multiblock instanceof KugelblitzMultiblock kugelblitzMultiblock) {
225-
kugelblitzMultiblock.addPulseEnergy(aggregatedEnergy, getFacing());
226-
break;
227-
}
220+
if (be instanceof PhotonConcentratorBE) {
221+
return i;
228222
}
229-
if (isMekanismGeneratorsLoaded() && be instanceof mekanism.generators.common.tile.fusion.TileEntityLaserFocusMatrix matrixBe) {
230-
matrixBe.receiveLaserEnergy(FloatingLong.create(aggregatedEnergy / 10));
231-
break;
223+
if (isMekanismGeneratorsLoaded() && be instanceof mekanism.generators.common.tile.fusion.TileEntityLaserFocusMatrix) {
224+
return i;
232225
}
233226
}
227+
return KUGELBLITZ_CONFIG.LASER_DISTANCE.get();
228+
}
229+
230+
private void transferEnergy() {
231+
if (energyTransfered) return;
232+
energyTransfered = true;
233+
BlockPos pos = getBlockPos().relative(getFacing(), getActualLaserDistance());
234+
BlockEntity be = level.getExistingBlockEntity(pos);
235+
if (be instanceof PhotonConcentratorBE photonConcentrator) {
236+
AbstractMultiblock multiblock = photonConcentrator.getMultiblock();
237+
if (multiblock instanceof KugelblitzMultiblock kugelblitzMultiblock) {
238+
kugelblitzMultiblock.addPulseEnergy(aggregatedEnergy, getFacing());
239+
return;
240+
}
241+
}
242+
if (isMekanismGeneratorsLoaded() && be instanceof mekanism.generators.common.tile.fusion.TileEntityLaserFocusMatrix matrixBe) {
243+
matrixBe.receiveLaserEnergy(FloatingLong.create(aggregatedEnergy / 10));
244+
}
234245
}
235246

236247
@Override

src/main/java/igentuman/nc/block/fission/FissionPort.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,17 @@ public void onNeighborChange(BlockState state, LevelReader level, BlockPos pos,
137137
if(level.isClientSide()) return;
138138
MultiblockHandler.get(((Level)level).dimension()).trackBlockChange(pos);
139139
}
140+
141+
@Override
142+
public void onPlace(BlockState pState, Level pLevel, BlockPos pPos, BlockState pOldState, boolean pMovedByPiston) {
143+
super.onPlace(pState, pLevel, pPos, pOldState, pMovedByPiston);
144+
MultiblockHandler.get(pLevel.dimension()).trackBlockChange(pPos, true);
145+
}
146+
147+
@Override
148+
public void onRemove(BlockState state, Level level, BlockPos pos, BlockState newState, boolean isMoving) {
149+
super.onRemove(state, level, pos, newState, isMoving);
150+
if(level.isClientSide()) return;
151+
MultiblockHandler.get(level.dimension()).trackBlockChange(pos, true);
152+
}
140153
}

src/main/java/igentuman/nc/block/fusion/FusionCasingBlock.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import net.minecraft.world.item.TooltipFlag;
99
import net.minecraft.world.item.context.BlockPlaceContext;
1010
import net.minecraft.world.level.BlockGetter;
11+
import net.minecraft.world.level.block.GlassBlock;
1112
import net.minecraft.world.level.block.SoundType;
1213
import net.minecraft.world.level.block.state.BlockState;
1314
import net.minecraftforge.registries.ForgeRegistries;
@@ -21,7 +22,7 @@ public class FusionCasingBlock extends MultiblockBlock {
2122
public FusionCasingBlock() {
2223
this(Properties.of()
2324
.sound(SoundType.METAL)
24-
.strength(2.0f)
25+
.strength(3.0f)
2526
.noOcclusion()
2627
.requiresCorrectToolForDrops());
2728
}

0 commit comments

Comments
 (0)