diff options
author | pariator <97362524+pariator@users.noreply.github.com> | 2022-02-10 09:55:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-10 08:55:28 -0800 |
commit | b87977e7f636f58ea6366868abddcf0993be01fd (patch) | |
tree | a6067131534dd103eb622798140b5cbec7f5c813 /src/main/java/gregtech | |
parent | 19809d78beee78012738f7587b61b47a3b36442b (diff) | |
download | GT5-Unofficial-b87977e7f636f58ea6366868abddcf0993be01fd.tar.gz GT5-Unofficial-b87977e7f636f58ea6366868abddcf0993be01fd.tar.bz2 GT5-Unofficial-b87977e7f636f58ea6366868abddcf0993be01fd.zip |
Fixes slime spawn handling variances Issue 7298 (#905)
* Fixes slime spawn handling variances
After testing, I was able to see 2 separate problems.
1: event.getResult() was occasionally returning ALLOW for some of the world spawned slimes. Slime spawn denial is done regardless of the ALLOW/DENY flag. This does not impact slimes spawned via eggs or powered spawners or slimes spawning after a slime is killed which apparently return DEFAULT for getResult().
2: Slimes don't seem to properly handle a getResult() value of DENY. The checkSpawn event is not cancellable. To fix this, the entity is also destroyed by setting isDead to true. This does occasionally cause slimes to appear on the minimap briefly before disappearing.
Lastly, with a forge update this could be handled much better by using the EntitySlime.spawnReason enum. That is not present in the current forge version, so I would consider this a temporary workaround and this method could/should be reworked if/when forge is updated.
* Make repellators stop slimes.
While testing, this was used to name the slimes as they were being generated. It turns out to also make the slimes behave properly in addition to the other changes.
* Minor Cleanup
Moved the slime handling out of the rest of the method and takes an approach of setting it to DEFAULT of it is ALLOW and then also adding a custom name tag if it doesn't have one. If it does have a custom name tag and ALLOW, then the slime spawn will be allowed.
Diffstat (limited to 'src/main/java/gregtech')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_SpawnEventHandler.java | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/src/main/java/gregtech/api/util/GT_SpawnEventHandler.java b/src/main/java/gregtech/api/util/GT_SpawnEventHandler.java index bd279f73e2..2191c119cb 100644 --- a/src/main/java/gregtech/api/util/GT_SpawnEventHandler.java +++ b/src/main/java/gregtech/api/util/GT_SpawnEventHandler.java @@ -23,10 +23,16 @@ public class GT_SpawnEventHandler { @SubscribeEvent public void denyMobSpawn(CheckSpawn event) { + if (event.entityLiving instanceof EntitySlime && !(((EntitySlime) event.entityLiving).getCustomNameTag().length() > 0)) { + ((EntitySlime) event.entityLiving).setCustomNameTag("DoNotSpawnSlimes"); + if(event.getResult() == Event.Result.ALLOW) event.setResult(Event.Result.DEFAULT); + } + if (event.getResult() == Event.Result.ALLOW) { return; } - if (event.entityLiving.isCreatureType(EnumCreatureType.monster, false) || event.entityLiving instanceof EntitySlime) { + + if (event.entityLiving.isCreatureType(EnumCreatureType.monster, false)) { for (int[] rep : mobReps) { if (rep[3] == event.entity.worldObj.provider.dimensionId) { TileEntity tTile = event.entity.worldObj.getTileEntity(rep[0], rep[1], rep[2]); |