/
Ore.java
145 lines (121 loc) · 3.63 KB
/
Ore.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
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
/*
* Work under Copyright. Licensed under the EUPL.
* See the project README.md and LICENSE.txt for more information.
*/
package net.dries007.tfc.api.types;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import net.minecraft.util.IStringSerializable;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.registries.IForgeRegistryEntry;
import net.dries007.tfc.ConfigTFC;
import net.dries007.tfc.api.registries.TFCRegistries;
/**
* todo: document API
*/
public class Ore extends IForgeRegistryEntry.Impl<Ore>
{
private final boolean graded;
private final Metal metal;
private final boolean canMelt;
private final double chunkChance, panChance;
/**
* Creates a registry object for an ore type
*
* @param name The registry name of the ore
* @param metal The metal, or null if it's a non-metal ore
* @param canMelt If the metal can be melted directly from the ore
* @param chunkChance the chance a chunk contains this ore when gold panning.
* @param panChance the chance to drop this ore when gold panning
*/
public Ore(ResourceLocation name, @Nullable Metal metal, boolean canMelt, double chunkChance, double panChance)
{
this.graded = (metal != null);
this.metal = metal;
this.canMelt = canMelt;
this.chunkChance = chunkChance;
this.panChance = panChance;
setRegistryName(name);
}
public Ore(ResourceLocation name, @Nonnull ResourceLocation metal, boolean canMelt, double chunkChance, double panChance)
{
this(name, TFCRegistries.METALS.getValue(metal), canMelt, chunkChance, panChance);
}
public Ore(ResourceLocation name, @Nonnull ResourceLocation metal)
{
this(name, TFCRegistries.METALS.getValue(metal), true, 0, 0);
}
public Ore(ResourceLocation name, @Nonnull ResourceLocation metal, boolean canMelt)
{
this(name, TFCRegistries.METALS.getValue(metal), canMelt, 0, 0);
}
public Ore(ResourceLocation name, @Nonnull ResourceLocation metal, double chunkChance, double panChance)
{
this(name, TFCRegistries.METALS.getValue(metal), true, chunkChance, panChance);
}
public Ore(ResourceLocation name)
{
this(name, (Metal) null, false, 0, 0);
}
public boolean isGraded()
{
return graded;
}
public boolean canPan()
{
return chunkChance > 0;
}
public double getPanChance()
{
return panChance;
}
public double getChunkChance()
{
return chunkChance;
}
@Nullable
public Metal getMetal()
{
return metal;
}
public boolean canMelt()
{
return canMelt;
}
@Override
public String toString()
{
//noinspection ConstantConditions
return getRegistryName().getPath();
}
public enum Grade implements IStringSerializable
{
NORMAL, POOR, RICH;
public static Grade byMetadata(int meta)
{
return Grade.values()[meta];
}
public int getSmeltAmount()
{
switch (this)
{
case POOR:
return ConfigTFC.GENERAL.poorOreMetalAmount;
case RICH:
return ConfigTFC.GENERAL.richOreMetalAmount;
case NORMAL:
default:
return ConfigTFC.GENERAL.normalOreMetalAmount;
}
}
@Override
public String getName()
{
return this.name().toLowerCase();
}
public int getMeta()
{
return this.ordinal();
}
}
}