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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
package com.sosnitzka.taiga.util;
import com.sosnitzka.taiga.Items;
import com.sosnitzka.taiga.TAIGA;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import org.apache.commons.lang3.StringUtils;
import slimeknights.tconstruct.library.MaterialIntegration;
import slimeknights.tconstruct.library.TinkerRegistry;
import slimeknights.tconstruct.library.materials.*;
import javax.annotation.Nullable;
import java.lang.reflect.Field;
import java.util.Random;
import static com.sosnitzka.taiga.TAIGA.proxy;
public class Utils {
public static String PREFIX_INGOT = "ingot";
public static String PREFIX_NUGGET = "nugget";
public static String PREFIX_ORE = "ore";
public static String PREFIX_BLOCK = "block";
public static String PREFIX_DUST = "dust";
public static String PREFIX_CRYSTAL = "crystal";
/**
* Registers the fluid and its bucket item
*
* @param fluid the fluid
*/
public static void registerFluid(Fluid fluid) {
FluidRegistry.registerFluid(fluid);
FluidRegistry.addBucketForFluid(fluid);
}
public static void registerTinkerAlloy(FluidStack output, FluidStack... inputs) {
if (inputs.length >= 2 && output != null) {
TinkerRegistry.registerAlloy(output, inputs);
}
}
public static boolean isNight(int time) {
return time > 12500;
}
public static double round2(double d) {
return (Math.round(d * 100.0) / 100.0);
}
public static void integrateMaterial(String oreSuffix, @Nullable Material material, Fluid fluid, int headDura,
float headSpeed, float headAttack, float handleMod, int handleDura, int
extra, int headLevel, float draw, float range, int bdamage) {
integrateMaterial(oreSuffix, material, fluid, headDura, headSpeed, headAttack, handleMod, handleDura, extra,
headLevel, new BowMaterialStats(draw, range, bdamage), false, true);
}
public static void integrateMaterial(String oreSuffix, @Nullable Material material, Fluid fluid, int headDura, float headSpeed, float headAttack, float handleMod, int handleDura, int extra, int headLevel, BowMaterialStats bowstats) {
integrateMaterial(oreSuffix, material, fluid, headDura, headSpeed, headAttack, handleMod, handleDura, extra, headLevel, bowstats, false, true);
}
public static void integrateMaterial(String oreSuffix, @Nullable Material material, Fluid fluid, int headDura, float headSpeed, float headAttack, float handleMod, int handleDura, int extra, int headLevel, BowMaterialStats bowstats, boolean craft, boolean cast) {
if (material != null) {
if (TinkerRegistry.getMaterial(material.identifier) != Material.UNKNOWN)
return;
TinkerRegistry.addMaterialStats(material, new HeadMaterialStats(headDura, headSpeed, headAttack,
headLevel));
TinkerRegistry.addMaterialStats(material, new HandleMaterialStats(handleMod, handleDura));
TinkerRegistry.addMaterialStats(material, new ExtraMaterialStats(extra));
TinkerRegistry.addMaterialStats(material, bowstats);
Item item = null;
Field[] items = Items.class.getDeclaredFields();
for (Field i : items) {
if (i.getName().equals(StringUtils.uncapitalize(oreSuffix) + "Ingot")) {
Item r = null;
try {
r = (Item) i.get(i.getType());
} catch (Exception e) {
e.printStackTrace();
}
item = r;
}
}
material.setFluid(fluid).setCraftable(craft).setCastable(cast).addItem(item, 1, Material.VALUE_Ingot);
material.setRepresentativeItem(item);
proxy.setRenderInfo(material);
}
MaterialIntegration integration = new MaterialIntegration(material, fluid, oreSuffix);
integration.preInit();
TAIGA.integrateList.add(integration);
}
public static void integrateOre(String oreSuffix, Fluid fluid) {
integrateMaterial(oreSuffix, null, fluid, -1, -1, -1, -1, -1, -1, -1, new BowMaterialStats(0.1f, 0.1f, -1f),
true, true);
}
public static int nextInt(Random random, int min, int max) {
return random.nextInt((max - min) + 1) + min;
}
public static class GeneralNBTData {
public int killcount;
public float health;
public int brokenblocks;
public float bonus;
public int curse;
public String name;
public float radius;
public float dfloat;
public int dint;
public boolean active;
public static GeneralNBTData read(NBTTagCompound tag) {
GeneralNBTData data = new GeneralNBTData();
data.killcount = tag.getInteger("killcount");
data.brokenblocks = tag.getInteger("brokenblocks");
data.health = tag.getFloat("health");
data.bonus = tag.getFloat("bonus");
data.curse = tag.getInteger("curse");
data.name = tag.getString("name");
data.radius = tag.getFloat("radius");
data.dfloat = tag.getFloat("dfloat");
data.dint = tag.getInteger("dint");
data.active = tag.getBoolean("active");
return data;
}
public void write(NBTTagCompound tag) {
tag.setInteger("killcount", killcount);
tag.setInteger("brokenblocks", brokenblocks);
tag.setFloat("health", health);
tag.setFloat("bonus", bonus);
tag.setInteger("curse", curse);
tag.setString("name", name);
tag.setFloat("radius", radius);
tag.setInteger("dint", dint);
tag.setFloat("dfloat", dfloat);
tag.setBoolean("active", active);
}
}
}
|