fix nullables and formatting

This commit is contained in:
Matthew Messinger 2017-06-12 23:55:50 -04:00
parent a411969a98
commit 370e8e3af3
25 changed files with 138 additions and 92 deletions

View file

@ -8,10 +8,8 @@ import com.google.common.collect.Maps;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.minecraft.InsecureTextureException;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import com.mojang.authlib.minecraft.MinecraftProfileTexture.Type;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import com.mojang.authlib.properties.Property;
import com.mojang.util.UUIDTypeAdapter;
import com.mumfrey.liteloader.core.LiteLoader;
@ -31,7 +29,7 @@ import org.apache.commons.io.FileUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.awt.*;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
@ -114,7 +112,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
}
private void loadTexture(GameProfile profile, final Type type, final SkinAvailableCallback callback) {
if (profile != null && profile.getId() != null) {
if (profile.getId() != null) {
Map<Type, MinecraftProfileTexture> data = loadProfileData(profile);
final MinecraftProfileTexture texture = data.get(type);
if (texture == null) {
@ -143,9 +141,7 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
if (imagebufferdownload != null) {
imagebufferdownload.skinAvailable();
}
if (callback != null) {
callback.skinAvailable(type, skin, texture);
}
callback.skinAvailable(type, skin, texture);
}
});
@ -179,26 +175,6 @@ public final class HDSkinManager implements IResourceManagerReloadListener {
});
}
private static Map<Type, MinecraftProfileTexture> getTexturesForProfile(GameProfile profile) {
LiteLoaderLogger.debug("Get textures for " + profile.getId());
Minecraft minecraft = Minecraft.getMinecraft();
MinecraftSessionService sessionService = minecraft.getSessionService();
Map<Type, MinecraftProfileTexture> textures;
try {
textures = sessionService.getTextures(profile, true);
} catch (InsecureTextureException var6) {
textures = sessionService.getTextures(profile, false);
}
if ((textures == null || textures.isEmpty())
&& profile.getId().equals(minecraft.getSession().getProfile().getId())) {
textures = sessionService.getTextures(sessionService.fillProfileProperties(profile, false), false);
}
return textures;
}
public void setSkinUrl(String skinUrl) {
this.skinUrl = skinUrl;
}

View file

