-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add mixin to free memory of missing textures maps * fix allocation spam from IC2 Direction.applyTo method
- Loading branch information
Showing
4 changed files
with
91 additions
and
0 deletions.
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
38 changes: 38 additions & 0 deletions
38
src/main/java/com/mitchej123/hodgepodge/mixins/early/memory/MixinFMLClientHandler.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,38 @@ | ||
package com.mitchej123.hodgepodge.mixins.early.memory; | ||
|
||
import java.util.Set; | ||
|
||
import net.minecraft.util.ResourceLocation; | ||
|
||
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; | ||
|
||
import com.google.common.collect.HashBasedTable; | ||
import com.google.common.collect.HashMultimap; | ||
import com.google.common.collect.SetMultimap; | ||
import com.google.common.collect.Sets; | ||
import com.google.common.collect.Table; | ||
|
||
import cpw.mods.fml.client.FMLClientHandler; | ||
|
||
@Mixin(value = FMLClientHandler.class, remap = false) | ||
public class MixinFMLClientHandler { | ||
|
||
@Shadow | ||
private SetMultimap<String, ResourceLocation> missingTextures; | ||
@Shadow | ||
private Set<String> badTextureDomains; | ||
@Shadow | ||
private Table<String, String, Set<ResourceLocation>> brokenTextures; | ||
|
||
@Inject(method = "logMissingTextureErrors", at = @At("TAIL")) | ||
private void hodgepodge$freeMemory(CallbackInfo ci) { | ||
missingTextures = HashMultimap.create(); | ||
badTextureDomains = Sets.newHashSet(); | ||
brokenTextures = HashBasedTable.create(); | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/mitchej123/hodgepodge/mixins/late/ic2/MixinDirection_Memory.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,41 @@ | ||
package com.mitchej123.hodgepodge.mixins.late.ic2; | ||
|
||
import net.minecraft.tileentity.TileEntity; | ||
import net.minecraft.world.World; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Unique; | ||
|
||
import ic2.api.Direction; | ||
|
||
@Mixin(value = Direction.class, remap = false) | ||
public abstract class MixinDirection_Memory { | ||
|
||
/** | ||
* @author Alexdoru | ||
* @reason Reduce allocation spam | ||
*/ | ||
@Overwrite | ||
public TileEntity applyTo(World world, int x, int y, int z) { | ||
if (world == null) return null; | ||
return switch ((Direction) (Object) this) { | ||
case XN -> hodgepodge$getTE(world, x - 1, y, z); | ||
case XP -> hodgepodge$getTE(world, x + 1, y, z); | ||
case YN -> hodgepodge$getTE(world, x, y - 1, z); | ||
case YP -> hodgepodge$getTE(world, x, y + 1, z); | ||
case ZN -> hodgepodge$getTE(world, x, y, z - 1); | ||
case ZP -> hodgepodge$getTE(world, x, y, z + 1); | ||
}; | ||
} | ||
|
||
@Unique | ||
private TileEntity hodgepodge$getTE(World world, int x, int y, int z) { | ||
if (world.blockExists(x, y, z)) { | ||
return world.getTileEntity(x, y, z); | ||
} else { | ||
return null; | ||
} | ||
} | ||
|
||
} |