Skip to content

Commit 8c5df67

Browse files
committed
Kugelblitz feature #147 WIP
1 parent f3b71b6 commit 8c5df67

File tree

22 files changed

+493
-53
lines changed

22 files changed

+493
-53
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ dependencies {
124124
compileOnly fg.deobf("curse.maven:emi-580555:5872526")
125125

126126
implementation fg.deobf("mekanism:Mekanism:${mc_version}-${mekanism_version}")
127+
implementation fg.deobf("mekanism:Mekanism:${mc_version}-${mekanism_version}:generators")
127128
//compileOnly fg.deobf("mekanism:Mekanism:${mc_version}-${mekanism_version}:api")
128129

129130
compileOnly("cc.tweaked:cc-tweaked-${mc_version}-core-api:${cc_version}")

src/main/java/igentuman/nc/NuclearCraft.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public static void registerConfigs()
5959
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, MaterialsConfig.spec, "NuclearCraft/materials.toml");
6060
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, OreGenConfig.spec, "NuclearCraft/ore_generation.toml");
6161
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, CommonConfig.spec, "NuclearCraft/common.toml");
62+
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, KugelblitzConfig.spec, "NuclearCraft/kugelblitz.toml");
6263
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ProcessorsConfig.spec, "NuclearCraft/processors.toml");
6364
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, FissionConfig.spec, "NuclearCraft/fission.toml");
6465
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, FusionConfig.spec, "NuclearCraft/fusion.toml");

src/main/java/igentuman/nc/block/entity/NuclearCraftBE.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package igentuman.nc.block.entity;
22

33
import igentuman.api.nc.SideModeToggleable;
4-
import igentuman.nc.block.entity.fission.FissionControllerBE;
54
import igentuman.nc.client.sound.SoundHandler;
65
import igentuman.nc.handler.CatalystHandler;
76
import igentuman.nc.handler.UpgradesHandler;
@@ -10,7 +9,6 @@
109
import igentuman.nc.recipes.NcRecipeType;
1110
import igentuman.nc.recipes.RecipeInfo;
1211
import igentuman.nc.recipes.type.NcRecipe;
13-
import igentuman.nc.setup.registration.NCSounds;
1412
import igentuman.nc.util.CustomEnergyStorage;
1513
import igentuman.nc.util.NCBlockPos;
1614
import igentuman.nc.util.annotation.NBTField;
@@ -26,7 +24,6 @@
2624
import net.minecraft.server.level.ServerPlayer;
2725
import net.minecraft.sounds.SoundEvent;
2826
import net.minecraft.sounds.SoundSource;
29-
import net.minecraft.world.item.ItemStack;
3027
import net.minecraft.world.level.block.Block;
3128
import net.minecraft.world.level.block.entity.BlockEntity;
3229
import net.minecraft.world.level.block.entity.BlockEntityType;
@@ -44,7 +41,7 @@
4441
import java.lang.reflect.Field;
4542
import java.util.*;
4643

47-
import static igentuman.nc.util.ModUtil.isMekanismLoadeed;
44+
import static igentuman.nc.util.ModUtil.isMekanismLoaded;
4845

4946
public class NuclearCraftBE extends BlockEntity {
5047

@@ -99,6 +96,14 @@ public CustomEnergyStorage energyStorage() {
9996
return energyStorage;
10097
}
10198

99+
public BlockEntity blockEntity(BlockPos pos) {
100+
BlockEntity blockEntity = level.getExistingBlockEntity(pos);
101+
if(blockEntity == null) {
102+
blockEntity = level.getBlockEntity(pos);
103+
}
104+
return blockEntity;
105+
}
106+
102107
public RecipeInfo recipeInfo() {
103108
return recipeInfo;
104109
}
@@ -339,7 +344,7 @@ public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable D
339344
return contentHandler().getFluidCapability(side);
340345
}
341346

