Purpose: To add mining to your server.
Features: random gems, mining emotes, multi player mining, etc.
Difficulty: 1, find your rocks by yourself.
Ya, I made this in about 4 hours with no reference... you must do my woodcutting tutorial first otherwise you'll be lost from the start. It's also recommended to do my other tutorial to change it to hashmap, but you don't have to.
make a new class in server.players.Skills called mining.
place this in there
Code:
package server.players.Skills;
import server.players.Client;
import server.Server;
import server.util.Misc;
/**
*
* @author Livinglife
*
* Initial Mining
*
*/
public class Mining implements Skill
{
public static int skillX = 0;
public static int skillY = 0;
public int toadd = -1;
public int replace = 452;
public final static int VALIDAXE[] = { 1265, 1267, 1269, 1271, 1273, 1275 };
public final static int UNCUTS[] = { 1617, 1619, 1621, 1623, 1625, 1627, 1629, 1631, 6571 };
public int xp = 0;
public static int item = -1;
private Client c;
/**
*
* @param c
* @param object
* @param type
* @param x
* @param y
*/
public Mining(Client c, int object, String type, int x, int y)
{
this.c = c;
readInput(this.c.playerLevel[14], type, this.c, x, y, object);
}
public Mining(Client c)
{
this.c = c;
}
/**
*
* @param level
* @param type
* @param c
* @param objectx
* @param objecty
* @param objectid
*/
public void readInput(int level, String type, Client c, int objectx, int objecty, int objectid)
{
synchronized(this)
{
if (type.equals("TIN") && level >= 1)
{
xp = 18;
item = 438;
this.c.canmine = true;
}
else if (type.equals("COPPER") && level >= 1)
{
xp = 18;
item = 436;
this.c.canmine = true;
}
else if (type.equals("BLUR") && level >= 10)
{
xp = 18;
item = 668;
this.c.canmine = true;
}
else if (type.equals("ELEMENTAL") && level >= 20)
{
xp = 0;
item = 2892;
this.c.canmine = true;
}
else if (type.equals("GRANITE") && level >= 45)
{
int i = Misc.random(3);
if (i == 1)
{
xp = 50;
item = 6979;
this.c.canmine = true;
}
else if (i == 2)
{
xp = 60;
item = 6981;
this.c.canmine = true;
}
else if (i == 3)
{
xp = 75;
item = 6983;
this.c.canmine = true;
}
}
else if (type.equals("CLAY") && level >= 1)
{
xp = 5;
item = 434;
this.c.canmine = true;
}
else if (type.equals("ESS") && level >= 1)
{
if (level >= 30)
{
xp = 5;
item = 1436;
}
else
{
xp = 5;
item = 7936;
}
}
else if (type.equals("IRON") && level >= 15)
{
xp = 35;
item = 440;
this.c.canmine = true;
}
else if (type.equals("SILVER") && level >= 20)
{
xp = 40;
item = 442;
this.c.canmine = true;
}
else if (type.equals("COAL") && level >= 30)
{
xp = 50;
item = 453;
this.c.canmine = true;
}
else if (type.equals("GOLD") && level >= 40)
{
xp = 65;
item = 444;
this.c.canmine = true;
}
else if (type.equals("MITH") && level >= 55)
{
xp = 80;
item = 447;
this.c.canmine = true;
}
else if (type.equals("ADDY") && level >= 70)
{
xp = 95;
item = 449;
this.c.canmine = true;
}
else if (type.equals("RUNE") && level >= 85)
{
xp = 125;
item = 451;
this.c.canmine = true;
}
else if (type.equals("LIME") && level >= 10)
{
xp = 27;
item = 3211;
this.c.canmine = true;
}
else
{
this.c.sendMessage("You need a higher mining level to extract ore from this rock!");
xp = 0;
item = -1;
this.c.canmine = false;
}
}
for (int id : VALIDAXE)
{
System.out.println(id);
System.out.println(c.playerEquipment[c.playerWeapon]);
if(id == c.playerEquipment[c.playerWeapon] && c.canmine && canminewithpick(c.playerEquipment[c.playerWeapon], c) || c.getItems().playerHasItem(id, 1) && c.canmine && canminewithpick(id, c))
{
System.out.println("Called");
switch (id)
{
case 1265:
c.mineanim = 625;
c.intervaldeduction = 0;
break;
case 1267:
c.mineanim = 626;
c.intervaldeduction = 1;
break;
case 1269:
c.mineanim = 627;
c.intervaldeduction = 2;
break;
case 1271:
c.mineanim = 628;
c.intervaldeduction = 3;
break;
case 1273:
c.mineanim = 629;
c.intervaldeduction = 4;
break;
case 1275:
c.mineanim = 624;
c.intervaldeduction = 5;
break;
}
try
{
this.c.sendMessage("You swing your pick at the rock.");
c.turnPlayerTo(objectx, objecty);
this.c.minetime = Misc.random(20 - c.intervaldeduction);
if (!type.equals("ESS"))
{
Server.worldObject.registerObject(1, objectx, objecty, objectid, replace, 30, 10, 0, objectid);
}
this.c.mn.doaction(c, item, -1, -1, objectx, objecty, objectid, xp);
}
catch(Exception e)
{
e.printStackTrace();
}
break;
}
else if (id == c.playerEquipment[c.playerWeapon] && c.canmine && !canminewithpick(c.playerEquipment[c.playerWeapon], c) || c.getItems().playerHasItem(id, 1) && c.canmine && !canminewithpick(id, c))
{
c.sendMessage("You need a higher mining level to use this pickaxe!");
c.canmine = false;
c.ismining = false;
}
}
}
/**
*
* @param i - item id
* @param c - Client object
* @return
*/
private boolean canminewithpick(int i, Client c) {
switch (i)
{
case 1265:
case 1267:
if (c.playerLevel[14] >= 1)
return true;
break;
case 1269:
if (c.playerLevel[14] >= 6)
return true;
break;
case 1273:
if (c.playerLevel[14] >= 21)
return true;
break;
case 1271:
if (c.playerLevel[14] >= 31)
return true;
break;
case 1275:
if (c.playerLevel[14] >= 41)
return true;
break;
default:
return false;
}
return false;
}
/**
* @param s
* @param c
*/
public void out(String s, Client c)
{
}
/**
* @param c
* @param toadd
* @param toremove
* @param toremove2
* @param x
* @param y
* @param objectid
* @param xp
* @return
*/
public boolean doaction(Client c, int toadd, int toremove, int toremove2, int x, int y, int objectid, int xp)
{
if (true)
{
if (c.getItems().freeSlots() > 0)
{
this.toadd = toadd;
this.c.ismining = true;
this.xp = xp;
if (c.minetime <= 0)
{
if (Misc.random(20) == 1 || Misc.random(10) == 1 && toadd == 453)
{
this.c.getItems().addItem(UNCUTS[Misc.random(8)], 1);
this.c.sendMessage("You find a gem in the rock!");
}
if (!(toadd == 1436) && !(toadd == 7936))
{
Server.worldObject.reduceHealth(x, y);
}
if (!(toadd == 1436) && !(toadd == 7936))
{
this.c.sendMessage("You get some ore");
}
else
{
this.c.sendMessage("You get some essence");
}
System.out.println(c.intervaldeduction);
this.c.minetime = Misc.random(20 - c.intervaldeduction);
this.c.getItems().addItem(toadd, 1);
this.c.getPA().addSkillXP(xp, 14);
this.c.getPA().refreshSkill(14);
}
}
else
{
this.c.sendMessage("You've do not have enough room in your inventory.");
this.c.canmine = false;
this.c.ismining = false;
this.c.minetime = 0;
}
}
return true;
}
}
Your done, close out of that, open up server.world.worldobject and find
Code:
c.iscutting = false;
c.cancut = false;
place this below that code
Code:
c.ismining = false;
c.canmine = false;
c.startAnimation(65535);
Done with that, now open up your client class and declare this somewhere
Code:
public boolean ismining;
public int mineanim;
public boolean canmine = false;
public int minetime;
public int minewait;
public Mining mn = new Mining(this);
public int intervaldeduction;
and put this in process (yes I know I should use events blah blah blah, if you really want it as events do it yourself.)
Code:
if (minewait > 0)
{
minewait--;
}
if (minetime > 0)
{
minetime--;
}
if (ismining && canmine && minewait <= 0 && goodDistance(skillX, skillY, getX(), getY(), 1))
{
startAnimation(mineanim);
minewait = 5;
}
//3176 3368
if (minetime <= 0 && ismining && goodDistance(skillX, skillY, getX(), getY(), 1))
{
if (goodDistance(skillX, skillY, getX(), getY(), 1))
{
mn.doaction(this, mn.toadd, -1, -1, skillX, skillY, -1, mn.xp);
}
else
{
ismining = false;
canmine = false;
}
}
Your done, save compile, good to go now some usage notes.
Bugs: none?
Changing the respawn object for like limestone granite, etc.: edit the brackets for it so like (I'll use limestone as an example) you'd do something like this
Code:
else if (type.equals("LIME") && level >= 10)
{
xp = 27;
item = 3211;
this.c.canmine = true;
replace = myreplacement;
}
this can also be useful for specifying certain replacement objects like specifying a certain object id for a respawn like to make it perfect, which isn't hard and you should be able to figure it out yourself.
Credits: Me.
P.S. post compile errors and bugs.