@ -3,6 +3,7 @@ package com.voxelmodpack.hdskins;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
@FunctionalInterface
public interface ISkinModifier {
void convertSkin(BufferedImage skin, Graphics dest);

View file

@ -2,6 +2,7 @@ package com.voxelmodpack.hdskins;
import net.minecraft.client.renderer.IImageBuffer;
import javax.annotation.Nullable;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
@ -12,8 +13,9 @@ public class ImageBufferDownloadHD implements IImageBuffer {
private BufferedImage image;
@Override
@SuppressWarnings("SuspiciousNameCombination")
public BufferedImage parseUserSkin(BufferedImage downloadedImage) {
@Nullable
@SuppressWarnings({"SuspiciousNameCombination", "NullableProblems"})
public BufferedImage parseUserSkin(@Nullable BufferedImage downloadedImage) {
if (downloadedImage == null) {
return null;
}

View file

@ -4,11 +4,13 @@ import net.minecraft.client.renderer.IImageBuffer;
import net.minecraft.client.renderer.ThreadDownloadImageData;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nullable;
public class PreviewTexture extends ThreadDownloadImageData {
private boolean uploaded;
public PreviewTexture(String url, ResourceLocation fallbackTexture, IImageBuffer imageBuffer) {
public PreviewTexture(String url, ResourceLocation fallbackTexture, @Nullable IImageBuffer imageBuffer) {
super(null, url, fallbackTexture, imageBuffer);
}

View file

@ -11,6 +11,7 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
@FunctionalInterface
public interface FileDropListener extends DropTargetListener {
@Override

View file

@ -51,7 +51,7 @@ import static com.mojang.authlib.minecraft.MinecraftProfileTexture.Type.ELYTRA;
import static com.mojang.authlib.minecraft.MinecraftProfileTexture.Type.SKIN;
import static net.minecraft.client.renderer.GlStateManager.*;
public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpenFileCallback {
public class GuiSkins extends GuiScreen {
private static final int MAX_SKIN_DIMENSION = 8192;
private static final String skinServerId = "7853dfddc358333843ad55a2c7485c4aa0380a51";
private int updateCounter = 0;
@ -242,8 +242,7 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe
this.remotePlayer.releaseTextures();
}
@Override
public void onFileOpenDialogClosed(JFileChooser fileDialog, int dialogResult) {
private void onFileOpenDialogClosed(JFileChooser fileDialog, int dialogResult) {
this.openFileThread = null;
this.btnBrowse.enabled = true;
if (dialogResult == 0) {
@ -293,7 +292,7 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe
if (guiButton.id == this.btnBrowse.id) {
this.selectedSkin = null;
this.localPlayer.releaseTextures();
this.openFileThread = new ThreadOpenFilePNG(this.mc, I18n.format("hdskins.open.title"), this);
this.openFileThread = new ThreadOpenFilePNG(this.mc, I18n.format("hdskins.open.title"), this::onFileOpenDialogClosed);
this.openFileThread.start();
guiButton.enabled = false;
}
@ -673,14 +672,14 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe
public static boolean isPowerOfTwo(int number) {
return number != 0 && (number & number - 1) == 0;
}
private void clearUploadedSkin(Session session) {
if (this.registerServerConnection(session, skinServerId)) {
Map<String, ?> sourceData = getClearData(session);
this.uploadError = null;
this.uploadingSkin = true;
this.skinUploadMessage = I18n.format("hdskins.request");
this.threadSkinUpload = new ThreadMultipartPostUpload(HDSkinManager.INSTANCE.getGatewayUrl(), sourceData, this);
this.threadSkinUpload = new ThreadMultipartPostUpload(HDSkinManager.INSTANCE.getGatewayUrl(), sourceData, this::onUploadComplete);
this.threadSkinUpload.start();
}
}
@ -691,7 +690,7 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe
this.uploadError = null;
this.uploadingSkin = true;
this.skinUploadMessage = I18n.format("hdskins.upload");
this.threadSkinUpload = new ThreadMultipartPostUpload(HDSkinManager.INSTANCE.getGatewayUrl(), sourceData, this);
this.threadSkinUpload = new ThreadMultipartPostUpload(HDSkinManager.INSTANCE.getGatewayUrl(), sourceData, this::onUploadComplete);
this.threadSkinUpload.start();
}
}
@ -717,8 +716,7 @@ public class GuiSkins extends GuiScreen implements IUploadCompleteCallback, IOpe
this.btnUpload.enabled = true;
}
@Override
public void onUploadComplete(String response) {
private void onUploadComplete(String response) {
LiteLoaderLogger.info("Upload completed with: %s", response);
this.uploadingSkin = false;
this.threadSkinUpload = null;

View file

@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.voxelmodpack.hdskins.gui;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -12,6 +12,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import javax.annotation.Nullable;
import java.util.Optional;
@Mixin(TileEntitySkullRenderer.class)
@ -24,7 +25,7 @@ public abstract class MixinSkullRenderer extends TileEntitySpecialRenderer<TileE
target = "Lnet/minecraft/client/renderer/tileentity/TileEntitySkullRenderer;bindTexture(Lnet/minecraft/util/ResourceLocation;)V",
ordinal = 4))
private void onBindTexture(TileEntitySkullRenderer tesr, ResourceLocation rl, float x, float y, float z, EnumFacing facing, float rotation, int meta,
GameProfile profile, int p_180543_8_, float ticks) {
@Nullable GameProfile profile, int p_180543_8_, float ticks) {
if (profile != null) {
Optional<ResourceLocation> skin = HDSkinManager.INSTANCE.getSkinLocation(profile, Type.SKIN, true);
if (skin.isPresent())

View file

@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.voxelmodpack.hdskins.mixin;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.voxelmodpack.hdskins.mod;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.voxelmodpack.hdskins;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.voxelmodpack.hdskins.resource;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -1,5 +1,6 @@
package com.voxelmodpack.hdskins.upload;
@FunctionalInterface
public interface IUploadCompleteCallback {
void onUploadComplete(String response);
}

View file

@ -2,6 +2,7 @@ package com.voxelmodpack.hdskins.upload;
import com.google.common.io.Files;
import javax.annotation.Nullable;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
@ -39,7 +40,7 @@ public class ThreadMultipartPostUpload extends Thread {
public String response;
public ThreadMultipartPostUpload(String method, String url, Map<String, ?> sourceData, String authorization, IUploadCompleteCallback callback) {
public ThreadMultipartPostUpload(String method, String url, Map<String, ?> sourceData, @Nullable String authorization, IUploadCompleteCallback callback) {
this.method = method;
this.urlString = url;
this.sourceData = sourceData;

View file

@ -7,6 +7,7 @@ import javax.swing.JFileChooser;
*
* @author Adam Mummery-Smith
*/
@FunctionalInterface
public interface IOpenFileCallback {
/**

View file

@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.voxelmodpack.hdskins.upload.awt;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -0,0 +1,7 @@
@MethodsReturnNonnullByDefault
@ParametersAreNonnullByDefault
package com.voxelmodpack.hdskins.upload;
import mcp.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View file

@ -8,11 +8,13 @@ import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.ForgeHooksClient;
import javax.annotation.Nullable;
public class ForgeProxy {
private static boolean forgeLoaded = ModUtilities.fmlIsPresent();
public static String getArmorTexture(Entity entity, ItemStack armor, String def, EntityEquipmentSlot slot, String type) {
public static String getArmorTexture(Entity entity, ItemStack armor, String def, EntityEquipmentSlot slot, @Nullable String type) {
if (forgeLoaded)
return ForgeHooksClient.getArmorTexture(entity, armor, def, slot, type);
return def;

View file

@ -36,8 +36,6 @@ public class PonyConfig implements Exposable {
}
public void setPonyLevel(PonyLevel ponylevel) {
if (ponylevel == null)
ponylevel = PonyLevel.PONIES;
this.ponylevel = ponylevel;
}
}

View file

@ -27,10 +27,22 @@ public class PonyData implements IPonyData {
.build();
private PonyRace race;
private TailLengths tailSize = TailLengths.FULL;
private PonyGender gender = PonyGender.MARE;
private PonySize size = PonySize.NORMAL;
private int glowColor = 0x4444aa;
private TailLengths tailSize;
private PonyGender gender;
private PonySize size;
private int glowColor;
public PonyData() {
this(PonyRace.HUMAN, TailLengths.FULL, PonyGender.MARE, PonySize.NORMAL, 0x4444aa);
}
private PonyData(PonyRace race, TailLengths tailSize, PonyGender gender, PonySize size, int glowColor) {
this.race = race;
this.tailSize = tailSize;
this.gender = gender;
this.size = size;
this.glowColor = glowColor;
}
public PonyRace getRace() {
return race;
@ -77,28 +89,21 @@ public class PonyData implements IPonyData {
}
static PonyData parse(BufferedImage image) {
PonyData data = new PonyData();
int racePx = TriggerPixels.RACE.readColor(image);
PonyRace race = RACE_COLORS.getOrDefault(racePx, PonyRace.HUMAN);
int race = TriggerPixels.RACE.readColor(image);
data.race = RACE_COLORS.get(race);
int tailPx = TriggerPixels.TAIL.readColor(image);
TailLengths tail = TAIL_COLORS.getOrDefault(tailPx, TailLengths.FULL);
int tail = TriggerPixels.TAIL.readColor(image);
if (TAIL_COLORS.containsKey(tail))
data.tailSize = TAIL_COLORS.get(tail);
int sizePx = TriggerPixels.SIZE.readColor(image);
PonySize size = SIZE_COLORS.getOrDefault(sizePx, PonySize.NORMAL);
int gender = TriggerPixels.GENDER.readColor(image);
if (gender == 0xffffff)
data.gender = PonyGender.STALLION;
int genderPx = TriggerPixels.GENDER.readColor(image);
PonyGender gender = genderPx == 0xffffff ? PonyGender.STALLION : PonyGender.MARE;
int size = TriggerPixels.SIZE.readColor(image);
if (SIZE_COLORS.containsKey(size))
data.size = SIZE_COLORS.get(size);
int glowColor = TriggerPixels.GLOW.readColor(image, -1);
int color = TriggerPixels.GLOW.readColor(image);
if (color != 0x000000)
data.glowColor = color;
return data;
return new PonyData(race, tail, gender, size, glowColor);
}
private enum TriggerPixels {
@ -116,7 +121,11 @@ public class PonyData implements IPonyData {
}
private int readColor(BufferedImage image) {
return image.getRGB(x, y) & 0xffffff;
return readColor(image, 0xffffff);
}
private int readColor(BufferedImage image, int mask) {
return image.getRGB(x, y) & mask;
}
}
}

View file

@ -1,6 +1,8 @@
package com.minelittlepony;
public enum PonyRace {
HUMAN(false, false),
EARTH(false, false),
PEGASUS(true, false),
UNICORN(false, true),

View file

@ -2,6 +2,7 @@ package com.minelittlepony.mixin;
import com.minelittlepony.MineLittlePony;
import com.minelittlepony.Pony;
import com.minelittlepony.PonyRace;
import com.minelittlepony.PonySize;
import com.minelittlepony.ducks.IRenderPony;
import com.minelittlepony.model.PMAPI;
@ -28,6 +29,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import javax.annotation.Nonnull;
@Mixin(RenderPlayer.class)
public abstract class MixinRenderPlayer extends RenderLivingBase<AbstractClientPlayer> implements IRenderPony {
@ -68,20 +70,18 @@ public abstract class MixinRenderPlayer extends RenderLivingBase<AbstractClientP
this.playerModel.getModel().isFlying = thePony.isPegasusFlying(player);
this.playerModel.getModel().isSleeping = player.isPlayerSleeping();
if (MineLittlePony.getConfig().showscale) {
if (this.playerModel.getModel().metadata.getRace() != null) {
PonySize size = thePony.metadata.getSize();
if (size == PonySize.FOAL)
this.shadowSize = 0.25F;
else if (size == PonySize.NORMAL)
this.shadowSize = 0.4F;
else if (size == PonySize.TALL)
this.shadowSize = 0.45F;
else
this.shadowSize = 0.5F;
if (MineLittlePony.getConfig().showscale && this.playerModel.getModel().metadata.getRace() != PonyRace.HUMAN) {
PonySize size = thePony.metadata.getSize();
if (size == PonySize.FOAL) {
this.shadowSize = 0.25F;
} else if (size == PonySize.NORMAL) {
this.shadowSize = 0.4F;
} else if (size == PonySize.TALL) {
this.shadowSize = 0.45F;
} else {
this.shadowSize = 0.5F;
}
} else {
this.shadowSize = 0.5F;
}
@ -95,10 +95,11 @@ public abstract class MixinRenderPlayer extends RenderLivingBase<AbstractClientP
if (MineLittlePony.getConfig().showscale && !(playerModel.getModel() instanceof ModelHumanPlayer)) {
PonySize size = thePony.metadata.getSize();
if (size == PonySize.LARGE)
if (size == PonySize.LARGE) {
GlStateManager.scale(0.9F, 0.9F, 0.9F);
else if (size == PonySize.NORMAL || size == PonySize.FOAL)
} else if (size == PonySize.NORMAL || size == PonySize.FOAL) {
GlStateManager.scale(0.8F, 0.8F, 0.8F);
}
}
}
@ -194,10 +195,12 @@ public abstract class MixinRenderPlayer extends RenderLivingBase<AbstractClientP
}
}
if (angle > Math.PI / 3)
if (angle > Math.PI / 3) {
angle = Math.PI / 3;
if (angle < -Math.PI / 3)
}
if (angle < -Math.PI / 3) {
angle = -Math.PI / 3;
}
this.playerModel.getModel().motionPitch = (float) Math.toDegrees(angle);
@ -214,12 +217,14 @@ public abstract class MixinRenderPlayer extends RenderLivingBase<AbstractClientP
ordinal = 3))
private void rotateRedirect(float f1, float f2, float f3, float f4) {
boolean isPony = this.playerModel.getModel() instanceof ModelPlayerPony;
if (isPony)
if (isPony) {
f1 += 90;
}
GlStateManager.rotate(f1, f2, f3, f4);
if (isPony)
if (isPony) {
GlStateManager.translate(0, -1, 0);
}
}
private void updateModel(AbstractClientPlayer player) {
@ -232,6 +237,7 @@ public abstract class MixinRenderPlayer extends RenderLivingBase<AbstractClientP
}
@Override
@Nonnull
public ResourceLocation getEntityTexture(AbstractClientPlayer player) {
Pony thePony = MineLittlePony.getInstance().getManager().getPonyFromResourceRegistry(player);
return thePony.getTextureResourceLocation();

View file

@ -129,7 +129,7 @@ public class PegasusWings extends ModelBase implements PonyModelConstants {
@Override
public void render(Entity entityIn, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch, float scale) {
if (pony.metadata.getRace() != null && pony.metadata.getRace().hasWings()) {
if (pony.metadata.getRace().hasWings()) {
if (!pony.isFlying && !pony.isSneak) {
for (ModelRenderer aLeftWing : this.leftWing) {

View file

@ -38,7 +38,7 @@ public class UnicornHorn extends ModelBase implements PonyModelConstants {
PonyData data = pony.metadata;
if (data.getRace() != null && data.getRace().hasHorn()) {
if (data.getRace().hasHorn()) {
this.horn.render(scale);
if ((pony.leftArmPose != ArmPose.EMPTY || pony.rightArmPose != ArmPose.EMPTY) && data.hasMagic()) {
GL11.glPushAttrib(24577);

View file

@ -10,14 +10,10 @@ public class HornGlowRenderer extends ModelRenderer {
private int textureOffsetX;
private int textureOffsetY;
private ModelBase baseModel;
public HornGlowRenderer(ModelBase par1ModelBase, String par2Str) {
super(par1ModelBase, par2Str);
this.baseModel = par1ModelBase;
}
public HornGlowRenderer(ModelBase par1ModelBase) {
this(par1ModelBase, null);
super(par1ModelBase);
this.baseModel = par1ModelBase;
}
public HornGlowRenderer(ModelBase par1ModelBase, int par2, int par3) {