1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
|
package gtPlusPlus.core.item.bauble;
import static gregtech.api.enums.Mods.GTPlusPlus;
import java.lang.reflect.Field;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import baubles.api.BaubleType;
import cpw.mods.fml.common.registry.GameRegistry;
import gregtech.asm.GTCorePlugin;
import gtPlusPlus.core.creative.AddToCreativeTab;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
public class FireProtectionBauble extends BaseBauble {
private static final Field isImmuneToFire;
static {
isImmuneToFire = ReflectionUtils
.getField(Entity.class, !GTCorePlugin.isDevEnv() ? "func_70045_F" : "isImmuneToFire");
}
public static boolean fireImmune(Entity aEntity) {
return aEntity.isImmuneToFire();
}
public static boolean setEntityImmuneToFire(Entity aEntity, boolean aImmune) {
try {
return ReflectionUtils.setField(aEntity, isImmuneToFire, aImmune);
} catch (Throwable t) {}
return false;
}
public FireProtectionBauble() {
super(BaubleType.RING);
String aUnlocalName = "GTPP.bauble.fireprotection.0" + ".name";
this.setUnlocalizedName(aUnlocalName);
this.setTextureName(GTPlusPlus.ID + ":" + getTextureNameForBauble());
this.setMaxDamage(100);
this.setMaxStackSize(1);
this.setNoRepair();
this.setCreativeTab(AddToCreativeTab.tabMachines);
if (GameRegistry.findItem(GTPlusPlus.ID, aUnlocalName) == null) {
GameRegistry.registerItem(this, aUnlocalName);
}
}
@Override
public void onUpdate(final ItemStack itemStack, final World worldObj, final Entity player, final int p_77663_4_,
final boolean p_77663_5_) {
super.onUpdate(itemStack, worldObj, player, p_77663_4_, p_77663_5_);
}
@Override
public String getItemStackDisplayName(final ItemStack p_77653_1_) {
return (EnumChatFormatting.DARK_RED + super.getItemStackDisplayName(p_77653_1_) + EnumChatFormatting.GRAY);
}
@Override
public boolean showDurabilityBar(final ItemStack stack) {
return false;
}
@Override
public void addInformation(final ItemStack stack, final EntityPlayer aPlayer, final List list, final boolean bool) {
super.addInformation(stack, aPlayer, list, bool);
}
@Override
public boolean canEquip(final ItemStack arg0, final EntityLivingBase arg1) {
return true;
}
@Override
public boolean canUnequip(final ItemStack arg0, final EntityLivingBase arg1) {
return true;
}
@Override
public void onEquipped(final ItemStack arg0, final EntityLivingBase aPlayer) {}
@Override
public void onUnequipped(final ItemStack arg0, final EntityLivingBase aPlayer) {
if (!aPlayer.worldObj.isRemote) {
if (aPlayer instanceof EntityPlayer bPlayer) {
if (bPlayer.isPotionActive(Potion.fireResistance)) {
bPlayer.removePotionEffect(Potion.fireResistance.id);
}
setEntityImmuneToFire(bPlayer, false);
}
}
}
@Override
public void onWornTick(final ItemStack aBaubleStack, final EntityLivingBase aPlayer) {
if (!aPlayer.worldObj.isRemote) {
if (aPlayer instanceof EntityPlayer bPlayer) {
if (!fireImmune(bPlayer)) {
setEntityImmuneToFire(bPlayer, true);
}
if (!bPlayer.isPotionActive(Potion.fireResistance)) {
bPlayer.addPotionEffect(new PotionEffect(Potion.fireResistance.id, 100, 4));
}
}
}
}
public String getTextureNameForBauble() {
return "baubles/itemFireProtectGlovesBetter";
}
}
|