Skip to content

Commit

Permalink
clean up imports
Browse files Browse the repository at this point in the history
  • Loading branch information
BraggestSage833 committed Aug 21, 2021
1 parent b9202ac commit 8320595
Show file tree
Hide file tree
Showing 69 changed files with 815 additions and 860 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
import gregtech.api.GTValues;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IElectricItem;
import gregtech.api.items.armor.ArmorMetaItem;
import gregtech.api.items.armor.ArmorUtils;
import gregtech.api.items.armor.QuarkTechSuite;
import gregtech.api.util.GTUtility;
import gregtech.api.util.input.EnumKey;
import gregtech.common.items.MetaItems;
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/gregtech/api/items/armor/ArmorLogicSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
import com.google.common.collect.Multimap;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IElectricItem;
import gregtech.api.items.armor.ArmorMetaItem;
import gregtech.api.items.armor.ArmorMetaItem.ArmorMetaValueItem;
import gregtech.api.items.armor.ISpecialArmorLogic;
import gregtech.api.items.metaitem.ElectricStats;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
Expand Down
16 changes: 10 additions & 6 deletions src/main/java/gregtech/api/items/armor/ArmorMetaItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.google.common.base.Preconditions;
import com.google.common.collect.Multimap;
import com.google.common.collect.Streams;
import gregtech.api.items.metaitem.MetaItem;
import gregtech.api.items.metaitem.stats.IEnchantabilityHelper;
import gregtech.api.items.metaitem.stats.IItemComponent;
Expand Down Expand Up @@ -94,7 +93,7 @@ public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
public boolean isValidArmor(ItemStack stack, EntityEquipmentSlot armorType, Entity entity) {
IArmorLogic armorLogic = getArmorLogic(stack);
return super.isValidArmor(stack, armorType, entity) &&
armorLogic.isValidArmor(stack, entity, armorType);
armorLogic.isValidArmor(stack, entity, armorType);
}

@Nullable
Expand Down Expand Up @@ -139,10 +138,14 @@ public void renderHelmetOverlay(ItemStack stack, EntityPlayer player, ScaledReso

private static EntityEquipmentSlot getSlotByIndex(int index) {
switch (index) {
case 0: return EntityEquipmentSlot.FEET;
case 1: return EntityEquipmentSlot.LEGS;
case 2: return EntityEquipmentSlot.CHEST;
default: return EntityEquipmentSlot.HEAD;
case 0:
return EntityEquipmentSlot.FEET;
case 1:
return EntityEquipmentSlot.LEGS;
case 2:
return EntityEquipmentSlot.CHEST;
default:
return EntityEquipmentSlot.HEAD;
}
}

Expand Down Expand Up @@ -174,6 +177,7 @@ public ArmorMetaValueItem addComponents(IItemComponent... stats) {
return this;
}
}

