SHOW:
|
|
- or go back to the newest paste.
1 | public Item[][] armors; | |
2 | private String[] colorOrder = {"Red", "Orange", "Yellow", "Green", "Blue", "Purple"}; | |
3 | // "Helmet" "Plate" "Legs" "Boots" | |
4 | @ load() | |
5 | { | |
6 | .... | |
7 | armors[0][0] = RedHelmet; | |
8 | armors[0][1] = RedPlate; | |
9 | armors[0][2] = RedLegs; | |
10 | armors[0][3] = RedBoots; | |
11 | armors[1][0] = OrangeHelmet; | |
12 | .... | |
13 | } | |
14 | public String getArmorColorIndex(String color) | |
15 | { | |
16 | for (int i = 0; i < colorOrder.length; i++) | |
17 | { | |
18 | if (colorOrder[i] == color) return i; | |
19 | } | |
20 | throw new IllegalArgumentException("Unknown color name!"); | |
21 | } | |
22 | ================ | |
23 | package net.minecraft.src; | |
24 | ||
25 | import java.io.DataInputStream; | |
26 | import java.io.DataOutputStream; | |
27 | import java.io.IOException; | |
28 | import java.io.PrintStream; | |
29 | import java.util.List; | |
30 | import java.util.Random; | |
31 | ||
32 | import net.minecraft.src.forge.ISpawnHandler; | |
33 | ||
34 | public class PaintballEntityRefillers extends PaintballEntityObjects implements IMob, ISpawnHandler | |
35 | { | |
36 | public PaintballEntityRefillers(World world) | |
37 | { | |
38 | super(world); | |
39 | } | |
40 | ||
41 | public PaintballEntityRefillers(World world, String color, double d, double d1, double d2) | |
42 | { | |
43 | super(world); | |
44 | setSize(0.35F, 0.50F); | |
45 | setPosition(d, d1, d2); | |
46 | refiller_color = color; | |
47 | motionX = 0.0D; | |
48 | motionY = 0.0D; | |
49 | motionZ = 0.0D; | |
50 | prevPosX = d; | |
51 | prevPosY = d1; | |
52 | prevPosZ = d2; | |
53 | if(!world.isRemote) | |
54 | { | |
55 | EntityPlayer entity = findPlayer(); | |
56 | if(entity != null) | |
57 | { | |
58 | faceEntity(entity, 180F, 180F); | |
59 | rotationYaw -= 90; | |
60 | renderYawOffset = rotationYaw; | |
61 | refiller_isRotated = false; | |
62 | } | |
63 | } | |
64 | refiller_color = color; | |
65 | } | |
66 | ||
67 | public void onUpdate() | |
68 | { | |
69 | super.onUpdate(); | |
70 | if(!refiller_isRotated) | |
71 | { | |
72 | renderYawOffset = rotationYaw; | |
73 | refiller_isRotated = true; | |
74 | } | |
75 | if(refiller_cooldown > 0) | |
76 | refiller_cooldown--; | |
77 | if(refiller_cooldown >= 900) | |
78 | texture = "/Paintball/" + refiller_color.toLowerCase() + "refiller5.png"; | |
79 | else if(refiller_cooldown >= 600 && refiller_cooldown < 900) | |
80 | texture = "/Paintball/" + refiller_color.toLowerCase() + "refiller4.png"; | |
81 | else if(refiller_cooldown >= 300 && refiller_cooldown < 600) | |
82 | texture = "/Paintball/" + refiller_color.toLowerCase() + "refiller3.png"; | |
83 | else if(refiller_cooldown > 0 && refiller_cooldown < 300) | |
84 | texture = "/Paintball/" + refiller_color.toLowerCase() + "refiller2.png"; | |
85 | else | |
86 | texture = "/Paintball/" + refiller_color.toLowerCase() + "refiller1.png"; | |
87 | } | |
88 | ||
89 | private boolean fullSuit(ItemStack[] armorinv, int colorindex) | |
90 | { | |
91 | boolean[] checklist = {false,false,false,false}; | |
92 | short count = 0; | |
93 | for(short i=0; i<4; i++) | |
94 | { | |
95 | if (armorinv[i] == null) | |
96 | { | |
97 | System.out.println("DEBUG: armor piece "+i+" was null"); | |
98 | return false; | |
99 | } | |
100 | checklist[i] = (armorinv[i] == mod_Paintball.armors[colorindex][i]); | |
101 | count++; | |
102 | } | |
103 | System.out.println("DEBUG: Armor array: "+checklist.toString()+"; armor count: "+count); | |
104 | return count == 3; | |
105 | } | |
106 | ||
107 | public boolean interact(EntityPlayer entityplayer) | |
108 | { | |
109 | World world = ModLoader.getMinecraftServerInstance().getWorldManager(entityplayer.dimension); | |
110 | if(!world.isRemote) | |
111 | { | |
112 | boolean SameTeam = fullSuit(entityplayer.inventory.armorInventory, mod_Paintball.getArmorColorIndex(refiller_color)); | |
113 | System.out.println(SameTeam); //Always false == thinks you're on the team | |
114 | System.out.println("DEBUG: Refiller cooldown: "+refiller_cooldown); | |
115 | if(SameTeam && refiller_cooldown == 0) | |
116 | { | |
117 | System.out.println("Server Give"); //Doesn't print until the second time you right click on the entity while it should be counting down | |
118 | boolean add1 = entityplayer.inventory.addItemStackToInventory(new ItemStack(mod_Paintball.pelletMap.get(refiller_color), 64)); | |
119 | boolean add2 = entityplayer.inventory.addItemStackToInventory(new ItemStack(mod_Paintball.pelletMap.get(refiller_color), 64)); | |
120 | boolean add3 = entityplayer.inventory.addItemStackToInventory(new ItemStack(mod_Paintball.pelletMap.get(refiller_color), 64)); | |
121 | if(add1 || add2 || add3) | |
122 | { | |
123 | refiller_cooldown = 1200; | |
124 | world.playSoundAtEntity(entityplayer, "random.pop", 1.0F, 1.0F / (mod_Paintball.pelletMap.get(refiller_color).itemRand.nextFloat() * 0.4F + 0.8F)); | |
125 | } | |
126 | } | |
127 | return true; | |
128 | } | |
129 | else | |
130 | { | |
131 | return false; | |
132 | } | |
133 | } | |
134 | ||
135 | protected EntityPlayer findPlayer() | |
136 | { | |
137 | EntityPlayer entityplayer = worldObj.getClosestPlayerToEntity(this, 16D); | |
138 | if(entityplayer != null && canEntityBeSeen(entityplayer)) | |
139 | return entityplayer; | |
140 | else | |
141 | return null; | |
142 | } | |
143 | ||
144 | public void writeEntityToNBT(NBTTagCompound nbttagcompound) | |
145 | { | |
146 | super.writeEntityToNBT(nbttagcompound); | |
147 | nbttagcompound.setString("Color", refiller_color); | |
148 | nbttagcompound.setInteger("Cooldown", refiller_cooldown); | |
149 | } | |
150 | ||
151 | public void readEntityFromNBT(NBTTagCompound nbttagcompound) | |
152 | { | |
153 | super.readEntityFromNBT(nbttagcompound); | |
154 | refiller_color = nbttagcompound.getString("Color"); | |
155 | refiller_cooldown = nbttagcompound.getInteger("Cooldown"); | |
156 | } | |
157 | ||
158 | public void writeSpawnData(DataOutputStream data) throws IOException | |
159 | { | |
160 | data.writeUTF(refiller_color); | |
161 | } | |
162 | ||
163 | public void readSpawnData(DataInputStream data) throws IOException | |
164 | { | |
165 | } | |
166 | ||
167 | protected int getDropItemId() | |
168 | { | |
169 | if(refiller_color == "Red") | |
170 | entityDropItem(new ItemStack(mod_Paintball.RedRefiller), 0.0F); | |
171 | else if(refiller_color == "Orange") | |
172 | entityDropItem(new ItemStack(mod_Paintball.OrangeRefiller), 0.0F); | |
173 | else if(refiller_color == "Yellow") | |
174 | entityDropItem(new ItemStack(mod_Paintball.YellowRefiller), 0.0F); | |
175 | else if(refiller_color == "Green") | |
176 | entityDropItem(new ItemStack(mod_Paintball.GreenRefiller), 0.0F); | |
177 | else if(refiller_color == "Blue") | |
178 | entityDropItem(new ItemStack(mod_Paintball.BlueRefiller), 0.0F); | |
179 | else if(refiller_color == "Purple") | |
180 | entityDropItem(new ItemStack(mod_Paintball.PurpleRefiller), 0.0F); | |
181 | return 0; | |
182 | } | |
183 | ||
184 | public String refiller_color; | |
185 | private boolean refiller_isRotated; | |
186 | private int refiller_cooldown; | |
187 | private Entity currentTarget; | |
188 | ||
189 | } |