-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathGunStatTweaker.java
63 lines (50 loc) · 1.78 KB
/
GunStatTweaker.java
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
package techguns.plugins.crafttweaker;
import crafttweaker.CraftTweakerAPI;
import crafttweaker.IAction;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.common.registry.GameRegistry;
import stanhebben.zenscript.annotations.ZenClass;
import stanhebben.zenscript.annotations.ZenMethod;
import techguns.Techguns;
import techguns.items.guns.GenericGun;
@ZenClass("mods.techguns.GunStats")
public class GunStatTweaker {
@ZenMethod
public static void setWeaponStat(String weaponname, String fieldname, float value) {
CraftTweakerAPI.apply(new setGunStatAction(weaponname, fieldname, value));
}
private static class setGunStatAction implements IAction {
protected String weaponname;
protected String fieldname;
protected GenericGun gun=null;
protected EnumGunStat field=null;
protected float value;
protected boolean gunOk;
public setGunStatAction(String weaponname, String fieldname, float value) {
this.fieldname=fieldname;
this.weaponname=weaponname;
Item item = GameRegistry.findRegistry(Item.class).getValue(new ResourceLocation(Techguns.MODID, weaponname));
this.field = EnumGunStat.parseFromString(fieldname);
this.value = value;
this.gunOk = item !=null && item instanceof GenericGun;
this.gun = (GenericGun) item;
}
@Override
public void apply() {
if(this.field!=null && this.gunOk) {
this.gun.setGunStat(field, value);
}
}
@Override
public String describe() {
if(!gunOk) {
return "Failed setting ["+fieldname+"] for Weapon: ["+weaponname+"]: ITEM IS NOT A GUN";
}
if (field==null) {
return "Failed setting ["+fieldname+"] for Weapon: ["+weaponname+"]: UNKNOWN FIELD";
}
return "Set ["+fieldname+"] for Weapon: ["+weaponname+"] to: "+value;
}
}
}