@Override
public boolean isEnchantable(ItemStack stack) {
return true;
Expand Down
92 changes: 46 additions & 46 deletions src/main/java/gregtech/api/items/armor/ISpecialArmorLogic.java
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
package gregtech.api.items.armor;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.ISpecialArmor.ArmorProperties;

import javax.annotation.Nonnull;

/**
* Armor logic that wraps {@link net.minecraftforge.common.ISpecialArmor} methods
* to allow full control over damage absorption additionally to vanilla attribute values
*/
public interface ISpecialArmorLogic extends IArmorLogic {

/**
* Retrieves the modifiers to be used when calculating armor damage.
*
* Armor will higher priority will have damage applied to them before
* lower priority ones. If there are multiple pieces of armor with the
* same priority, damage will be distributed between them based on there
* absorption ratio.
*/
ArmorProperties getProperties(EntityLivingBase player, @Nonnull ItemStack armor, DamageSource source, double damage, EntityEquipmentSlot equipmentSlot);

/**
* Get the displayed effective armor.
*
* @return The number of armor points for display, 2 per shield.
*/
int getArmorDisplay(EntityPlayer player, @Nonnull ItemStack armor, int slot);

/**
* Simple check to see if the armor should interact with "Unblockable" damage
* sources. A fair number of vanilla damage sources have this tag, such as
* Anvils, Falling, Fire, and Magic.
*
* Returning true here means that the armor is able to meaningfully respond
* to this damage source. Otherwise, no interaction is allowed.
*/
default boolean handleUnblockableDamage(EntityLivingBase entity, @Nonnull ItemStack armor, DamageSource source, double damage, EntityEquipmentSlot equipmentSlot) {
return false;
}
}
package gregtech.api.items.armor;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.ISpecialArmor.ArmorProperties;

import javax.annotation.Nonnull;

/**
* Armor logic that wraps {@link net.minecraftforge.common.ISpecialArmor} methods
* to allow full control over damage absorption additionally to vanilla attribute values
*/
public interface ISpecialArmorLogic extends IArmorLogic {

/**
* Retrieves the modifiers to be used when calculating armor damage.
* <p>
* Armor will higher priority will have damage applied to them before
* lower priority ones. If there are multiple pieces of armor with the
* same priority, damage will be distributed between them based on there
* absorption ratio.
*/
ArmorProperties getProperties(EntityLivingBase player, @Nonnull ItemStack armor, DamageSource source, double damage, EntityEquipmentSlot equipmentSlot);

/**
* Get the displayed effective armor.
*
* @return The number of armor points for display, 2 per shield.
*/
int getArmorDisplay(EntityPlayer player, @Nonnull ItemStack armor, int slot);

/**
* Simple check to see if the armor should interact with "Unblockable" damage
* sources. A fair number of vanilla damage sources have this tag, such as
* Anvils, Falling, Fire, and Magic.
* <p>
* Returning true here means that the armor is able to meaningfully respond
* to this damage source. Otherwise, no interaction is allowed.
*/
default boolean handleUnblockableDamage(EntityLivingBase entity, @Nonnull ItemStack armor, DamageSource source, double damage, EntityEquipmentSlot equipmentSlot) {
return false;
}
}
2 changes: 0 additions & 2 deletions src/main/java/gregtech/api/items/armor/NanoMuscleSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import gregtech.api.GTValues;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IElectricItem;
import gregtech.api.items.armor.ArmorLogicSuite;
import gregtech.api.items.armor.ArmorUtils;
import gregtech.api.util.GTUtility;
import gregtech.api.util.input.EnumKey;
import gregtech.common.items.MetaItems;
Expand Down
1 change: 0 additions & 1 deletion src/main/java/gregtech/api/net/KeysPacket.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package gregtech.api.net;



import gregtech.api.util.input.EnumKey;
import gregtech.api.util.input.Key;
import gregtech.api.util.input.Keybinds;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/gregtech/api/net/NetworkHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public PacketCodec(PacketEncoder<T> encoder, PacketDecoder<T> decoder) {
this.decoder = decoder;
}
}

