Skip to content

Monster repeller blocks portal spawns - #7915

Open
Spaghetti-OberNub wants to merge 5 commits into
masterfrom
monster-repellent-blocks-portal-spawns
Open

Monster repeller blocks portal spawns#7915
Spaghetti-OberNub wants to merge 5 commits into
masterfrom
monster-repellent-blocks-portal-spawns

Conversation

@Spaghetti-OberNub

@Spaghetti-OberNub Spaghetti-OberNub commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Added a static instance for GTSpawnEventHandler, as well as an isAreaProtected-method to check if mobs should spawn in a portal. The condition is tested in a mixin.

This is the first time writing a mixin so please take a short look at it when reviewing. :)

Closes Issue 26004

Checklist

  • I have tested this PR in DevEnv*
  • I have tested this PR in Fullpack
  • This PR is in compliance with the GTNH AI Policy

* tested by forcing 20 portal update ticks per tick (see comment)

@Spaghetti-OberNub Spaghetti-OberNub added the Enhancement Improve an existing mechanic. Please explain the change with a before/after comparison. label Sep 2, 2026
Comment thread src/main/java/gregtech/api/util/GTSpawnEventHandler.java Outdated
Comment thread src/mixin/java/gregtech/mixin/mixins/early/minecraft/PortalSpawnCheckMixin.java Outdated
@Spaghetti-OberNub

Spaghetti-OberNub commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Just FYI, this was used to test spawning if someone else wants to verify or play around with it. (Warning dirty vibe code)

// in GTProxy.java
FMLCommonHandler.instance().bus().register(new SpeedupTickHandler());

// in SpeedupTickHandler.java
package gregtech; 

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import net.minecraft.block.BlockPortal;
import net.minecraft.world.WorldServer;
import net.minecraft.world.chunk.Chunk;

public class SpeedupTickHandler {

    private int debugTimer = 0;

    @SubscribeEvent
    public void onWorldTick(TickEvent.WorldTickEvent event) {
        if (event.phase == TickEvent.Phase.START && !event.world.isRemote) {
            WorldServer world = (WorldServer) event.world;

            debugTimer++;
            if (debugTimer >= 20) {
                debugTimer = 0;
            }
            
            for (Object chunkObj : world.theChunkProviderServer.loadedChunks) {
                Chunk chunk = (Chunk) chunkObj;
                
                for (int x = 0; x < 16; x++) {
                    for (int z = 0; z < 16; z++) {
                        for (int y = 0; y < 256; y++) {
                            int realX = chunk.xPosition * 16 + x;
                            int realZ = chunk.zPosition * 16 + z;
                            
                            if (world.getBlock(realX, y, realZ) instanceof BlockPortal) {
                                BlockPortal portal = (BlockPortal) world.getBlock(realX, y, realZ);
                                
                                for (int i = 0; i < 20; i++) {
                                    portal.updateTick(world, realX, y, realZ, world.rand);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Enhancement Improve an existing mechanic. Please explain the change with a before/after comparison.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Monster Repellator should block nether portal zombie piglin spawns

3 participants