From 4bb56f85a5714f97e3104b8c269e597b454e1a48 Mon Sep 17 00:00:00 2001 From: citrons Date: Sun, 5 Nov 2023 15:55:48 -0600 Subject: formatting --- .../mondecitronne/homunculus/EntityHomunculus.java | 43 +++++------ .../homunculus/GameProfileFetcher.java | 84 ++++++++++++---------- .../com/mondecitronne/homunculus/Homunculus.java | 4 +- .../homunculus/client/RenderHomunculus.java | 14 ++-- .../homunculus/proxy/ClientProxy.java | 3 +- .../com/mondecitronne/homunculus/proxy/Proxy.java | 3 +- .../homunculus/proxy/ServerProxy.java | 2 +- .../mondecitronne/homunculus/skin/DefaultSkin.java | 2 +- .../homunculus/skin/FallbackSkin.java | 5 +- .../mondecitronne/homunculus/skin/HTTPSkin.java | 5 +- .../mondecitronne/homunculus/skin/PlayerSkin.java | 52 +++++++------- .../com/mondecitronne/homunculus/skin/Skin.java | 4 +- 12 files changed, 116 insertions(+), 105 deletions(-) diff --git a/src/main/java/com/mondecitronne/homunculus/EntityHomunculus.java b/src/main/java/com/mondecitronne/homunculus/EntityHomunculus.java index d74b905..548aa78 100644 --- a/src/main/java/com/mondecitronne/homunculus/EntityHomunculus.java +++ b/src/main/java/com/mondecitronne/homunculus/EntityHomunculus.java @@ -16,38 +16,39 @@ import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.world.World; public class EntityHomunculus extends EntityLiving { - private static final DataParameter SKIN_SOURCE = EntityDataManager.createKey(EntityHomunculus.class, DataSerializers.COMPOUND_TAG); - + private static final DataParameter SKIN_SOURCE = EntityDataManager.createKey(EntityHomunculus.class, + DataSerializers.COMPOUND_TAG); + private final Skin defaultSkin; private static final Skin FALLBACK_SKIN = new FallbackSkin(); private Skin skin; - + public EntityHomunculus(World world) { super(world); getDataManager().register(SKIN_SOURCE, new NBTTagCompound()); defaultSkin = new DefaultSkin(getUniqueID()); } - + @Override protected void entityInit() { super.entityInit(); } - + private boolean isPlayerProfileUpdated(GameProfile a, GameProfile b) { if (b == null || b.getName() == null) { return a != null; } else { - return !a.getName().toLowerCase().equals(b.getName().toLowerCase()) || - (b.getId() != null && a.getId() != null && !b.getId().equals(a.getId())); + return !a.getName().toLowerCase().equals(b.getName().toLowerCase()) + || (b.getId() != null && a.getId() != null && !b.getId().equals(a.getId())); } } - + private void dispatchFetchSkin() { if (this.getEntityWorld().isRemote && skin != null) { skin.dispatchFetch(); } } - + private void updateSkin() { NBTTagCompound sourceNBT = getDataManager().get(SKIN_SOURCE); if (sourceNBT.hasKey("Type")) { @@ -58,7 +59,8 @@ public class EntityHomunculus extends EntityLiving { skin = null; break; } - if (!(skin instanceof PlayerSkin) || isPlayerProfileUpdated(((PlayerSkin) skin).getPlayerProfile(), sourceProfile)) { + if (!(skin instanceof PlayerSkin) + || isPlayerProfileUpdated(((PlayerSkin) skin).getPlayerProfile(), sourceProfile)) { skin = new PlayerSkin(sourceProfile, getEntityWorld().isRemote); dispatchFetchSkin(); } @@ -84,7 +86,7 @@ public class EntityHomunculus extends EntityLiving { skin = null; } } - + public Skin getSkin() { updateSkin(); if (skin != null) { @@ -97,7 +99,7 @@ public class EntityHomunculus extends EntityLiving { return defaultSkin; } } - + @Override public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); @@ -113,7 +115,7 @@ public class EntityHomunculus extends EntityLiving { } } } - + @Override public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); @@ -122,13 +124,14 @@ public class EntityHomunculus extends EntityLiving { NBTTagCompound profileCompound = new NBTTagCompound(); NBTUtil.writeGameProfile(profileCompound, ((PlayerSkin) skin).getPlayerProfile()); NBTTagCompound sourceCompound = new NBTTagCompound(); - sourceCompound.setTag("Name", profileCompound.getTag("Name")); - if (profileCompound.hasKey("Id")) { - // save ID so that if a player changes their name, the skin is invalidated rather than pulling the skin of whoever takes the name - sourceCompound.setTag("Id", profileCompound.getTag("Id")); - } - sourceCompound.setString("Type", "player"); - compound.setTag("SkinSource", sourceCompound); + sourceCompound.setTag("Name", profileCompound.getTag("Name")); + if (profileCompound.hasKey("Id")) { + // save ID so that if a player changes their name, the skin is invalidated + // rather than pulling the skin of whoever takes the name + sourceCompound.setTag("Id", profileCompound.getTag("Id")); + } + sourceCompound.setString("Type", "player"); + compound.setTag("SkinSource", sourceCompound); } else if (skin instanceof HTTPSkin) { NBTTagCompound sourceCompound = new NBTTagCompound(); sourceCompound.setString("URL", ((HTTPSkin) skin).getUrl()); diff --git a/src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java b/src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java index 0651d34..3654c80 100644 --- a/src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java +++ b/src/main/java/com/mondecitronne/homunculus/GameProfileFetcher.java @@ -21,27 +21,30 @@ public class GameProfileFetcher { private static MinecraftSessionService sessionService; private static GameProfileRepository profileRepo; // there could be contention if thread pool has more than one thread - private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 1, 1L, TimeUnit.MINUTES, new LinkedBlockingQueue()); - + private static final ExecutorService THREAD_POOL = new ThreadPoolExecutor(0, 1, 1L, TimeUnit.MINUTES, + new LinkedBlockingQueue()); + private static final Map fetchersByName = Maps.newHashMap(); private static final Map fetchersById = Maps.newHashMap(); - + @Nullable private GameProfile profile; - - public static void init(File dataDir) { - YggdrasilAuthenticationService auth = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString()); - sessionService = auth.createMinecraftSessionService(); - profileRepo = auth.createProfileRepository(); - } - + + public static void init(File dataDir) { + YggdrasilAuthenticationService auth = new YggdrasilAuthenticationService(Proxy.NO_PROXY, + UUID.randomUUID().toString()); + sessionService = auth.createMinecraftSessionService(); + profileRepo = auth.createProfileRepository(); + } + private GameProfileFetcher(GameProfile profileIn) { dispatchFetchProfile(profileIn); } - + public static GameProfileFetcher fetchProfile(GameProfile profile) { if (profile.getId() != null && fetchersById.containsKey(profile.getId())) { - // if the profile specifies an ID, ensure that the fetcher with the correct ID returns, as it will reject a profile with the wrong ID + // if the profile specifies an ID, ensure that the fetcher with the correct ID + // returns, as it will reject a profile with the wrong ID return fetchersById.get(profile.getId()); } else if (fetchersByName.containsKey(profile.getName())) { return fetchersByName.get(profile.getName()); @@ -54,34 +57,37 @@ public class GameProfileFetcher { return fetcher; } } - + @Nullable public synchronized GameProfile getGameProfile() { - return profile; + return profile; + } + + private void dispatchFetchProfile(GameProfile profileIn) { + THREAD_POOL.submit(new Runnable() { + public void run() { + class LocalCallback implements ProfileLookupCallback { + public GameProfile fetched; + + public void onProfileLookupSucceeded(GameProfile success) { + fetched = success; + } + + public void onProfileLookupFailed(GameProfile failed, Exception exception) { + fetched = null; + } + } + ; + LocalCallback callback = new LocalCallback(); + profileRepo.findProfilesByNames(new String[] { profileIn.getName() }, Agent.MINECRAFT, callback); + + GameProfile fetched = sessionService.fillProfileProperties(callback.fetched, false); + if (profileIn.getId() == null || fetched.getId().equals(profileIn.getId())) { + synchronized (this) { + profile = fetched; + } + } + } + }); } - - private void dispatchFetchProfile(GameProfile profileIn) { - THREAD_POOL.submit(new Runnable() { - public void run() { - class LocalCallback implements ProfileLookupCallback { - public GameProfile fetched; - public void onProfileLookupSucceeded(GameProfile success) { - fetched = success; - } - public void onProfileLookupFailed(GameProfile failed, Exception exception) { - fetched = null; - } - }; - LocalCallback callback = new LocalCallback(); - profileRepo.findProfilesByNames(new String[] {profileIn.getName()}, Agent.MINECRAFT, callback); - - GameProfile fetched = sessionService.fillProfileProperties(callback.fetched, false); - if (profileIn.getId() == null || fetched.getId().equals(profileIn.getId())) { - synchronized (this) { - profile = fetched; - } - } - } - }); - } } diff --git a/src/main/java/com/mondecitronne/homunculus/Homunculus.java b/src/main/java/com/mondecitronne/homunculus/Homunculus.java index a354e60..663e872 100644 --- a/src/main/java/com/mondecitronne/homunculus/Homunculus.java +++ b/src/main/java/com/mondecitronne/homunculus/Homunculus.java @@ -44,9 +44,9 @@ public class Homunculus { public File getDataDir() { return dataDir; } - + public void putDataDirIn(File dir) { - assert(dataDir == null); + assert (dataDir == null); dataDir = new File(dir, MODID + "_data"); dataDir.mkdir(); } diff --git a/src/main/java/com/mondecitronne/homunculus/client/RenderHomunculus.java b/src/main/java/com/mondecitronne/homunculus/client/RenderHomunculus.java index 159602a..804cf85 100644 --- a/src/main/java/com/mondecitronne/homunculus/client/RenderHomunculus.java +++ b/src/main/java/com/mondecitronne/homunculus/client/RenderHomunculus.java @@ -14,29 +14,29 @@ import net.minecraft.util.ResourceLocation; public class RenderHomunculus extends RenderLivingBase { public static final Factory FACTORY = new Factory(); private final Map modelTypes = Maps.newHashMap(); - - public RenderHomunculus(RenderManager rendermanagerIn) { + + public RenderHomunculus(RenderManager rendermanagerIn) { super(rendermanagerIn, new ModelPlayer(0.0F, false), 0.5F); modelTypes.put("default", new ModelPlayer(0.0F, false)); - modelTypes.put("slim", new ModelPlayer(0.0F, true)); + modelTypes.put("slim", new ModelPlayer(0.0F, true)); } - + @Nonnull public String getModelType(EntityHomunculus entity) { return "default"; } - + @Override protected ResourceLocation getEntityTexture(@Nonnull EntityHomunculus entity) { return entity.getSkin().getTexture(); } - + @Override public void doRender(EntityHomunculus entity, double x, double y, double z, float entityYaw, float partialTicks) { mainModel = modelTypes.get(entity.getSkin().getModelType()); super.doRender(entity, x, y, z, entityYaw, partialTicks); } - + @Override protected boolean canRenderName(EntityHomunculus entity) { return super.canRenderName(entity) && entity.hasCustomName(); diff --git a/src/main/java/com/mondecitronne/homunculus/proxy/ClientProxy.java b/src/main/java/com/mondecitronne/homunculus/proxy/ClientProxy.java index 906a08f..c8d074e 100644 --- a/src/main/java/com/mondecitronne/homunculus/proxy/ClientProxy.java +++ b/src/main/java/com/mondecitronne/homunculus/proxy/ClientProxy.java @@ -18,7 +18,7 @@ public class ClientProxy extends Proxy { public void preInit(FMLPreInitializationEvent e) { super.preInit(e); RenderingRegistry.registerEntityRenderingHandler(EntityHomunculus.class, RenderHomunculus.FACTORY); - + Homunculus.instance.putDataDirIn(Minecraft.getMinecraft().gameDir); GameProfileFetcher.init(Homunculus.instance.getDataDir()); } @@ -27,4 +27,3 @@ public class ClientProxy extends Proxy { public static void registerModels(ModelRegistryEvent event) { } } - diff --git a/src/main/java/com/mondecitronne/homunculus/proxy/Proxy.java b/src/main/java/com/mondecitronne/homunculus/proxy/Proxy.java index a243838..9ec06f2 100644 --- a/src/main/java/com/mondecitronne/homunculus/proxy/Proxy.java +++ b/src/main/java/com/mondecitronne/homunculus/proxy/Proxy.java @@ -16,7 +16,8 @@ import com.mondecitronne.homunculus.Homunculus; @Mod.EventBusSubscriber public class Proxy { public void preInit(FMLPreInitializationEvent e) { - EntityRegistry.registerModEntity(new ResourceLocation(Homunculus.MODID, "homunculus"), EntityHomunculus.class, "homunculus", 0, Homunculus.instance, 64, 3, true); + EntityRegistry.registerModEntity(new ResourceLocation(Homunculus.MODID, "homunculus"), EntityHomunculus.class, + "homunculus", 0, Homunculus.instance, 64, 3, true); } public void init(FMLInitializationEvent e) { diff --git a/src/main/java/com/mondecitronne/homunculus/proxy/ServerProxy.java b/src/main/java/com/mondecitronne/homunculus/proxy/ServerProxy.java index f017f03..9ff221f 100644 --- a/src/main/java/com/mondecitronne/homunculus/proxy/ServerProxy.java +++ b/src/main/java/com/mondecitronne/homunculus/proxy/ServerProxy.java @@ -9,7 +9,7 @@ public class ServerProxy extends Proxy { @Override public void preInit(FMLPreInitializationEvent e) { super.preInit(e); - Homunculus.instance.putDataDirIn(FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory()); + Homunculus.instance.putDataDirIn(FMLCommonHandler.instance().getMinecraftServerInstance().getDataDirectory()); GameProfileFetcher.init(Homunculus.instance.getDataDir()); } } diff --git a/src/main/java/com/mondecitronne/homunculus/skin/DefaultSkin.java b/src/main/java/com/mondecitronne/homunculus/skin/DefaultSkin.java index 0dbab38..cb60087 100644 --- a/src/main/java/com/mondecitronne/homunculus/skin/DefaultSkin.java +++ b/src/main/java/com/mondecitronne/homunculus/skin/DefaultSkin.java @@ -7,7 +7,7 @@ import net.minecraft.util.ResourceLocation; public class DefaultSkin extends Skin { private final UUID id; - + public DefaultSkin(UUID id) { this.id = id; } diff --git a/src/main/java/com/mondecitronne/homunculus/skin/FallbackSkin.java b/src/main/java/com/mondecitronne/homunculus/skin/FallbackSkin.java index d36b4d6..4050208 100644 --- a/src/main/java/com/mondecitronne/homunculus/skin/FallbackSkin.java +++ b/src/main/java/com/mondecitronne/homunculus/skin/FallbackSkin.java @@ -5,8 +5,9 @@ import com.mondecitronne.homunculus.Homunculus; import net.minecraft.util.ResourceLocation; public class FallbackSkin extends Skin { - static final ResourceLocation FALLBACK_TEXTURE = new ResourceLocation(Homunculus.MODID, "textures/entity/homunculus_fallback.png"); - + static final ResourceLocation FALLBACK_TEXTURE = new ResourceLocation(Homunculus.MODID, + "textures/entity/homunculus_fallback.png"); + @Override public String getModelType() { return "default"; diff --git a/src/main/java/com/mondecitronne/homunculus/skin/HTTPSkin.java b/src/main/java/com/mondecitronne/homunculus/skin/HTTPSkin.java index 65fd895..7da0d86 100644 --- a/src/main/java/com/mondecitronne/homunculus/skin/HTTPSkin.java +++ b/src/main/java/com/mondecitronne/homunculus/skin/HTTPSkin.java @@ -7,16 +7,17 @@ import net.minecraft.util.ResourceLocation; public class HTTPSkin extends Skin { private final String url; private final String modelType; + public HTTPSkin(String skin_url, String modelType) { url = skin_url; this.modelType = modelType; } - + @Override public boolean isLoaded() { return false; } - + @Override @Nullable public String getModelType() { diff --git a/src/main/java/com/mondecitronne/homunculus/skin/PlayerSkin.java b/src/main/java/com/mondecitronne/homunculus/skin/PlayerSkin.java index 7964411..c6cbfdd 100644 --- a/src/main/java/com/mondecitronne/homunculus/skin/PlayerSkin.java +++ b/src/main/java/com/mondecitronne/homunculus/skin/PlayerSkin.java @@ -14,34 +14,34 @@ public class PlayerSkin extends Skin { private final GameProfileFetcher profileFetcher; private final boolean isRemote; boolean profileTexturesLoading; - - public PlayerSkin(GameProfile profile, boolean isRemote) { - this.profile = profile; - profileFetcher = GameProfileFetcher.fetchProfile(profile); - this.isRemote = isRemote; - profileTexturesLoading = false; - } - - @Override - public boolean isLoaded() { - if (this.isRemote) { - return getTexture() != null && getModelType() != null; - } else { - return profileFetcher.getGameProfile() != null; - } - } + + public PlayerSkin(GameProfile profile, boolean isRemote) { + this.profile = profile; + profileFetcher = GameProfileFetcher.fetchProfile(profile); + this.isRemote = isRemote; + profileTexturesLoading = false; + } + + @Override + public boolean isLoaded() { + if (this.isRemote) { + return getTexture() != null && getModelType() != null; + } else { + return profileFetcher.getGameProfile() != null; + } + } public GameProfile getPlayerProfile() { - GameProfile fetchProfile = profileFetcher.getGameProfile(); - if (fetchProfile != null) { - return fetchProfile; - } else { - return profile; - } + GameProfile fetchProfile = profileFetcher.getGameProfile(); + if (fetchProfile != null) { + return fetchProfile; + } else { + return profile; + } } protected MinecraftProfileTexture getProfileTexture() { - assert(this.isRemote); + assert (this.isRemote); GameProfile playerProfile = profileFetcher.getGameProfile(); if (playerProfile != null) { Minecraft minecraft = Minecraft.getMinecraft(); @@ -62,7 +62,7 @@ public class PlayerSkin extends Skin { @Override public String getModelType() { - assert(this.isRemote); + assert (this.isRemote); if (getTexture() != null) { MinecraftProfileTexture tex = getProfileTexture(); if (tex != null) { @@ -71,11 +71,11 @@ public class PlayerSkin extends Skin { } return null; } - + @Override @Nullable public ResourceLocation getTexture() { - assert(this.isRemote); + assert (this.isRemote); MinecraftProfileTexture tex = getProfileTexture(); if (tex != null) { ResourceLocation location = Minecraft.getMinecraft().getSkinManager().loadSkin(tex, Type.SKIN); diff --git a/src/main/java/com/mondecitronne/homunculus/skin/Skin.java b/src/main/java/com/mondecitronne/homunculus/skin/Skin.java index da798fa..7da3385 100644 --- a/src/main/java/com/mondecitronne/homunculus/skin/Skin.java +++ b/src/main/java/com/mondecitronne/homunculus/skin/Skin.java @@ -7,13 +7,13 @@ public abstract class Skin { public boolean isLoaded() { return true; } - + public void dispatchFetch() { } @Nullable abstract public String getModelType(); - + @Nullable abstract public ResourceLocation getTexture(); } -- cgit v1.2.3