Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Port over Gregicality Armor #96

Merged
merged 56 commits into from
Sep 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
87d6e0d
Add Armor
BraggestSage833 Aug 19, 2021
830021d
Add Aromor related configs
BraggestSage833 Aug 19, 2021
b9784de
Add armor related events
BraggestSage833 Aug 19, 2021
96af6e6
add Keybind related method calls
BraggestSage833 Aug 19, 2021
8dccf77
Sim
BraggestSage833 Aug 19, 2021
993e9c7
Add armor api files
BraggestSage833 Aug 19, 2021
0152430
Add Armor classes
BraggestSage833 Aug 19, 2021
8c12da9
Add packet handler
BraggestSage833 Aug 19, 2021
562b5fe
Add classes for keybinds
BraggestSage833 Aug 19, 2021
9bcc855
Add keybind related classes
BraggestSage833 Aug 19, 2021
19c992b
Fix NPE
BraggestSage833 Aug 19, 2021
0b76912
Sim
BraggestSage833 Aug 19, 2021
c0bd3dc
add Batterypack configs
BraggestSage833 Aug 19, 2021
2e2ca53
add BATPACK and NIGHTVISION
BraggestSage833 Aug 19, 2021
a134d32
Sim
BraggestSage833 Aug 19, 2021
d73db70
Add Night and bat classes
BraggestSage833 Aug 19, 2021
d7b7b55
fix error
BraggestSage833 Aug 19, 2021
f2c23a8
Sim
BraggestSage833 Aug 19, 2021
696b6ef
Fix Enchantability list by armor type
BraggestSage833 Aug 19, 2021
c9d3991
Add needed Json's
BraggestSage833 Aug 19, 2021
14d4c9e
Sim
BraggestSage833 Aug 19, 2021
fa923b1
Sim.2
BraggestSage833 Aug 19, 2021
7255038
Sim.3
BraggestSage833 Aug 19, 2021
a0a6aff
Sim.4
BraggestSage833 Aug 19, 2021
4acef9c
Add armor related lang stuff
BraggestSage833 Aug 19, 2021
07ed130
fix path location
BraggestSage833 Aug 19, 2021
cb57ee4
Fix model locations
BraggestSage833 Aug 19, 2021
9ffa9fe
add needed items
BraggestSage833 Aug 19, 2021
0141edf
Sim
BraggestSage833 Aug 19, 2021
43a31e0
add missing PNG's
BraggestSage833 Aug 19, 2021
b302bda
add missing Json
BraggestSage833 Aug 19, 2021
220289b
add missing json
BraggestSage833 Aug 19, 2021
933759a
Sim
BraggestSage833 Aug 19, 2021
7035c8c
relocating class
BraggestSage833 Aug 19, 2021
7b9872b
relocating class 2
BraggestSage833 Aug 19, 2021
2c231ef
relocating class 3
BraggestSage833 Aug 19, 2021
351a83e
relocating class
BraggestSage833 Aug 19, 2021
1cf2c56
fix file path
BraggestSage833 Aug 19, 2021
0058b45
fix filepath
BraggestSage833 Aug 19, 2021
9bacccf
fix Jetpack fall damage
BraggestSage833 Aug 19, 2021
21e29f8
add missing call
BraggestSage833 Aug 19, 2021
8c35a31
fix code
BraggestSage833 Aug 20, 2021
256bafe
Add armor recipes
BraggestSage833 Aug 20, 2021
37ced06
Add missing coremods
BraggestSage833 Aug 20, 2021
bf0d246
Sim
BraggestSage833 Aug 20, 2021
85c0ad0
finish coremod
BraggestSage833 Aug 20, 2021
bf39425
clean up imports
BraggestSage833 Aug 21, 2021
39ad2b9
fix merge issues
Aug 30, 2021
3d49b21
Add duct tape to recipes
BraggestSage833 Aug 30, 2021
f4e58eb
clean up configs a bit
Sep 4, 2021
2f2805c
clean up batpack configs, change some defaults
Sep 4, 2021
71bc84a
heavily clean up armor configs
Sep 4, 2021
aa625d9
fix typos, use EnumRarity over hardcoded color
Sep 4, 2021
10925f5
fix a couple mistakes
Sep 4, 2021
756606b
re-order armor items in JEI
Sep 4, 2021
3e1a1e9
move some classes to common
Sep 4, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/main/java/gregtech/GregTechMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@
import gregtech.api.util.AnnotatedMaterialHandlerLoader;
import gregtech.api.util.GTLog;
import gregtech.api.util.NBTUtil;
import gregtech.api.util.input.Keybinds;
import gregtech.api.worldgen.config.WorldGenRegistry;
import gregtech.common.CommonProxy;
import gregtech.common.ConfigHolder;
import gregtech.common.MetaEntities;
import gregtech.common.MetaFluids;
import gregtech.common.*;
import gregtech.common.blocks.MetaBlocks;
import gregtech.common.blocks.modelfactories.BlockCompressedFactory;
import gregtech.common.blocks.modelfactories.BlockFrameFactory;
Expand All @@ -41,6 +39,7 @@
import net.minecraft.client.resources.SimpleReloadableResourceManager;
import gregtech.loaders.recipe.component.AnnotatedComponentHandlerLoader;
import net.minecraftforge.classloading.FMLForgePlugin;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.LoaderException;
Expand Down Expand Up @@ -78,8 +77,10 @@ public class GregTechMod {

@Mod.EventHandler
public void onPreInit(FMLPreInitializationEvent event) {
GTLog.init(event.getModLog());
NetworkHandler.init();

MinecraftForge.EVENT_BUS.register(new EventHandlers());
GTLog.init(event.getModLog());
MetaTileEntityUIFactory.INSTANCE.init();
PlayerInventoryUIFactory.INSTANCE.init();
CoverBehaviorUIFactory.INSTANCE.init();
Expand All @@ -94,6 +95,7 @@ public void onPreInit(FMLPreInitializationEvent event) {
if (GTValues.isModLoaded(GTValues.MODID_CT)) {
GTLog.logger.info("Running early CraftTweaker initialization scripts...");
runEarlyCraftTweakerScripts();
MinecraftForge.EVENT_BUS.register(this);
}

//freeze material registry before processing items, blocks and fluids
Expand All @@ -112,6 +114,7 @@ public void onPreInit(FMLPreInitializationEvent event) {
AnnotatedComponentHandlerLoader.discoverAndLoadAnnotatedComponentHandlers(event.getAsmData());

proxy.onPreLoad();
Keybinds.register();
}

@Mod.EventHandler
Expand Down
45 changes: 23 additions & 22 deletions src/main/java/gregtech/api/items/armor/ArmorHooks.java
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
package gregtech.api.items.armor;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.NonNullList;

public class ArmorHooks {

public static void damageArmor(float damage, EntityLivingBase entity, NonNullList<ItemStack> inventory, DamageSource damageSource) {
double armorDamage = Math.max(1.0F, damage / 4.0F);
for (int i = 0; i < inventory.size(); i++) {
ItemStack itemStack = inventory.get(i);
if (itemStack.getItem() instanceof IArmorItem) {
((IArmorItem) itemStack.getItem()).damageArmor(entity, itemStack, damageSource, (int) armorDamage, i);
if (inventory.get(i).getCount() == 0) {
inventory.set(i, ItemStack.EMPTY);
}
}
}
}
}
package gregtech.api.items.armor;

import net.minecraft.entity.EntityLivingBase;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.util.NonNullList;

@SuppressWarnings("unused")
public class ArmorHooks {

public static void damageArmor(float damage, EntityLivingBase entity, NonNullList<ItemStack> inventory, DamageSource damageSource) {
double armorDamage = Math.max(1.0F, damage / 4.0F);
for (int i = 0; i < inventory.size(); i++) {
ItemStack itemStack = inventory.get(i);
if (itemStack.getItem() instanceof IArmorItem) {
((IArmorItem) itemStack.getItem()).damageArmor(entity, itemStack, damageSource, (int) armorDamage, i);
if (inventory.get(i).getCount() == 0) {
inventory.set(i, ItemStack.EMPTY);
}
}
}
}
}
166 changes: 166 additions & 0 deletions src/main/java/gregtech/api/items/armor/ArmorLogicSuite.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package gregtech.api.items.armor;


import com.google.common.collect.ImmutableMultimap;
import com.google.common.collect.Multimap;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IElectricItem;
import gregtech.api.items.armor.ArmorMetaItem.ArmorMetaValueItem;
import gregtech.api.items.metaitem.ElectricStats;
import net.minecraft.client.resources.I18n;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.common.ISpecialArmor.ArmorProperties;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;
import java.util.List;

public abstract class ArmorLogicSuite implements ISpecialArmorLogic {

protected final int energyPerUse;
protected final int tier;
protected final long maxCapacity;
protected final EntityEquipmentSlot SLOT;
@SideOnly(Side.CLIENT)
protected ArmorUtils.ModularHUD HUD;

protected ArmorLogicSuite(int energyPerUse, long maxCapacity, int tier, EntityEquipmentSlot slot) {
this.energyPerUse = energyPerUse;
this.maxCapacity = maxCapacity;
this.tier = tier;
this.SLOT = slot;
if (ArmorUtils.SIDE.isClient() && this.isNeedDrawHUD()) {
HUD = new ArmorUtils.ModularHUD();
}
}

@Override
public abstract void onArmorTick(World world, EntityPlayer player, ItemStack itemStack);

@Override
public int getArmorLayersAmount(ItemStack itemStack) {
return 1;
}

@Override
public ArmorProperties getProperties(EntityLivingBase player, @Nonnull ItemStack armor, DamageSource source, double damage, EntityEquipmentSlot equipmentSlot) {
IElectricItem item = armor.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
int damageLimit = Integer.MAX_VALUE;
if (source.isUnblockable()) return new ArmorProperties(0, 0.0, 0);
if (energyPerUse > 0) damageLimit = (int) Math.min(damageLimit, item.getCharge() * 1.0 / energyPerUse * 25.0);
return new ArmorProperties(0, getAbsorption(armor) * getDamageAbsorption(), damageLimit);
}

@Override
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
IElectricItem item = armor.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (item == null) return 0;
if (item.getCharge() >= energyPerUse) {
return (int) Math.round(20.0F * this.getAbsorption(armor) * this.getDamageAbsorption());
} else {
return (int) Math.round(4.0F * this.getAbsorption(armor) * this.getDamageAbsorption());
}
}

@Override
public void addToolComponents(ArmorMetaValueItem mvi) {
// mvi.addStats(ElectricStats.createElectricItem(maxCapacity, tier));
mvi.addComponents(new ElectricStats(maxCapacity, tier, true, false) {
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
return onRightClick(world, player, hand);
}

@Override
public void addInformation(ItemStack itemStack, List<String> lines) {
addInfo(itemStack, lines);
}
});
}

public void addInfo(ItemStack itemStack, List<String> lines) {
}

public ActionResult<ItemStack> onRightClick(World world, EntityPlayer player, EnumHand hand) {
if (player.getHeldItem(hand).getItem() instanceof ArmorMetaItem) {
ItemStack armor = player.getHeldItem(hand);
if (armor.getItem() instanceof ArmorMetaItem && player.inventory.armorInventory.get(SLOT.getIndex()).isEmpty() && !player.isSneaking()) {
player.inventory.armorInventory.set(SLOT.getIndex(), armor.copy());
player.setHeldItem(hand, ItemStack.EMPTY);
player.playSound(new SoundEvent(new ResourceLocation("item.armor.equip_generic")), 1.0F, 1.0F);
return ActionResult.newResult(EnumActionResult.SUCCESS, armor);
}
}

return ActionResult.newResult(EnumActionResult.PASS, player.getHeldItem(hand));
}

@Override
public void damageArmor(EntityLivingBase entity, ItemStack itemStack, DamageSource source, int damage, EntityEquipmentSlot equipmentSlot) {
}

@Override
public EntityEquipmentSlot getEquipmentSlot(ItemStack itemStack) {
return SLOT;
}

@Override
public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) {
return ImmutableMultimap.of();
}

@Override
public String getArmorTexture(ItemStack stack, Entity entity, EntityEquipmentSlot slot, String type) {
return "";
}

public abstract double getDamageAbsorption();

@SideOnly(Side.CLIENT)
public boolean isNeedDrawHUD() {
return false;
}

@SideOnly(Side.CLIENT)
public void drawHUD(ItemStack stack) {
this.addCapacityHUD(stack);
this.HUD.draw();
this.HUD.reset();
}

@SideOnly(Side.CLIENT)
protected void addCapacityHUD(ItemStack stack) {
IElectricItem cont = stack.getCapability(GregtechCapabilities.CAPABILITY_ELECTRIC_ITEM, null);
if (cont == null) return;
if (cont.getCharge() == 0) return;
float energyMultiplier = cont.getCharge() * 100.0F / cont.getMaxCharge();
this.HUD.newString(I18n.format("metaarmor.hud.energy_lvl", String.format("%.1f", energyMultiplier) + "%"));
}

public int getEnergyPerUse() {
return this.energyPerUse;
}

protected float getAbsorption(ItemStack itemStack) {
switch (this.getEquipmentSlot(itemStack)) {
case HEAD:
return 0.15F;
case CHEST:
return 0.4F;
case LEGS:
return 0.3F;
case FEET:
return 0.15F;
default:
return 0.0F;
}
}
}
52 changes: 39 additions & 13 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 All @@ -15,6 +14,7 @@
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.util.DamageSource;
import net.minecraft.world.World;
Expand Down Expand Up @@ -94,7 +94,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 +139,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 All @@ -161,7 +165,7 @@ public IArmorLogic getArmorLogic() {
}

