Update TextureStitchEvent.Pre to give access to the list of ResourceLocations that will be loaded as textures. (#5870)

This commit is contained in:
primetoxinz 2019-07-03 15:26:51 -04:00 committed by LexManos
parent bc23c1ddb2
commit 765efc3c72
3 changed files with 35 additions and 17 deletions

View file

@ -1,6 +1,6 @@
--- a/net/minecraft/client/renderer/texture/AtlasTexture.java
+++ b/net/minecraft/client/renderer/texture/AtlasTexture.java
@@ -79,10 +79,12 @@
@@ -79,6 +79,7 @@
}
}
@ -8,11 +8,14 @@
}
public AtlasTexture.SheetData func_215254_a(IResourceManager p_215254_1_, Iterable<ResourceLocation> p_215254_2_, IProfiler p_215254_3_) {
Set<ResourceLocation> set = Sets.newHashSet();
+ net.minecraftforge.client.ForgeHooksClient.onTextureStitchedPre(this);
p_215254_3_.func_76320_a("preparing");
p_215254_2_.forEach((p_215253_1_) -> {
if (p_215253_1_ == null) {
@@ -91,6 +92,7 @@
set.add(p_215253_1_);
}
});
+ net.minecraftforge.client.ForgeHooksClient.onTextureStitchedPre(this, set);
int i = this.field_215265_o;
Stitcher stitcher = new Stitcher(i, i, this.field_147636_j);
int j = Integer.MAX_VALUE;
@@ -110,6 +112,7 @@
int i1 = Math.min(j, k);
@ -29,15 +32,14 @@
try {
iresource = p_195422_1_.func_199002_a(resourcelocation);
p_195422_2_.func_195664_a(iresource, this.field_147636_j + 1);
@@ -267,7 +271,94 @@
this.field_94252_e.clear();
@@ -268,6 +272,93 @@
this.field_94258_i.clear();
}
+
+ //===================================================================================================
+ // Forge Start
+ //===================================================================================================
+
+ private final java.util.Deque<ResourceLocation> loadingSprites = new java.util.ArrayDeque<>();
+ private final java.util.Set<ResourceLocation> loadedSprites = new java.util.HashSet<>();
+

View file

@ -31,6 +31,7 @@ import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.Optional;
import java.util.Random;
@ -178,9 +179,9 @@ public class ForgeHooksClient
return MinecraftForge.EVENT_BUS.post(new RenderSpecificHandEvent(hand, partialTicks, interpPitch, swingProgress, equipProgress, stack));
}
public static void onTextureStitchedPre(AtlasTexture map)
public static void onTextureStitchedPre(AtlasTexture map, Set<ResourceLocation> resourceLocations)
{
ModLoader.get().postEvent(new TextureStitchEvent.Pre(map));
ModLoader.get().postEvent(new TextureStitchEvent.Pre(map, resourceLocations));
// ModelLoader.White.INSTANCE.register(map); // TODO Custom TAS
ModelDynBucket.LoaderDynBucket.INSTANCE.register(map);
}

View file

@ -19,9 +19,12 @@
package net.minecraftforge.client.event;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.eventbus.api.Event;
import net.minecraft.client.renderer.texture.AtlasTexture;
import java.util.Set;
public class TextureStitchEvent extends Event
{
@ -38,17 +41,29 @@ public class TextureStitchEvent extends Event
}
/**
* Fired when the TextureMap is told to refresh it's stitched texture.
* Called after the Stitched list is cleared, but before any blocks or items
* add themselves to the list.
* Fired when the TextureMap is told to refresh it's stitched texture.
* Called before the {@link net.minecraft.client.renderer.texture.TextureAtlasSprite} are loaded.
*/
public static class Pre extends TextureStitchEvent
{
public Pre(AtlasTexture map){ super(map); }
private final Set<ResourceLocation> sprites;
public Pre(AtlasTexture map, Set<ResourceLocation> sprites)
{
super(map);
this.sprites = sprites;
}
/**
* Add a sprite to be stitched into the Texture Atlas.
*/
public boolean addSprite(ResourceLocation sprite) {
return this.sprites.add(sprite);
}
}
/**
* This event is fired once the texture map has loaded all textures and
* This event is fired once the texture map has loaded all textures and
* stitched them together. All Icons should have there locations defined
* by the time this is fired.
*/