Skip to content

Commit

Permalink
Fixes some issues trying to load models and textures from custom loca…
Browse files Browse the repository at this point in the history
…tions

this should fix some problems with attempting to make custom data/resourcepacks, and having to put the models all in with the normal ones.
  • Loading branch information
Thutmose committed Jan 3, 2023
1 parent fe9f545 commit 0b9ac78
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main/java/pokecube/api/data/PokedexEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,8 @@ private static void addFromEvolution(final PokedexEntry a, final PokedexEntry b)

@CopyToGender
public String texturePath = PokedexEntry.TEXTUREPATH;
@CopyToGender
public String modelPath = PokedexEntry.MODELPATH;

@CopyToGender
public PokeType type1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ public FormeHolder getForme(final PokedexEntry baseEntry)
c.material = ThutCore.trim(c.material);
this._matsMap_.put(c.material, c);
}
String tex = PokedexEntry.TEXTUREPATH;
String model = PokedexEntry.MODELPATH;
String model = baseEntry.modelPath;

String modid = baseEntry.getModId();
if (modid == null) modid = "pokecube_mobs";
if (!baseEntry.texturePath.contains(":")) baseEntry.texturePath = modid + ":" + baseEntry.texturePath;
String tex = baseEntry.texturePath;

ResourceLocation texl = this.tex != null ? PokecubeItems.toResource(tex + this.tex, modid) : null;
ResourceLocation modell = this.model != null ? PokecubeItems.toResource(model + this.model, modid) : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ public void init()
boolean noUpdate = this.wrapper != null && this.wrapper.lastInit > Tracker.instance().getTick()
&& this.wrapper.lastInit - Tracker.instance().getTick() < 100;
if (noUpdate) return;
if (ThutCore.conf.debug_models) PokecubeAPI.logDebug("Reloaded model for " + entry);
RenderPokemob.holders.put(this.entry, this);
this.toRun.clear();
this.toRunNames.clear();
Expand Down Expand Up @@ -482,7 +483,6 @@ public void render(final Mob entity, final float entityYaw, final float partialT
if (holder.wrapper == null || !holder.wrapper.isLoaded())
{
holder.init();
if (ThutCore.conf.debug_models) PokecubeAPI.logDebug("Reloaded model for " + entry);
}
if (holder.wrapper != null && !holder.wrapper.isLoaded())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,8 @@ private void initStage2(PokedexEntry entry)
String anim = this.anim_path;
if (anim == null) anim = model;
entry.texturePath = tex;
entry.modelPath = model;

entry.model = new ResourceLocation(this.modid, model + entry.getTrimmedName() + entry.modelExt);
entry.texture = new ResourceLocation(this.modid, tex + entry.getTrimmedName() + ".png");
entry.animation = new ResourceLocation(this.modid, anim + entry.getTrimmedName() + ".xml");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ public ResourceLocation getTexture()

String texName = entry.texturePath + entry.getTrimmedName();

if (!texName.contains(":")) texName = entry.getModId() + ":" + texName;

if (this.getCustomHolder() != null && this.getCustomHolder().texture != null)
texName = this.getCustomHolder().texture.toString();
texName = texName.replace(".png", "");
Expand Down Expand Up @@ -69,6 +71,9 @@ public ResourceLocation modifyTexture(ResourceLocation texture)
final int maxNum = this.entry.textureDetails.length * this.entry.textureDetails[0].length;
final ResourceLocation[] tex = new ResourceLocation[maxNum];
String base = this.getPokedexEntry().texturePath + texture.getPath();

if (!base.contains(":")) base = entry.getModId() + ":" + base;

if (base.endsWith(".png")) base = base.substring(0, base.length() - 4);
for (int i = 0; i < maxNum; i++)
{
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/pokecube/mobs/PokecubeMobs.java
Original file line number Diff line number Diff line change
Expand Up @@ -609,12 +609,14 @@ public void onPreCapture(final Pre evt)
@SubscribeEvent
public void RegisterPokemobsEvent(final RegisterPokemobsEvent.Register event)
{
final String tex = PokedexEntry.TEXTUREPATH;
final String model = PokedexEntry.MODELPATH;
final String modid = PokecubeMobs.MODID;
Database.getSortedFormes().forEach(entry -> {
if (!modid.equals(entry.getModId())) return;
entry.texturePath = modid + ":" + tex;
String tex = entry.texturePath;
String model = entry.modelPath;
entry.texturePath = tex;
if (!tex.contains(":")) entry.texturePath = modid + ":" + tex;
else tex = tex.split(":")[1];
entry.model = new ResourceLocation(modid, model + entry.getTrimmedName() + entry.modelExt);
entry.texture = new ResourceLocation(modid, tex + entry.getTrimmedName() + ".png");
entry.animation = new ResourceLocation(modid, model + entry.getTrimmedName() + ".xml");
Expand Down

0 comments on commit 0b9ac78

Please sign in to comment.