-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathworkPlan.java
More file actions
239 lines (208 loc) · 5.79 KB
/
Copy pathworkPlan.java
File metadata and controls
239 lines (208 loc) · 5.79 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
package com.custommods.ai;
import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import com.custommods.walkmod.Step;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Vec3;
public class WorkPlan {
public static enum Type {smelt, craft, tool, moveto};
public static int NOT_FOUND = -1;
private List list;
private List typeList;
private List usedItems;
private List locationList;
///Constructor
public WorkPlan(){
this.list = new ArrayList();
this.typeList = new ArrayList<Type>();
this.usedItems = new ArrayList<ItemStack>();
this.locationList = new ArrayList<ItemStack>();
}
///Add item to Craft
public void add (ItemStack item){
typeList.add(Type.craft);
list.add(item);
}
///Add an object
public void add(Object object, Type type){
typeList.add(type);
list.add(object);
}
///Add Queue of steps
public void add (Queue<Step> steps){
typeList.add(Type.moveto);
list.add(steps);
}
///Check if the plan is empty
public boolean isEmpty(){
return list.isEmpty();
}
///Add item that is used
public void addUsedItem(ItemStack item){
usedItems.add(item);
}
///Remove an item from the used
public boolean removeUsedItem(ItemStack item){
int stack = item.stackSize;
for (Object object : usedItems) {
if (object instanceof ItemStack){
if (Item.getIdFromItem(item.getItem()) == Item.getIdFromItem(((ItemStack) object).getItem())){
if (((ItemStack) object).stackSize <= stack){
stack -= ((ItemStack) object).stackSize;
usedItems.remove(object);
if (stack==0){
return true;
}
}
else{
((ItemStack) object).stackSize -= stack;
return true;
}
}
}
}
return false;
}
///Add location to the locationList
public void addLoc(Vec3 loc){
locationList.add(loc);
}
///Peek location from the locationList
public Vec3 peekLoc(){
return (Vec3) locationList.get(locationList.size()-1);
}
///Pull location from the locationList
public Vec3 pullLoc(){
Vec3 toReturn = peekLoc();
removeLoc();
return toReturn;
}
///Remove the last form the locationList
public void removeLoc(){
locationList.remove(locationList.size() - 1);
}
///Count the number of location
public int countLoc(){
return locationList.size();
}
///Return array of all the location in the location list
public Vec3[] GetLoctionArr(){
Vec3[] toReturn = new Vec3[locationList.size()];
int conter = 0;
for (Object object : locationList) {
if (object instanceof Vec3){
toReturn[conter++] = (Vec3)object;
}
}
return toReturn;
}
///Get the number of stack of the item been used, return NOT_FOUND if the item not found
public int getStackInUsed(ItemStack item){
int conter = 0;
for (Object object : usedItems) {
if (object instanceof ItemStack){
if (Item.getIdFromItem(item.getItem()) == Item.getIdFromItem(((ItemStack) object).getItem())){
conter += ((ItemStack) object).stackSize;
}
}
}
if (conter != 0){
return conter;
}
return NOT_FOUND;
}
///Check if can used an item
public boolean canUsedItem(ItemStack item, AIinventory inve){
int stack = 0;
ItemStack newItem = new ItemStack(item.getItem());
newItem.stackSize = item.stackSize;
if ((stack = getStackInUsed(item))!=NOT_FOUND){
newItem.stackSize += stack;
}
return inve.haveItem(newItem);
}
///Remove the last one in the plan
public void removeLast(){
typeList.remove(typeList.size()-1);
list.remove(list.size()-1);
}
///Peek the first one in the plan
public Object peekLast(){
return list.get(list.size()-1);
}
//Peek the first type in the list
public Type peekType(){
return (Type) typeList.get(typeList.size()-1);
}
///Pull the first one in the plan
public Object pullLast(){
Object toReturn = list.get(list.size()-1);
this.removeLast();
return toReturn;
}
///Remove the first one in the plan
public void removeFirst(){
typeList.remove(0);
list.remove(0);
}
///Peek the first one in the plan
public Object peekFirst(){
return list.get(0);
}
///Peek the first Type in the plan
public Type peekFirstType(){
return (Type) typeList.get(0);
}
///Pull the first one in the plan
public Object pullFirst(){
Object toReturn = list.get(0);
this.removeFirst();
return toReturn;
}
///Return the string with all the plan
public String toString(){
String toReturn = "";
int index = 0;
if (list.isEmpty()){
return "Plan is empty";
}
for (int i = 0 ; i < list.size() ; i++) {
if (typeList.get(i) == Type.craft){
toReturn += index++ + ": Craft- " + ((ItemStack) list.get(i)).getDisplayName() + "\n";
}
else if (list.get(i) instanceof Queue){
toReturn += index++ + ": Move to- " + ((Step) ((Queue)list.get(i)).peek()).getLocation() + "\n";
}
else if (typeList.get(i) == Type.smelt){
toReturn += index++ + ": smelt - " + ((ItemStack) list.get(i)).getDisplayName() + "\n";
}
else if (typeList.get(i) == Type.tool){
switch ((Integer)list.get(i)) {
case AIinventory.AXE:
toReturn += index++ + ": Swhich to tool- axe \n";
break;
case AIinventory.PICKAXE:
toReturn += index++ + ": Swhich to tool- picaxe \n";
break;
case AIinventory.SHOVEL:
toReturn += index++ + ": Swhich to tool- shovel \n";
break;
default:
toReturn += index++ + ": Swhich to tool- ERROR: no tool \n";
break;
}
}
else{
if (list.get(i) == null){
toReturn += index++ + ": is null \n";
}
else{
toReturn += index++ + ": Not Found: " + list.get(i).toString() + "\n";
}
}
}
return toReturn;
}
}