-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #552 from jchung01/mod-tweaks
Add Woot mixin for proper entity cleanup
- Loading branch information
Showing
13 changed files
with
256 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/main/java/mod/acgaming/universaltweaks/mods/woot/ITartarusCleaner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package mod.acgaming.universaltweaks.mods.woot; | ||
|
||
import net.minecraft.world.World; | ||
|
||
public interface ITartarusCleaner | ||
{ | ||
void ut$clean(World world, int boxId, boolean removeAll); | ||
void ut$freeBoxes(); | ||
boolean ut$areBoxesInUse(); | ||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/mod/acgaming/universaltweaks/mods/woot/UTWootTicketManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package mod.acgaming.universaltweaks.mods.woot; | ||
|
||
import java.util.List; | ||
|
||
import net.minecraft.util.math.ChunkPos; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldServer; | ||
import net.minecraftforge.common.ForgeChunkManager; | ||
|
||
import ipsis.Woot; | ||
import ipsis.woot.dimension.WootDimensionManager; | ||
import ipsis.woot.util.DebugSetup; | ||
import mod.acgaming.universaltweaks.UniversalTweaks; | ||
|
||
public class UTWootTicketManager | ||
{ | ||
public static final ChunkPos CHUNK = new ChunkPos(WootDimensionManager.CHUNK_X, WootDimensionManager.CHUNK_Z); | ||
public static ForgeChunkManager.Ticket ticket; | ||
|
||
public static void forceChunk(World world, int boxId) | ||
{ | ||
WorldServer worldWoot = Woot.wootDimensionManager.getWorldServer(world); | ||
if (ticket == null) | ||
{ | ||
Woot.debugSetup.trace(DebugSetup.EnumDebugType.TARTARUS, "UTWootTicketManager:callback", "requesting a ticket"); | ||
ticket = ForgeChunkManager.requestTicket(Woot.instance, worldWoot, ForgeChunkManager.Type.NORMAL); | ||
if (ticket == null) | ||
{ | ||
UniversalTweaks.LOGGER.error("UTWootTicketManager ::: Could not get a ticket for Tartarus (Woot)! Please report to Universal Tweaks."); | ||
return; | ||
} | ||
} | ||
Woot.debugSetup.trace(DebugSetup.EnumDebugType.TARTARUS, "UTWootTicketManager:callback", "forcing chunk for boxId " + boxId); | ||
ForgeChunkManager.forceChunk(ticket, CHUNK); | ||
} | ||
|
||
public static void releaseChunk(int boxId) | ||
{ | ||
if (ticket == null) return; | ||
Woot.debugSetup.trace(DebugSetup.EnumDebugType.TARTARUS, "UTWootTicketManager:callback", "trying to release chunk for boxId " + boxId); | ||
if (!((ITartarusCleaner) Woot.tartarusManager).ut$areBoxesInUse()) | ||
{ | ||
Woot.debugSetup.trace(DebugSetup.EnumDebugType.TARTARUS, "UTWootTicketManager:callback", "releasing ticket"); | ||
ForgeChunkManager.releaseTicket(ticket); | ||
ticket = null; | ||
} | ||
} | ||
|
||
public static void callback(List<ForgeChunkManager.Ticket> tickets, World world) | ||
{ | ||
int dim = world.provider.getDimension(); | ||
if (dim != Woot.wootDimensionManager.getDimensionId()) return; | ||
// Sanity check | ||
if (tickets.size() > 1) | ||
{ | ||
for (ForgeChunkManager.Ticket ticket : tickets) | ||
{ | ||
ForgeChunkManager.releaseTicket(ticket); | ||
} | ||
} | ||
UTWootTicketManager.ticket = tickets.get(0); | ||
((ITartarusCleaner) Woot.tartarusManager).ut$freeBoxes(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/mod/acgaming/universaltweaks/mods/woot/mixin/UTEntitySpawnerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package mod.acgaming.universaltweaks.mods.woot.mixin; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityLivingBase; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
import com.llamalad7.mixinextras.sugar.Local; | ||
import ipsis.woot.spawning.EntitySpawner; | ||
import ipsis.woot.util.WootMobName; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
// Courtesy of jchung01 | ||
@Mixin(value = EntitySpawner.class, remap = false) | ||
public class UTEntitySpawnerMixin | ||
{ | ||
/** | ||
* @reason Set correct entity values BEFORE passing to events. | ||
*/ | ||
@Inject(method = "spawnEntity", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;doSpecialSpawn(Lnet/minecraft/entity/EntityLiving;Lnet/minecraft/world/World;FFF)Z")) | ||
private void ut$fixInitSpawn(WootMobName wootMobName, World world, BlockPos pos, CallbackInfoReturnable<Entity> cir, @Local Entity entity) | ||
{ | ||
((EntityLivingBase)entity).recentlyHit = 100; | ||
entity.setPosition(pos.getX(), pos.getY(), pos.getZ()); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
src/main/java/mod/acgaming/universaltweaks/mods/woot/mixin/UTTartarusManagerMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package mod.acgaming.universaltweaks.mods.woot.mixin; | ||
|
||
import java.util.HashMap; | ||
|
||
import com.google.common.base.Predicate; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.item.EntityItem; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldServer; | ||
|
||
import ipsis.Woot; | ||
import ipsis.woot.loot.schools.SpawnBox; | ||
import ipsis.woot.loot.schools.TartarusManager; | ||
import mod.acgaming.universaltweaks.mods.woot.ITartarusCleaner; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
// Courtesy of jchung01 | ||
@Mixin(value = TartarusManager.class, remap = false) | ||
public class UTTartarusManagerMixin implements ITartarusCleaner | ||
{ | ||
@Shadow | ||
private HashMap<Integer, SpawnBox> spawnBoxMap; | ||
|
||
@Override | ||
public void ut$clean(World world, int boxId, boolean removeAll) | ||
{ | ||
WorldServer worldWoot = Woot.wootDimensionManager.getWorldServer(world); | ||
if (worldWoot == null) return; | ||
// Some additionally spawned entities are not EntityLiving (like AoA heartstones), so search by exclusion | ||
Predicate<Entity> condition = entity -> | ||
{ | ||
boolean ret = !(entity instanceof EntityPlayer); | ||
return removeAll ? ret : ret && !(entity instanceof EntityItem); | ||
}; | ||
for (Entity entity : worldWoot.getEntitiesWithinAABB(Entity.class, this.spawnBoxMap.get(boxId).getAxisAlignedBB(), condition)) | ||
{ | ||
worldWoot.removeEntityDangerously(entity); | ||
} | ||
} | ||
|
||
@Override | ||
public void ut$freeBoxes() | ||
{ | ||
for (SpawnBox box : spawnBoxMap.values()) | ||
{ | ||
box.clearUsed(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean ut$areBoxesInUse() | ||
{ | ||
for (SpawnBox box: spawnBoxMap.values()) | ||
{ | ||
if (box.isUsed()) return true; | ||
} | ||
return false; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/mod/acgaming/universaltweaks/mods/woot/mixin/UTTartarusSchoolMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package mod.acgaming.universaltweaks.mods.woot.mixin; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import ipsis.Woot; | ||
import ipsis.woot.farming.ITickTracker; | ||
import ipsis.woot.farmstructure.IFarmSetup; | ||
import ipsis.woot.loot.schools.TartarusManager; | ||
import ipsis.woot.loot.schools.TartarusSchool; | ||
import mod.acgaming.universaltweaks.mods.woot.ITartarusCleaner; | ||
import mod.acgaming.universaltweaks.mods.woot.UTWootTicketManager; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
// Courtesy of jchung01 | ||
@Mixin(value = TartarusSchool.class, remap = false) | ||
public class UTTartarusSchoolMixin | ||
{ | ||
@Shadow | ||
private int spawnId; | ||
|
||
@Inject(method = "tick", at = @At(value = "INVOKE", target = "Lipsis/woot/loot/schools/TartarusManager;spawnInBox(Lnet/minecraft/world/World;ILipsis/woot/util/WootMobName;Lipsis/woot/util/EnumEnchantKey;)V", shift = At.Shift.AFTER)) | ||
private void ut$cleanupOnDeath(ITickTracker tickTracker, World world, BlockPos origin, IFarmSetup farmSetup, CallbackInfo ci) | ||
{ | ||
if (spawnId == -1) return; | ||
((ITartarusCleaner) Woot.tartarusManager).ut$clean(world, spawnId, false); | ||
UTWootTicketManager.forceChunk(world, spawnId); | ||
} | ||
|
||
@WrapOperation(method = "tick", at = @At(value = "INVOKE", target = "Lipsis/woot/loot/schools/TartarusManager;freeSpawnBoxId(I)I")) | ||
private int ut$cleanupOnFree(TartarusManager instance, int id, Operation<Integer> original, ITickTracker tickTracker, World world) | ||
{ | ||
int oldSpawnId = spawnId; | ||
((ITartarusCleaner) Woot.tartarusManager).ut$clean(world, oldSpawnId, true); | ||
spawnId = original.call(instance, oldSpawnId); | ||
UTWootTicketManager.releaseChunk(oldSpawnId); | ||
return spawnId; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/mod/acgaming/universaltweaks/mods/woot/mixin/UTWootMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package mod.acgaming.universaltweaks.mods.woot.mixin; | ||
|
||
import net.minecraftforge.common.ForgeChunkManager; | ||
|
||
import ipsis.Woot; | ||
import mod.acgaming.universaltweaks.mods.woot.UTWootTicketManager; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
// Courtesy of jchung01 | ||
@Mixin(value = Woot.class, remap = false) | ||
public class UTWootMixin | ||
{ | ||
@Inject(method = "postInit", at = @At(value = "TAIL")) | ||
private void utRegisterTicketCallback(CallbackInfo ci) | ||
{ | ||
ForgeChunkManager.setForcedChunkLoadingCallback(Woot.instance, UTWootTicketManager::callback); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"package": "mod.acgaming.universaltweaks.mods.woot.mixin", | ||
"refmap": "universaltweaks.refmap.json", | ||
"minVersion": "0.8", | ||
"compatibilityLevel": "JAVA_8", | ||
"mixins": ["UTEntitySpawnerMixin", "UTTartarusManagerMixin", "UTTartarusSchoolMixin", "UTWootMixin"] | ||
} |