public ArmorMetaValueItem setArmorLogic(IArmorLogic armorLogic) {
Preconditions.checkNotNull(armorLogic, "Cannot set armorLogic to null");
Preconditions.checkNotNull(armorLogic, "Cannot set ArmorLogic to null");
this.armorLogic = armorLogic;
this.armorLogic.addToolComponents(this);
return this;
Expand All @@ -173,20 +177,42 @@ public ArmorMetaValueItem addComponents(IItemComponent... stats) {
super.addComponents(stats);
return this;
}

@Override
public ArmorMetaValueItem setModelAmount(int modelAmount) {
return (ArmorMetaValueItem) super.setModelAmount(modelAmount);
}

@Override
public ArmorMetaValueItem setRarity(EnumRarity rarity) {
return (ArmorMetaValueItem) super.setRarity(rarity);
}
}

@Override
public boolean isEnchantable(ItemStack stack) {
public boolean isEnchantable(@Nonnull ItemStack stack) {
return true;
}

@Override
public int getItemEnchantability(ItemStack stack) {

public int getItemEnchantability(@Nonnull ItemStack stack) {
return 50;
}
//TODO add Enchantability list by armor type

@Override
public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) {
return enchantment.isAllowedOnBooks();
public boolean canApplyAtEnchantingTable(@Nonnull ItemStack stack, @Nonnull Enchantment enchantment) {
switch (this.getEquipmentSlot(stack)) {
case HEAD:
return enchantment.type.canEnchantItem(Items.DIAMOND_HELMET);
case CHEST:
return enchantment.type.canEnchantItem(Items.DIAMOND_CHESTPLATE);
case LEGS:
return enchantment.type.canEnchantItem(Items.DIAMOND_LEGGINGS);
case FEET:
return enchantment.type.canEnchantItem(Items.DIAMOND_BOOTS);
default:
return enchantment.isAllowedOnBooks();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
@SuppressWarnings("unused")
public class ArmorRenderHooks {

public static boolean shouldNotRenderHeadItem(EntityLivingBase entityLivingBase) {
Expand Down
Loading