From e1fa888c31f1b8203053f94fc4a388bf2a9654b7 Mon Sep 17 00:00:00 2001 From: Xalcon Date: Thu, 27 Jul 2023 11:17:38 +0200 Subject: [PATCH] introduce "intentional spawn" checks #214 --- changelog.md | 60 ++----------------- gradle.properties | 2 +- .../EntityBlockingEventHandler.java | 60 +++++++++++++++++-- 3 files changed, 60 insertions(+), 62 deletions(-) diff --git a/changelog.md b/changelog.md index 61f7f6c..21c21ad 100644 --- a/changelog.md +++ b/changelog.md @@ -1,61 +1,9 @@ +## v20.1.2 +- Improve blocking behavior for Mega Torch and Dread Lamp. Intentional Spawns (like Spawn Eggs, bucket placements, breeding) should no longer be blocked + ## v20.1.1 - Improve compatibility with Modded Spawners (i.e. EnderIO Spawners should no longer be blocked) - Improve Village Siege Blocking ## v20.1.0 -- Initial Port to Minecraft 1.20.1 - -## v19.4.0 -- Limit MC Version to 1.19.4+ for the Torchmaster 19.4.x version line (MC 1.19.4+). Use version 19.2.90+ for MC 1.19.2 -- Improve Invisible Light removal when Feral Flare Lantern is removed without player interaction - -## v19.2.3 -- Upgrade to MC 1.19.4 - -## v19.2.2 -- Fix non-intentional chunkloading via the feral flare lantern in some rare edge cases - -## v19.2.1 -- Upgrade to Mc 1.19.3 - -## v19.2.0 -- Upgrade to MC 1.19.2 - -## v19.0.2-beta -- fix crash on startup with more recent versions of forge - -## v19.0.1-beta -- Fix crash when placing Feral Flare Lantern - -## v19.0.0-alpha -- Initial port to MC 1.19 - -## v18.1.0 -- Allow the Mega Torch to block Village Sieges. This feature will be moved to a dedicated block in a future release. -- Upgrade to Minecraft 1.18.2 - -## v18.0.5 -- Fix a typo in the axe harvesting tags file - -## v18.0.4 -- Promote Mod to Release -- Adjust block sounds to reflect their materials more closely -- Add harvest tool for each block (Axe: Megatorch, Pickaxe: Feral Flare Lantern, Dread Lamp) -- Fix breaking particales for Feral Flare Lantern -- Added locations for: - - PT_BR, PT_PT by vimino@github - - FR_FR by dracnis@github - -## v18.0.3-beta -- Fix feral flare lantern not being able to remove light blocks after the chunk unloaded (i.e. world restart) - -## v18.0.2-beta -- Feral Flare Lantern can now place light blocks at y < 0 in non-superflat worlds (this one slipped through, sorry!) - -## v18.0.1-beta -- Feral Flare Lantern can now place light blocks at y < 0 -- Add support for the DoSpecialSpawn event -- Piglins spawning from Nether Portals should now be blocked - -## v18.0.0-beta -initial release for Minecraft 1.18 +- Initial Port to Minecraft 1.20.1 \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 06581b4..5a9cfc5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -48,7 +48,7 @@ mod_name=Torchmaster # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=All Rights Reserved # The mod version. See https://semver.org/ -mod_version=20.1.1 +mod_version=20.1.2 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/net/xalcon/torchmaster/common/logic/entityblocking/EntityBlockingEventHandler.java b/src/main/java/net/xalcon/torchmaster/common/logic/entityblocking/EntityBlockingEventHandler.java index b4c055d..0fdd6f4 100644 --- a/src/main/java/net/xalcon/torchmaster/common/logic/entityblocking/EntityBlockingEventHandler.java +++ b/src/main/java/net/xalcon/torchmaster/common/logic/entityblocking/EntityBlockingEventHandler.java @@ -6,7 +6,6 @@ import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobSpawnType; import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.SpawnerBlockEntity; import net.minecraftforge.event.AttachCapabilitiesEvent; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.living.MobSpawnEvent; @@ -23,19 +22,70 @@ @Mod.EventBusSubscriber(modid = Torchmaster.MODID) public class EntityBlockingEventHandler { + private static boolean isIntentionalSpawn(MobSpawnType spawnType) + { + switch(spawnType) + { + case BREEDING: + case DISPENSER: + case BUCKET: + case CONVERSION: + case SPAWN_EGG: + case TRIGGERED: + case COMMAND: + return true; + case NATURAL: + case CHUNK_GENERATION: + case PATROL: + case SPAWNER: + case STRUCTURE: + case MOB_SUMMONED: + case REINFORCEMENT: + case JOCKEY: + default: + return false; + } + } + + private static boolean isNaturalSpawn(MobSpawnType spawnType) + { + switch(spawnType) + { + case NATURAL: + case CHUNK_GENERATION: + case PATROL: // Patrol can be considered natural + default: + return true; + case BREEDING: + case CONVERSION: + case BUCKET: + case DISPENSER: + case SPAWNER: + case STRUCTURE: + case MOB_SUMMONED: + case JOCKEY: + case REINFORCEMENT: + case TRIGGERED: + case SPAWN_EGG: + case COMMAND: + return false; + } + } + @SubscribeEvent(priority = EventPriority.HIGH) public static void onFinalizeSpawn(MobSpawnEvent.FinalizeSpawn event) { boolean log = TorchmasterConfig.GENERAL.logSpawnChecks.get(); if (log) Torchmaster.Log.debug("CheckSpawn - SpawnType: {}, EntityType: {}, Pos: {}/{}/{}", event.getSpawnType(), EntityType.getKey(event.getEntity().getType()), event.getX(), event.getY(), event.getZ()); if(event.isSpawnCancelled()) return; + + // Check if the spawn was intentional (i.e. player invoked), we dont block those + if(isIntentionalSpawn(event.getSpawnType())) return; + if(!TorchmasterConfig.GENERAL.aggressiveSpawnChecks.get() && event.getResult() == Event.Result.ALLOW) return; if(TorchmasterConfig.GENERAL.blockOnlyNaturalSpawns.get()) { - if(event.getSpawnType() == MobSpawnType.SPAWNER) - { - return; - } + if(isNaturalSpawn(event.getSpawnType())) return; } var entity = event.getEntity();