342-
if(isMekanismLoadeed() && contentHandler() != null) {
347+
if(isMekanismLoaded() && contentHandler() != null) {
343348
if(cap == mekanism.common.capabilities.Capabilities.GAS_HANDLER) {
344349
if(contentHandler().hasFluidCapability(side)) {
345350
return LazyOptional.of(() -> contentHandler().gasConverter(side));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable D
301301
return getOCDevice(cap, side);
302302
}
303303
}
304-
if(isMekanismLoadeed() && isSteamMode) {
304+
if(isMekanismLoaded() && isSteamMode) {
305305
if(cap == mekanism.common.capabilities.Capabilities.GAS_HANDLER) {
306306
if(contentHandler().hasFluidCapability(side)) {
307307
return LazyOptional.of(() -> contentHandler().gasConverter(side));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable D
147147
return controller().getEnergy().cast();
148148
}
149149

150-
if (isMekanismLoadeed() && isSteamMode) {
150+
if (isMekanismLoaded() && isSteamMode) {
151151
if (cap == mekanism.common.capabilities.Capabilities.GAS_HANDLER) {
152152
if (controller().contentHandler().hasFluidCapability(side)) {
153153
return LazyOptional.of(() -> controller().contentHandler().gasConverter(side));

src/main/java/igentuman/nc/block/entity/fusion/FusionCoreBE.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ protected FusionCoreProxyBE[] getProxies() {
525525
for(int y = 0; y < 3; y++) {
526526
for (int x = -1; x < 2; x++) {
527527
for (int z = -1; z < 2; z++) {
528-
BlockEntity be = Objects.requireNonNull(getLevel()).getBlockEntity(getBlockPos().offset(x, y, z));
529-
if (be instanceof FusionCoreProxyBE) {
530-
proxyBES[i] = (FusionCoreProxyBE) be;
528+
BlockEntity be = blockEntity(getBlockPos().offset(x, y, z));
529+
if (be instanceof FusionCoreProxyBE proxy) {
530+
proxyBES[i] = proxy;
531531
i++;
532532
}
533533
}

src/main/java/igentuman/nc/block/entity/fusion/FusionCoreProxyBE.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable D
178178
}
179179
}
180180

181-
if(isMekanismLoadeed()) {
181+
if(isMekanismLoaded()) {
182182
if(cap == mekanism.common.capabilities.Capabilities.GAS_HANDLER) {
183183
if(controller().contentHandler().hasFluidCapability(side)) {
184184
return LazyOptional.of(() -> controller().contentHandler().gasConverter(side));

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public class BlackHoleBE extends NuclearCraftBE {
1414

1515
public static String NAME = "black_hole";
16-
public float scale = 0.2f;
16+
public float scale = 0.3f;
1717

1818
@NBTField
1919
public boolean isInitialized = false;
@@ -26,16 +26,16 @@ public BlackHoleBE(BlockPos pPos, BlockState pBlockState) {
2626
public void tickClient() {
2727
if (spawnSoundCooldown > 1) {
2828
stopSound();
29-
scale = 0.2f;
29+
scale = 0.3f;
3030
}
3131
if (spawnSoundCooldown > 0) {
3232
spawnSoundCooldown--;
33-
scale = Math.max(0.19f, Math.min(0.21f, getLevel().getRandom().nextFloat()));
33+
scale = Math.max(0.29f, Math.min(0.31f, getLevel().getRandom().nextFloat()));
3434
return;
3535
}
3636
if (!isInitialized) {
3737
isInitialized = true;
38-
spawnSoundCooldown = 35;
38+
spawnSoundCooldown = 28;
3939
playSound(BLACKHOLE_SPAWN, 0.8f);
4040
}
4141
playSound(BLACKHOLE_IDLE, 0.7f);

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

Lines changed: 167 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,207 @@
11
package igentuman.nc.block.entity.kugelblitz;
22

33
import igentuman.nc.block.entity.NuclearCraftBE;
4-
import igentuman.nc.handler.sided.SidedContentHandler;
4+
import igentuman.nc.block.entity.fusion.FusionCoreProxyBE;
5+
import igentuman.nc.client.particle.FusionBeamParticleData;
6+
import igentuman.nc.multiblock.AbstractNCMultiblock;
7+
import igentuman.nc.multiblock.MultiblockHandler;
8+
import igentuman.nc.multiblock.kugelblitz.KugelblitzMultiblock;
9+
import igentuman.nc.multiblock.kugelblitz.KugelblitzRegistration;
510
import igentuman.nc.util.CustomEnergyStorage;
11+
import igentuman.nc.util.NCBlockPos;
12+
import igentuman.nc.util.annotation.NBTField;
13+
import mekanism.api.math.FloatingLong;
614
import net.minecraft.core.BlockPos;
15+
import net.minecraft.core.Direction;
16+
import net.minecraft.server.level.ServerLevel;
17+
import net.minecraft.server.level.ServerPlayer;
18+
import net.minecraft.world.level.block.Block;
19+
import net.minecraft.world.level.block.entity.BlockEntity;
720
import net.minecraft.world.level.block.entity.BlockEntityType;
821
import net.minecraft.world.level.block.state.BlockState;
22+
import net.minecraft.world.phys.Vec3;
923
import net.minecraftforge.common.util.LazyOptional;
1024
import net.minecraftforge.energy.IEnergyStorage;
25+
import net.minecraftforge.registries.ForgeRegistries;
1126

12-
import static igentuman.nc.handler.sided.SlotModePair.SlotMode.INPUT;
13-
import static igentuman.nc.handler.sided.SlotModePair.SlotMode.OUTPUT;
27+
import static igentuman.nc.block.fission.FissionControllerBlock.POWERED;
28+
import static igentuman.nc.handler.config.KugelblitzConfig.KUGELBLITZ_CONFIG;
1429
import static igentuman.nc.multiblock.kugelblitz.KugelblitzRegistration.EXPL_BE;
30+
import static igentuman.nc.setup.registration.NCSounds.LASER_SHOOT;
31+
import static igentuman.nc.util.ModUtil.isMekanismLoaded;
32+
import static net.minecraft.world.level.block.DirectionalBlock.FACING;
1533

1634
public class EXPLBE extends NuclearCraftBE {
1735

36+
@NBTField
37+
public int pulseEnergy;
38+
@NBTField
39+
public int inputRedstoneSignal = 0;
40+
@NBTField
41+
public boolean activated = false;
42+
@NBTField
1843
public int energyPerTick;
44+
@NBTField
45+
public int pulseTime = 0;
46+
1947
protected final LazyOptional<IEnergyStorage> energy;
20-
public final SidedContentHandler contentHandler;
2148
public final CustomEnergyStorage energyStorage;
49+
private EXPLProxyBE[] proxyBES;
50+
private boolean energyTransfered = false;
2251

2352
public EXPLBE(BlockPos pPos, BlockState pBlockState) {
2453
super(EXPL_BE.get(), pPos, pBlockState);
2554
energyStorage = createEnergy();
2655
energy = LazyOptional.of(() -> energyStorage);
27-
contentHandler = new SidedContentHandler(
28-
0, 0,
29-
1, 1, 10, 10);
30-
contentHandler().setBlockEntity(this);
31-
contentHandler().fluidCapability.setGlobalMode(0, INPUT);
32-
contentHandler().fluidCapability.setGlobalMode(1, OUTPUT);
3356
}
3457

3558
public EXPLBE(BlockEntityType<?> pType, BlockPos pPos, BlockState pBlockState) {
3659
this(pPos, pBlockState);
3760
}
3861

62+
protected void sendBeamData(FusionBeamParticleData data, BlockPos from) {
63+
Vec3 vec = Vec3.atCenterOf(from);
64+
if (!getLevel().isClientSide() && level instanceof ServerLevel serverWorld) {
65+
for (ServerPlayer player : serverWorld.players()) {
66+
serverWorld.sendParticles(player, data, true, vec.x, vec.y, vec.z, 1, 0, 0, 0, 0);
67+
}
68+
}
69+
}
70+
71+
protected void renderBeam() {
72+
int beamLength = 12;
73+
sendBeamData(new FusionBeamParticleData(getFacing(), beamLength, energyStorage().getEnergyStored()/(float)energyStorage().getMaxEnergyStored()*0.5f),
74+
getBlockPos().relative(getFacing())
75+
);
76+
}
77+
78+
private Direction getFacing() {
79+
return getBlockState().getValue(FACING);
80+
}
81+
3982
protected CustomEnergyStorage createEnergy() {
40-
return new CustomEnergyStorage(2_048_000_000, 5000000, 0) {
83+
return new CustomEnergyStorage(2_048_000_000, 1000000, 0) {
4184
@Override
4285
protected void onEnergyChanged() {
4386
setChanged();
4487
}
4588
};
4689
}
4790

91+
protected EXPLProxyBE[] getProxies() {
92+
if(proxyBES == null) {
93+
//proxy block placement depends on facing
94+
Direction facing = getFacing();
95+
int minX = -1, maxX = 0, minY = -1, minZ = 2, maxY = 4, maxZ = 2;
96+
switch (facing) {
97+
case UP:
98+
minX = -1; minY = 0; minZ = -1; maxX = 2; maxY = 4; maxZ = 2;
99+
break;
100+
case DOWN:
101+
minX = -1; minY = -3; minZ = -1; maxX = 2; maxY = 1; maxZ = 2;
102+
break;
103+
case NORTH:
104+
minX = -1; minY = -1; minZ = -3; maxX = 2; maxY = 2; maxZ = 1;
105+
break;
106+
case SOUTH:
107+
minX = -1; minY = -1; minZ = 0; maxX = 2; maxY = 2; maxZ = 4;
108+
break;
109+
case WEST:
110+
minX = -3; minY = -1; minZ = -1; maxX = 1; maxY = 2; maxZ = 2;
111+
break;
112+
case EAST:
113+
minX = 0; minY = -1; minZ = -1; maxX = 4; maxY = 2; maxZ = 2;
114+
break;
115+
}
116+
proxyBES = new EXPLProxyBE[35];
117+
int i = 0;
118+
119+
for (int x = minX; x < maxX; x++) {
120+
for (int z = minZ; z < maxZ; z++) {
121+
for (int y = minY; y < maxY; y++) {
122+
BlockEntity be = blockEntity(getBlockPos().offset(x, y, z));
123+
if (be instanceof EXPLProxyBE explProxy) {
124+
proxyBES[i] = explProxy;
125+
i++;
126+
}
127+
}
128+
}
129+
}
130+
}
131+
return proxyBES;
132+
}
133+
134+
private void tickProxyBlocks() {
135+
for(EXPLProxyBE proxy: getProxies()) {
136+
if(proxy == null) continue;
137+
proxy.forceTickServer(this);
138+
}
139+
}
140+
141+
@Override
142+
public void tickServer() {
143+
inputRedstoneSignal = 0;
144+
tickProxyBlocks();
145+
activated = activated || inputRedstoneSignal > 0;
146+
pulseEnergy = energyStorage().getEnergyStored();
147+
if (activated && pulseEnergy == energyStorage().getMaxEnergyStored()) {
148+
if (pulseTime == 0) {
149+
pulseTime = 80;
150+
}
151+
}
152+
if(pulseTime > 0) {
153+
level.setBlockAndUpdate(worldPosition, getBlockState());
154+
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), Block.UPDATE_NEIGHBORS);
155+
pulseTime--;
156+
setChanged();
157+
if(pulseTime < 40) {
158+
renderBeam();
159+
energyStorage().setEnergy(energyStorage().getEnergyStored()/2);
160+
}
161+
if(pulseTime < 35 && pulseTime > 30) {
162+
transferEnergy();
163+
}
164+
if (pulseTime < 10) {
165+
energyStorage().setEnergy(0);
166+
energyTransfered = false;
167+
}
168+
}
169+
if(activated && pulseTime < 1) {
170+
activated = false;
171+
setChanged();
172+
level.setBlockAndUpdate(worldPosition, getBlockState());
173+
level.sendBlockUpdated(worldPosition, getBlockState(), getBlockState(), Block.UPDATE_NEIGHBORS);
174+
}
175+
}
176+
177+
private void transferEnergy() {
178+
if (energyTransfered) return;
179+
energyTransfered = true;
180+
for (int i = 4; i <= KUGELBLITZ_CONFIG.LASER_DISTANCE.get()+4; i++) {
181+
BlockPos pos = getBlockPos().relative(getFacing(), i);
182+
BlockEntity be = level.getExistingBlockEntity(pos);
183+
if (be instanceof PhotonConcentratorBE photonConcentrator) {
184+
AbstractNCMultiblock multiblock = photonConcentrator.getMultiblock();
185+
if (multiblock instanceof KugelblitzMultiblock kugelblitzMultiblock) {
186+
kugelblitzMultiblock.addPulseEnergy(pulseEnergy, getFacing());
187+
break;
188+
}
189+
}
190+
if (isMekanismLoaded() && be instanceof mekanism.generators.common.tile.fusion.TileEntityLaserFocusMatrix matrixBe) {
191+
matrixBe.receiveLaserEnergy(FloatingLong.create(pulseEnergy));
192+
break;
193+
}
194+
}
195+
}
196+
48197
@Override
49-
public SidedContentHandler contentHandler() {
50-
return contentHandler;
198+
public void tickClient() {
199+
if(pulseEnergy > 0 && pulseTime > 78) {
200+
playSound(LASER_SHOOT, 0.9f);
201+
}
202+
if(pulseTime < 1) {
203+
stopSound();
204+
}
51205
}
52206

53207
@Override

0 commit comments

Comments
 (0)