Skip to content

Commit

Permalink
introduce "intentional spawn" checks #214
Browse files Browse the repository at this point in the history
  • Loading branch information
Xalcon committed Jul 27, 2023
1 parent 6ae550a commit e1fa888
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 62 deletions.
60 changes: 4 additions & 56 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand Down

0 comments on commit e1fa888

Please sign in to comment.