-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathNaturalReinforcement.java
More file actions
119 lines (96 loc) · 3.08 KB
/
Copy pathNaturalReinforcement.java
File metadata and controls
119 lines (96 loc) · 3.08 KB
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
package com.untamedears.citadel.entity;
import java.util.HashMap;
import java.util.Random;
import java.util.List;
import java.util.ArrayList;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.block.Block;
import com.untamedears.citadel.NaturalReinforcementConfig;
/**
* User: erocs
*/
public class NaturalReinforcement implements IReinforcement {
// HashMap<materialId, breakCount>
public static final HashMap<Integer, NaturalReinforcementConfig> CONFIGURATION =
new HashMap<Integer, NaturalReinforcementConfig>();
private ReinforcementKey id_;
private boolean broken_;
private int max_durability_;
private Random random;
public NaturalReinforcement() {
this.random = new Random();
}
public NaturalReinforcement(Block block, int max_durability) {
this.id_ = new ReinforcementKey(block);
this.max_durability_ = max_durability;
this.random = new Random();
}
public ReinforcementKey getId() { return id_; }
public void setId(ReinforcementKey id) { this.id_ = id; }
public Block getBlock() {
try {
return Bukkit.getServer().getWorld(id_.getWorld()).getBlockAt(
id_.getX(),
id_.getY(),
id_.getZ());
} catch (NullPointerException e){
return null;
}
}
public int getMaxDurability() { return max_durability_; }
public void setMaxDurability(int max_durability) { this.max_durability_ = max_durability; }
public double getHealth() {
return 1.0;
}
public String getHealthText() {
return "naturally";
}
public String getStatus() { return getHealthText(); }
@Override
public String toString() {
return String.format("%s, hardness %d", id_, max_durability_);
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof IReinforcement)) return false;
IReinforcement r = (IReinforcement)o;
return this.id_.equals(r.getId());
}
public int compareTo(IReinforcement r) {
return this.id_.compareTo(r.getId());
}
@Override
public int hashCode() {
return this.id_.hashCode();
}
@Override
public boolean isBroken() {
return broken_;
}
@Override
public boolean breakOnce() {
if (broken_) return true;
if (random.nextInt(max_durability_) == 0) {
broken_ = true;
}
return broken_;
}
public List<ItemStack> generateChipDrops() {
List<ItemStack> result = new ArrayList<ItemStack>();
NaturalReinforcementConfig config = getConfig();
if (config == null) {
return null;
}
Material mat = getConfig().generateChipDrop(random);
if (mat != null) {
result.add(new ItemStack(mat, 1));
}
return result;
}
public NaturalReinforcementConfig getConfig() {
return NaturalReinforcement.CONFIGURATION.get(getBlock().getTypeId());
}
}