public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("Gregtech");
private static final HashMap<Class<? extends Packet>, PacketCodec<? extends Packet>> codecMap = new HashMap<>();
@SideOnly(Side.CLIENT)
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/gregtech/api/util/LocalizationUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public class LocalizationUtils {
* <li>`LocalisationUtils` is only for cases where some kind of translation is required on the server and there is no client/player in context.</li>
* <li>`LocalisationUtils` is "best effort" and will probably only work properly with en-us.</li>
* </ul>
*
* @param localisationKey the localisation key passed to the underlying format function
* @param substitutions the substitutions passed to the underlying format function
* @param substitutions the substitutions passed to the underlying format function
* @return the localized string.
*/
public static String format(String localisationKey, Object... substitutions) {
Expand All @@ -36,6 +37,7 @@ public static String format(String localisationKey, Object... substitutions) {
* <li>`LocalisationUtils` is only for cases where some kind of translation is required on the server and there is no client/player in context.</li>
* <li>`LocalisationUtils` is "best effort" and will probably only work properly with en-us.</li>
* </ul>
*
* @param localisationKey the localisation key passed to the underlying hasKey function
* @return a boolean indicating if the given localisation key has localisations
*/
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/gregtech/api/util/input/Key.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class Key { @SideOnly(Side.CLIENT)
private KeyBinding binding;
public class Key {
@SideOnly(Side.CLIENT)
private KeyBinding binding;
public final EnumKey KEY;
public boolean state;
public static final String KEYS_CATEGORY = "gregtech";
Expand Down
64 changes: 32 additions & 32 deletions src/main/java/gregtech/common/asm/LayerArmorBaseVisitor.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
package gregtech.common.asm;

import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

import gregtech.common.asm.util.ObfMapping;

class LayerArmorBaseVisitor extends MethodVisitor implements Opcodes {

public static final String TARGET_CLASS_NAME = "net/minecraft/client/renderer/entity/layers/LayerArmorBase";
public static final ObfMapping TARGET_METHOD = new ObfMapping(TARGET_CLASS_NAME, "func_188361_a", "(Lnet/minecraft/entity/EntityLivingBase;FFFFFFFLnet/minecraft/inventory/EntityEquipmentSlot;)V");

private static final String ARMOR_HOOKS_OWNER = "gregtech/api/items/armor/ArmorRenderHooks";
private static final String ARMOR_HOOKS_SIGNATURE = "(Lnet/minecraft/client/renderer/entity/layers/LayerArmorBase;Lnet/minecraft/entity/EntityLivingBase;FFFFFFFLnet/minecraft/inventory/EntityEquipmentSlot;)V";
private static final String ARMOR_HOOKS_METHOD_NAME = "renderArmorLayer";

public LayerArmorBaseVisitor(MethodVisitor mv) {
super(Opcodes.ASM5, mv);
}

@Override
public void visitInsn(int opcode) {
if (opcode == Opcodes.RETURN) {
super.visitVarInsn(ALOAD, 0); //this
super.visitVarInsn(ALOAD, 1); //entityLivingBaseIn
for (int i = 0; i < 7; i++) super.visitVarInsn(FLOAD, 2 + i); //limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale
super.visitVarInsn(ALOAD, 9); //slotIn
super.visitMethodInsn(INVOKESTATIC, ARMOR_HOOKS_OWNER, ARMOR_HOOKS_METHOD_NAME, ARMOR_HOOKS_SIGNATURE, false);
}
super.visitInsn(opcode);
}
}
package gregtech.common.asm;

import gregtech.common.asm.util.ObfMapping;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

class LayerArmorBaseVisitor extends MethodVisitor implements Opcodes {

public static final String TARGET_CLASS_NAME = "net/minecraft/client/renderer/entity/layers/LayerArmorBase";
public static final ObfMapping TARGET_METHOD = new ObfMapping(TARGET_CLASS_NAME, "func_188361_a", "(Lnet/minecraft/entity/EntityLivingBase;FFFFFFFLnet/minecraft/inventory/EntityEquipmentSlot;)V");

private static final String ARMOR_HOOKS_OWNER = "gregtech/api/items/armor/ArmorRenderHooks";
private static final String ARMOR_HOOKS_SIGNATURE = "(Lnet/minecraft/client/renderer/entity/layers/LayerArmorBase;Lnet/minecraft/entity/EntityLivingBase;FFFFFFFLnet/minecraft/inventory/EntityEquipmentSlot;)V";
private static final String ARMOR_HOOKS_METHOD_NAME = "renderArmorLayer";

public LayerArmorBaseVisitor(MethodVisitor mv) {
super(Opcodes.ASM5, mv);
}

@Override
public void visitInsn(int opcode) {
if (opcode == Opcodes.RETURN) {
super.visitVarInsn(ALOAD, 0); //this
super.visitVarInsn(ALOAD, 1); //entityLivingBaseIn
for (int i = 0; i < 7; i++)
super.visitVarInsn(FLOAD, 2 + i); //limbSwing, limbSwingAmount, partialTicks, ageInTicks, netHeadYaw, headPitch, scale
super.visitVarInsn(ALOAD, 9); //slotIn
super.visitMethodInsn(INVOKESTATIC, ARMOR_HOOKS_OWNER, ARMOR_HOOKS_METHOD_NAME, ARMOR_HOOKS_SIGNATURE, false);
}
super.visitInsn(opcode);
}
}
111 changes: 55 additions & 56 deletions src/main/java/gregtech/common/asm/LayerCustomHeadVisitor.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,55 @@
package gregtech.common.asm;

import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

import gregtech.common.asm.util.ObfMapping;
import gregtech.common.asm.util.SafeMethodVisitor;

class LayerCustomHeadVisitor extends SafeMethodVisitor {

public static final String TARGET_CLASS_NAME = "net/minecraft/client/renderer/entity/layers/LayerCustomHead";
public static final ObfMapping TARGET_METHOD = new ObfMapping(TARGET_CLASS_NAME, "func_177141_a", "(Lnet/minecraft/entity/EntityLivingBase;FFFFFFF)V");

private static final String METHOD_OWNER = "net/minecraft/client/renderer/ItemRenderer";
private static final String METHOD_SIGNATURE = "(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/renderer/block/model/ItemCameraTransforms$TransformType;)V";
private static final String METHOD_NAME = "func_178099_a";
private static final ObfMapping METHOD_MAPPING = new ObfMapping(METHOD_OWNER, METHOD_NAME, METHOD_SIGNATURE).toRuntime();


private static final String ARMOR_HOOKS_OWNER = "gregtech/api/items/armor/ArmorRenderHooks";
private static final String ARMOR_HOOKS_SIGNATURE = "(Lnet/minecraft/entity/EntityLivingBase;)Z";
private static final String ARMOR_HOOKS_METHOD_NAME = "shouldNotRenderHeadItem";

public LayerCustomHeadVisitor(MethodVisitor mv) {
super(Opcodes.ASM5, mv);
}

private boolean checkTargetInsn(int opcode, String owner, String name, String desc) {
return opcode == Opcodes.INVOKEVIRTUAL && METHOD_MAPPING.s_owner.equals(owner) && METHOD_MAPPING.matches(name, desc);
}

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (checkTargetInsn(opcode, owner, name, desc)) {
markPatchedSuccessfully();
Label endLabel = new Label();
Label skipLabel = new Label();
super.visitVarInsn(Opcodes.ALOAD, 1); //load entity
super.visitMethodInsn(Opcodes.INVOKESTATIC, ARMOR_HOOKS_OWNER, ARMOR_HOOKS_METHOD_NAME, ARMOR_HOOKS_SIGNATURE, false);
super.visitJumpInsn(Opcodes.IFEQ, skipLabel);
for (int i = 0; i < 4; i++) super.visitInsn(Opcodes.POP); //pop this, entity, stack, transformType
super.visitJumpInsn(Opcodes.GOTO, endLabel);
super.visitLabel(skipLabel);
super.visitMethodInsn(opcode, owner, name, desc, itf);
super.visitLabel(endLabel);
return;
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
}

@Override
protected String getInjectTargetString() {
return String.format("Patch target: %s; injection point: %s; (point not found)", TARGET_METHOD, METHOD_MAPPING);
}
}
package gregtech.common.asm;

import gregtech.common.asm.util.ObfMapping;
import gregtech.common.asm.util.SafeMethodVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

class LayerCustomHeadVisitor extends SafeMethodVisitor {

public static final String TARGET_CLASS_NAME = "net/minecraft/client/renderer/entity/layers/LayerCustomHead";
public static final ObfMapping TARGET_METHOD = new ObfMapping(TARGET_CLASS_NAME, "func_177141_a", "(Lnet/minecraft/entity/EntityLivingBase;FFFFFFF)V");

private static final String METHOD_OWNER = "net/minecraft/client/renderer/ItemRenderer";
private static final String METHOD_SIGNATURE = "(Lnet/minecraft/entity/EntityLivingBase;Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/renderer/block/model/ItemCameraTransforms$TransformType;)V";
private static final String METHOD_NAME = "func_178099_a";
private static final ObfMapping METHOD_MAPPING = new ObfMapping(METHOD_OWNER, METHOD_NAME, METHOD_SIGNATURE).toRuntime();


private static final String ARMOR_HOOKS_OWNER = "gregtech/api/items/armor/ArmorRenderHooks";
private static final String ARMOR_HOOKS_SIGNATURE = "(Lnet/minecraft/entity/EntityLivingBase;)Z";
private static final String ARMOR_HOOKS_METHOD_NAME = "shouldNotRenderHeadItem";

public LayerCustomHeadVisitor(MethodVisitor mv) {
super(Opcodes.ASM5, mv);
}

private boolean checkTargetInsn(int opcode, String owner, String name, String desc) {
return opcode == Opcodes.INVOKEVIRTUAL && METHOD_MAPPING.s_owner.equals(owner) && METHOD_MAPPING.matches(name, desc);
}

@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (checkTargetInsn(opcode, owner, name, desc)) {
markPatchedSuccessfully();
Label endLabel = new Label();
Label skipLabel = new Label();
super.visitVarInsn(Opcodes.ALOAD, 1); //load entity
super.visitMethodInsn(Opcodes.INVOKESTATIC, ARMOR_HOOKS_OWNER, ARMOR_HOOKS_METHOD_NAME, ARMOR_HOOKS_SIGNATURE, false);
super.visitJumpInsn(Opcodes.IFEQ, skipLabel);
for (int i = 0; i < 4; i++) super.visitInsn(Opcodes.POP); //pop this, entity, stack, transformType
super.visitJumpInsn(Opcodes.GOTO, endLabel);
super.visitLabel(skipLabel);
super.visitMethodInsn(opcode, owner, name, desc, itf);
super.visitLabel(endLabel);
return;
}
super.visitMethodInsn(opcode, owner, name, desc, itf);
}

@Override
protected String getInjectTargetString() {
return String.format("Patch target: %s; injection point: %s; (point not found)", TARGET_METHOD, METHOD_MAPPING);
}
}
Loading

0 comments on commit 8320595

Please sign in to comment.