Java Reference
In-Depth Information
Changes We Need
Here's what I came up with:
1.
Change the
importjava.util.ArrayList;
to
importjava.util.HashMap;
.
2.
Change the
cowList
from
publicstaticArrayList<Cow>cowList=newArrayList<Cow>();
to use a hash instead:
publicstaticHashMap<Cow,CreeperCowTimer>allCows=new
HashMap<Cow,CreeperCowTimer>();
. Also, I renamed it to “allCows” so that the
type of list isn't part of the name.
3.
Change the
cowList.add(cow);
to
allCows.put(cow, new CreeperCowTimer(cow));
since
you have to
put
in a hash.
4.
Change the
for
loop to iterate through the
HashMap
so the new loop looks
like this:
for
(Cow c : allCows.keySet()) {
CreeperCowTimer superCow = allCows.get(c);
superCow.jump(me.getLocation());
}
Right about now this might feel frustrating.
That's okay: it's not important to get it right the first time. That rarely happens
and doesn't gain you much. It
is
important to get it right the last time.
With these changes we can now test jumping. I'll fire up the server, connect
from the client, and test by spawning just a single cow first. Then I can use
the
testJump
command to see if it starts heading toward me:
/testspawncows 5 1