Skip to content

Commit

Permalink
start moving species backend over to stacked textures
Browse files Browse the repository at this point in the history
  • Loading branch information
parzivail committed Feb 1, 2021
1 parent 3397085 commit c5a9694
Show file tree
Hide file tree
Showing 83 changed files with 379 additions and 170 deletions.
129 changes: 58 additions & 71 deletions src/main/java/com/parzivail/pswg/Galaxies.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
package com.parzivail.pswg.client.species;

import com.parzivail.pswg.Client;
import com.parzivail.pswg.client.model.npc.*;
import com.parzivail.pswg.container.SwgSpecies;
import com.parzivail.pswg.container.SwgSpeciesRegistry;
import com.parzivail.pswg.species.SwgSpecies;
import net.minecraft.util.Identifier;

import java.util.HashMap;

public class SwgSpeciesModels
{
private static final HashMap<Integer, Identifier> TEXTURE_CACHE = new HashMap<>();

public static final HashMap<Identifier, SwgSpeciesModel> MODELS = new HashMap<>();

static
{
// register(new SwgSpeciesModel(SwgSpecies.SPECIES_AQUALISH_M, new ModelAqualish<>(true, 0)));
// register(new SwgSpeciesModel(SwgSpecies.SPECIES_AQUALISH_F, new ModelAqualish<>(false, 0)));
register(new SwgSpeciesModel(SwgSpecies.SPECIES_BITH_M, new ModelBith<>(true, 0)));
register(new SwgSpeciesModel(SwgSpecies.SPECIES_BITH_F, new ModelBith<>(false, 0)));
register(new SwgSpeciesModel(SwgSpeciesRegistry.SPECIES_BITH_M, new ModelBith<>(true, 0)));
register(new SwgSpeciesModel(SwgSpeciesRegistry.SPECIES_BITH_F, new ModelBith<>(false, 0)));
// register(new SwgSpeciesModel(SwgSpecies.SPECIES_BOTHAN_M, new ModelBothan<>(true, 0)));
// register(new SwgSpeciesModel(SwgSpecies.SPECIES_BOTHAN_F, new ModelBothan<>(false, 0)));
register(new SwgSpeciesModel(SwgSpecies.SPECIES_CHAGRIAN_M, new ModelChagrian<>(true, 0)));
register(new SwgSpeciesModel(SwgSpecies.SPECIES_CHAGRIAN_F, new ModelChagrian<>(false, 0)));
register(new SwgSpeciesModel(SwgSpeciesRegistry.SPECIES_CHAGRIAN_M, new ModelChagrian<>(true, 0)));
register(new SwgSpeciesModel(SwgSpeciesRegistry.SPECIES_CHAGRIAN_F, new ModelChagrian<>(false, 0)));
// register(new SwgSpeciesModel(SwgSpecies.SPECIES_KAMINOAN_M, new ModelKaminoan<>(true, 0)));
// register(new SwgSpeciesModel(SwgSpecies.SPECIES_KAMINOAN_F, new ModelKaminoan<>(false, 0)));
register(new SwgSpeciesModel(SwgSpecies.SPECIES_TOGRUTA_M, new ModelTogrutaM<>(0)));
register(new SwgSpeciesModel(SwgSpecies.SPECIES_TOGRUTA_F, new ModelTogrutaF<>(0)));
register(new SwgSpeciesModel(SwgSpecies.SPECIES_JAWA, new ModelJawa<>(0)));
register(new SwgSpeciesModel(SwgSpecies.SPECIES_TWILEK_M, new ModelTwilek<>(true, 0)));
register(new SwgSpeciesModel(SwgSpecies.SPECIES_TWILEK_F, new ModelTwilek<>(false, 0)));
register(new SwgSpeciesModel(SwgSpeciesRegistry.SPECIES_TOGRUTA_M, new ModelTogrutaM<>(0)));
register(new SwgSpeciesModel(SwgSpeciesRegistry.SPECIES_TOGRUTA_F, new ModelTogrutaF<>(0)));
register(new SwgSpeciesModel(SwgSpeciesRegistry.SPECIES_JAWA, new ModelJawa<>(0)));
register(new SwgSpeciesModel(SwgSpeciesRegistry.SPECIES_TWILEK_M, new ModelTwilek<>(true, 0)));
register(new SwgSpeciesModel(SwgSpeciesRegistry.SPECIES_TWILEK_F, new ModelTwilek<>(false, 0)));
// register(new SwgSpeciesModel(SwgSpecies.SPECIES_WOOKIEE_M, new ModelWookiee<>(true, 0)));
// register(new SwgSpeciesModel(SwgSpecies.SPECIES_WOOKIEE_F, new ModelWookiee<>(false, 0)));
}
Expand All @@ -35,4 +39,13 @@ private static void register(SwgSpeciesModel model)
{
MODELS.put(model.identifier, model);
}

public static Identifier getTexture(SwgSpecies species)
{
int hashCode = species.hashCode();
if (!TEXTURE_CACHE.containsKey(hashCode))
TEXTURE_CACHE.put(hashCode, Client.stackedTextureProvider.loadTexture("species/" + hashCode, species.getTextureStack()));

return TEXTURE_CACHE.get(hashCode);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.util.Collection;

@Environment(EnvType.CLIENT)
public class StackedTexture extends ResourceTexture
Expand All @@ -22,10 +23,10 @@ public class StackedTexture extends ResourceTexture
private final Identifier[] textures;
private boolean loaded;

public StackedTexture(Identifier fallbackSkin, Identifier... textures)
public StackedTexture(Identifier fallbackSkin, Collection<Identifier> textures)
{
super(fallbackSkin);
this.textures = textures;
this.textures = textures.toArray(new Identifier[0]);
}

private void onTextureLoaded(NativeImage image)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.Util;

import java.util.Collection;

@Environment(EnvType.CLIENT)
public class StackedTextureProvider
{
Expand All @@ -23,7 +25,7 @@ public StackedTextureProvider(TextureManager textureManager, String identifierRo
this.identifierRoot = identifierRoot;
}

public Identifier loadTexture(String id, Identifier... textures)
public Identifier loadTexture(String id, Collection<Identifier> textures)
{
final Identifier identifier = new Identifier(identifierRoot + "/" + id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.parzivail.pswg.container.SwgSpecies;
import com.parzivail.pswg.container.SwgSpeciesRegistry;
import net.minecraft.command.CommandSource;
import net.minecraft.util.Identifier;

Expand All @@ -23,7 +23,7 @@ public Identifier parse(StringReader stringReader) throws CommandSyntaxException
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder)
{
return context.getSource() instanceof CommandSource ? CommandSource.suggestIdentifiers(SwgSpecies.SPECIES.stream(), builder) : Suggestions.empty();
return context.getSource() instanceof CommandSource ? CommandSource.suggestIdentifiers(SwgSpeciesRegistry.SPECIES.stream(), builder) : Suggestions.empty();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.parzivail.pswg.container.SwgSpecies;
import com.parzivail.pswg.container.SwgSpeciesRegistry;
import net.minecraft.command.CommandSource;
import net.minecraft.util.Identifier;

Expand Down Expand Up @@ -37,11 +37,11 @@ public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> cont
{
Identifier species = context.getArgument("species", Identifier.class);

if (!SwgSpecies.SPECIES.contains(species))
if (!SwgSpeciesRegistry.SPECIES.contains(species))
{
return Suggestions.empty();
}

return context.getSource() instanceof CommandSource ? CommandSource.suggestMatching(SwgSpecies.VARIANTS.get(species), builder) : Suggestions.empty();
return context.getSource() instanceof CommandSource ? CommandSource.suggestMatching(SwgSpeciesRegistry.VARIANTS.get(species), builder) : Suggestions.empty();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.parzivail.pswg.component;

import com.parzivail.pswg.species.SwgSpeciesInstance;
import com.parzivail.pswg.species.SwgSpecies;
import dev.onyxstudios.cca.api.v3.component.AutoSyncedComponent;
import dev.onyxstudios.cca.api.v3.component.ComponentV3;
import net.minecraft.entity.player.PlayerEntity;
Expand All @@ -20,18 +20,17 @@ public SwgPersistentComponents(PlayerEntity provider)
this.provider = provider;
}

public SwgSpeciesInstance getSpecies()
public SwgSpecies getSpecies()
{
return SwgSpeciesInstance.fromString(species);
// TODO
return null;
}

public void setSpecies(SwgSpeciesInstance species)
public void setSpecies(SwgSpecies species)
{
String speciesStr = "";
if (species != null)
speciesStr = species.toString();
// TODO

this.species = speciesStr;
this.species = "";
SwgEntityComponents.PERSISTENT.sync(provider, SPECIES_SYNCOP);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import java.util.ArrayList;
import java.util.HashMap;

public class SwgSpecies
public class SwgSpeciesRegistry
{
public static final ArrayList<Identifier> SPECIES = new ArrayList<>();
public static final HashMap<Identifier, String[]> VARIANTS = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.parzivail.pswg.mixin;

import com.parzivail.pswg.client.species.SwgSpeciesModels;
import com.parzivail.pswg.component.SwgEntityComponents;
import com.parzivail.pswg.component.SwgPersistentComponents;
import com.parzivail.pswg.species.SwgSpeciesInstance;
import com.parzivail.pswg.species.SwgSpecies;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.network.AbstractClientPlayerEntity;
Expand All @@ -22,11 +23,11 @@ private void getSkinTexture(CallbackInfoReturnable<Identifier> cir)
{
SwgPersistentComponents pc = SwgEntityComponents.getPersistent((PlayerEntity)(Object)this);

SwgSpeciesInstance species = pc.getSpecies();
SwgSpecies species = pc.getSpecies();
if (species == null)
return;

cir.setReturnValue(species.getTexture());
cir.setReturnValue(SwgSpeciesModels.getTexture(species));
cir.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.parzivail.pswg.client.species.SwgSpeciesModels;
import com.parzivail.pswg.component.SwgEntityComponents;
import com.parzivail.pswg.component.SwgPersistentComponents;
import com.parzivail.pswg.species.SwgSpeciesInstance;
import com.parzivail.pswg.species.SwgSpecies;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
Expand Down Expand Up @@ -50,11 +50,11 @@ private <T extends Entity> void getRenderer(T entity, CallbackInfoReturnable<Ent

SwgPersistentComponents pc = SwgEntityComponents.getPersistent((PlayerEntity)entity);

SwgSpeciesInstance species = pc.getSpecies();
SwgSpecies species = pc.getSpecies();
if (species == null)
return;

cir.setReturnValue((EntityRenderer<T>)modelRenderers.get(species.getModel().identifier.toString()));
cir.setReturnValue((EntityRenderer<T>)modelRenderers.get(species.getModel().toString()));
cir.cancel();
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/parzivail/pswg/species/SpeciesGender.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.parzivail.pswg.species;

import net.minecraft.util.Identifier;

public enum SpeciesGender
{
MALE("m"),
FEMALE("f");

private final String slug;

SpeciesGender(String slug)
{
this.slug = slug;
}

public String getSlug()
{
return slug;
}

public static SpeciesGender fromSlug(String genderedSlug)
{
String[] parts = genderedSlug.split("_", 2);

if (parts.length == 2 && parts[1].equals(FEMALE.slug))
return FEMALE;

return MALE;
}

public static Identifier toSlug(SwgSpecies species)
{
Identifier slug = species.getSlug();
SpeciesGender gender = species.getGender();
return new Identifier(slug.getNamespace(), slug.getPath() + '_' + gender.slug);
}
}
Loading

0 comments on commit c5a9694

Please sign in to comment.