From 279ef0b9de6b8a29fa87106c3cdb1f15bebeea24 Mon Sep 17 00:00:00 2001 From: Spicierspace153 <21964509+Spicierspace153@users.noreply.github.com> Date: Tue, 16 Sep 2025 15:48:51 -0600 Subject: [PATCH 1/3] void cleansing behavior --- .../cosmiccore/common/abyss/AbyssLogic.java | 4 +- .../behavior/VoidPylonBehavior.java | 87 +++++++++++++++++++ 2 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java diff --git a/src/main/java/com/ghostipedia/cosmiccore/common/abyss/AbyssLogic.java b/src/main/java/com/ghostipedia/cosmiccore/common/abyss/AbyssLogic.java index ef6add15e..015d872cc 100644 --- a/src/main/java/com/ghostipedia/cosmiccore/common/abyss/AbyssLogic.java +++ b/src/main/java/com/ghostipedia/cosmiccore/common/abyss/AbyssLogic.java @@ -122,11 +122,11 @@ private static void executePlayer(ServerPlayer player, IAbyssTimer cap) { player.hurt(player.damageSources().fellOutOfWorld(), Float.MAX_VALUE); } - private static void sendHUD(ServerPlayer player, long remain, long max) { + public static void sendHUD(ServerPlayer player, long remain, long max) { CCoreNetwork.sendToPlayer(player, new SyncTimeBarPacket(AbyssRules.DIM.location(), remain, max)); } - private static void hideHUD(ServerPlayer player) { + public static void hideHUD(ServerPlayer player) { CCoreNetwork.sendToPlayer(player, new SyncTimeBarPacket(AbyssRules.DIM.location(), -1, 0)); } } diff --git a/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java b/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java new file mode 100644 index 000000000..78d2ebcfb --- /dev/null +++ b/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java @@ -0,0 +1,87 @@ +package com.ghostipedia.cosmiccore.common.machine.multiblock.behavior; + +import com.ghostipedia.cosmiccore.common.abyss.AbyssBudgetCap; +import com.ghostipedia.cosmiccore.common.abyss.AbyssRules; + +import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; +import com.gregtechceu.gtceu.api.machine.TickableSubscription; +import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine; +import com.gregtechceu.gtceu.api.pattern.util.RelativeDirection; + +import com.gregtechceu.gtceu.utils.GTMath; +import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.util.Mth; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.phys.AABB; + +import org.jetbrains.annotations.NotNull; + +import static com.ghostipedia.cosmiccore.common.abyss.AbyssLogic.hideHUD; +import static com.ghostipedia.cosmiccore.common.abyss.AbyssLogic.sendHUD; + +public class VoidPylonBehavior extends WorkableElectricMultiblockMachine { + + @NotNull + private AABB killzone = new AABB(BlockPos.ZERO); + private TickableSubscription hurtSub; + private int purify = 1; + + public VoidPylonBehavior(IMachineBlockEntity holder, Object... args) { + super(holder, args); + } + + private void updateBounds(int multiplier) { + var flt = RelativeDirection.offsetPos(getPos(), getFrontFacing(), getUpwardsFacing(), isFlipped(), 3, 14, -14); + var brb = RelativeDirection.offsetPos(getPos(), getFrontFacing(), getUpwardsFacing(), isFlipped(), -14, -14, + 14); + killzone = new AABB(flt, brb); + } + + @Override + public void onPartUnload() { + super.onPartUnload(); + unsubscribe(hurtSub); + hurtSub = null; + } + + @Override + public void onStructureInvalid() { + super.onStructureInvalid(); + unsubscribe(hurtSub); + hurtSub = null; + } + + @Override + public void onStructureFormed() { + super.onStructureFormed(); + hurtSub = subscribeServerTick(this::cleanse); + updateBounds(1); + } + + private void cleanse() { + if (getOffsetTimer() % 35 != 0) return; + if (!this.isFormed) return; + if (isRemote() || getLevel() == null) return; + for (Entity entity : getLevel().getEntities(null, killzone)) { + if (entity instanceof Player player) { + + player.getCapability(AbyssBudgetCap.CAP).ifPresent(cap -> { + + var level = getLevel(); + + + if (level.dimension().equals(AbyssRules.DIM)) { + cap.setRemainingTicks(AbyssRules.DIM, (long) Mth.clamp( (cap.getRemainingTicks(AbyssRules.DIM) + 40), 0, AbyssRules.MAX_TICKS)); + if (player instanceof ServerPlayer sPlayer) { + sendHUD(sPlayer, cap.getRemainingTicks(AbyssRules.DIM), AbyssRules.MAX_TICKS); + } + } + }); + + } + } + } + +} From 95e89a9bfb37432b5449bf03d83bdf6dbe004093 Mon Sep 17 00:00:00 2001 From: Spicierspace153 <21964509+Spicierspace153@users.noreply.github.com> Date: Tue, 16 Sep 2025 19:28:23 -0600 Subject: [PATCH 2/3] wowa lighting changes to show the radius of where its doing da clean --- .../behavior/VoidPylonBehavior.java | 86 +++++++++++++++++-- 1 file changed, 77 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java b/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java index 78d2ebcfb..ebadacedd 100644 --- a/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java +++ b/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java @@ -4,29 +4,35 @@ import com.ghostipedia.cosmiccore.common.abyss.AbyssRules; import com.gregtechceu.gtceu.api.machine.IMachineBlockEntity; +import com.gregtechceu.gtceu.api.machine.MetaMachine; import com.gregtechceu.gtceu.api.machine.TickableSubscription; import com.gregtechceu.gtceu.api.machine.multiblock.WorkableElectricMultiblockMachine; import com.gregtechceu.gtceu.api.pattern.util.RelativeDirection; -import com.gregtechceu.gtceu.utils.GTMath; +import net.minecraft.client.Minecraft; import net.minecraft.core.BlockPos; +import net.minecraft.server.level.ServerLevel; import net.minecraft.server.level.ServerPlayer; import net.minecraft.util.Mth; import net.minecraft.world.entity.Entity; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.LightLayer; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.lighting.BlockLightEngine; import net.minecraft.world.phys.AABB; import org.jetbrains.annotations.NotNull; -import static com.ghostipedia.cosmiccore.common.abyss.AbyssLogic.hideHUD; import static com.ghostipedia.cosmiccore.common.abyss.AbyssLogic.sendHUD; public class VoidPylonBehavior extends WorkableElectricMultiblockMachine { @NotNull - private AABB killzone = new AABB(BlockPos.ZERO); + private AABB cleanAura = new AABB(BlockPos.ZERO); private TickableSubscription hurtSub; - private int purify = 1; + private boolean createLight = true; public VoidPylonBehavior(IMachineBlockEntity holder, Object... args) { super(holder, args); @@ -36,7 +42,7 @@ private void updateBounds(int multiplier) { var flt = RelativeDirection.offsetPos(getPos(), getFrontFacing(), getUpwardsFacing(), isFlipped(), 3, 14, -14); var brb = RelativeDirection.offsetPos(getPos(), getFrontFacing(), getUpwardsFacing(), isFlipped(), -14, -14, 14); - killzone = new AABB(flt, brb); + cleanAura = new AABB(flt, brb); } @Override @@ -51,6 +57,8 @@ public void onStructureInvalid() { super.onStructureInvalid(); unsubscribe(hurtSub); hurtSub = null; + createLight = false; + removeLight(); } @Override @@ -64,14 +72,14 @@ private void cleanse() { if (getOffsetTimer() % 35 != 0) return; if (!this.isFormed) return; if (isRemote() || getLevel() == null) return; - for (Entity entity : getLevel().getEntities(null, killzone)) { + emitLight(); + for (Entity entity : getLevel().getEntities(null, cleanAura)) { if (entity instanceof Player player) { - + // gets the cab player.getCapability(AbyssBudgetCap.CAP).ifPresent(cap -> { - var level = getLevel(); - + //checks if ur in the abyss and if so set the remaining tick and sync the hud :ta7: if (level.dimension().equals(AbyssRules.DIM)) { cap.setRemainingTicks(AbyssRules.DIM, (long) Mth.clamp( (cap.getRemainingTicks(AbyssRules.DIM) + 40), 0, AbyssRules.MAX_TICKS)); if (player instanceof ServerPlayer sPlayer) { @@ -84,4 +92,64 @@ private void cleanse() { } } + private void emitLight() { + if (getLevel() == null || isRemote()) return; + if (!(getLevel() instanceof ServerLevel level)) return; + if(!createLight) return; + + double cx = (cleanAura.minX + cleanAura.maxX) / 2.0; + double cz = (cleanAura.minZ + cleanAura.maxZ) / 2.0; + int maxLight = 15; + double maxDistance = Math.max(cleanAura.getXsize(), cleanAura.getZsize()) / 2.0; + + for (int x = Mth.floor(cleanAura.minX); x <= Mth.ceil(cleanAura.maxX); x++) { + for (int z = Mth.floor(cleanAura.minZ); z <= Mth.ceil(cleanAura.maxZ); z++) { + BlockPos pos = new BlockPos(x, this.getPos().getY(), z); + + double dx = x + 0.5 - cx; + double dz = z + 0.5 - cz; + double distance = Math.sqrt(dx * dx + dz * dz); + + if (distance <= maxDistance) { // only inside circle + // exponential falloff + double factor = Math.exp(-distance / maxDistance); + int lightLevel = Mth.clamp( + (int) Math.ceil(maxLight * factor), + 0, maxLight + ); + + if (lightLevel > 0) { + BlockState state = Blocks.LIGHT.defaultBlockState() + .setValue(net.minecraft.world.level.block.LightBlock.LEVEL, lightLevel); + + BlockState current = level.getBlockState(pos); + if (current.isAir() || current.is(Blocks.LIGHT)) { + level.setBlock(pos, state, Block.UPDATE_CLIENTS); + } + } + } + } + } + createLight = false; + } + + private void removeLight() { + if (getLevel() == null || isRemote()) return; + if (!(getLevel() instanceof ServerLevel level)) return; + if (createLight) return; + + for (int x = Mth.floor(cleanAura.minX); x <= Mth.ceil(cleanAura.maxX); x++) { + for (int z = Mth.floor(cleanAura.minZ); z <= Mth.ceil(cleanAura.maxZ); z++) { + BlockPos pos = new BlockPos(x, this.getPos().getY(), z); + + BlockState current = level.getBlockState(pos); + if (current.is(Blocks.LIGHT)) { + level.setBlock(pos, Blocks.AIR.defaultBlockState(), Block.UPDATE_CLIENTS); + } + } + } + } + + + } From 5d710674695ea27f5551d631a54c2309dbf7acfc Mon Sep 17 00:00:00 2001 From: Spicierspace153 <21964509+Spicierspace153@users.noreply.github.com> Date: Tue, 16 Sep 2025 19:36:50 -0600 Subject: [PATCH 3/3] i can write good code sometimes --- .../common/machine/multiblock/behavior/VoidPylonBehavior.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java b/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java index ebadacedd..dbab51ef5 100644 --- a/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java +++ b/src/main/java/com/ghostipedia/cosmiccore/common/machine/multiblock/behavior/VoidPylonBehavior.java @@ -110,7 +110,7 @@ private void emitLight() { double dz = z + 0.5 - cz; double distance = Math.sqrt(dx * dx + dz * dz); - if (distance <= maxDistance) { // only inside circle + if (distance <= maxDistance) { // exponential falloff double factor = Math.exp(-distance / maxDistance); int lightLevel = Mth.clamp(