alright currently the new problem is this, when i click on the interface button i get disconnected, here is my buttons code, if i just use the shrimp on the stove with just 1 in the inventory it works, but when i click the button nothing occurs
Code:
case 10:
if(obj.getDefinition().getName().equalsIgnoreCase("Range")) {
Food food = Food.forId(item.getId());
if(food != null) {
if(player.getInventory().getCount(food.getRaw()) > 1) {
player.getActionSender().sendInterfaceModel(309, 2, 130, food.getRaw());
player.getActionSender().sendString(309, 6, "<br><br><br><br>" + ItemDefinition.forId(food.getRaw()).getName());
player.getActionSender().sendChatboxInterface(309);
player.setInterfaceAttribute("cook_type", food);
player.setInterfaceAttribute("cook_index", food.getIndex());
return;
} else {
player.getActionQueue().addAction(new CookingAction(player, 1, food));
}
return;
}
}
break;
Code:
if(player.getInterfaceAttribute("cook_index") != null && player.getInterfaceAttribute("cook_type") != null) {
int productionCount = -1;
switch(childId) {
case 6:
productionCount = 1;
break;
case 5:
productionCount = 5;
break;
case 4:
player.getInterfaceState().openEnterAmountInterface(309, -1, -1);
break;
case 3:
productionCount = 28;
break;
}
if(productionCount != -1) {
player.getInterfaceAttribute("cook_type");
player.getActionQueue().addAction(new CookingAction(player, productionCount, Food.forId((Integer) player.getInterfaceAttribute("cook_index"))));
player.getActionSender().removeChatboxInterface();
}
}
and the class
Code:
package org.rs2server.rs2.model.skills;
import java.util.HashMap;
import java.util.Map;
import java.security.SecureRandom;
import org.rs2server.rs2.action.impl.ProductionAction;
import org.rs2server.rs2.model.Animation;
import org.rs2server.rs2.model.Graphic;
import org.rs2server.rs2.model.Item;
import org.rs2server.rs2.model.Mob;
import org.rs2server.rs2.model.Skills;
public class CookingAction extends ProductionAction {
private final SecureRandom cookingRandom = new SecureRandom();
/**
* The amount of items to produce.
*/
private int productionCount;
/**
* The food we are cooking
*/
private Food food;
public CookingAction(Mob mob, int productionCount, Food food) {
super(mob);
this.productionCount = productionCount;
this.food = food;
}
/**
* Represents types of cooking food.
*
* @author Linux
*
*/
public enum Food {
SHRIMP(1, 317, 315, 7954, 1, 34, 300);
private int index;
/**
* The raw item id
*/
private int raw;
/**
* The cooked item id
*/
private int cooked;
/**
* The burnt item id
*/
private int burnt;
/**
* The required level
*/
private int level;
/**
* The level once you stop burning
*/
private int bestLevel;
/**
* The experience earned
*/
private final double exp;
/**
* Creates a new cookable food
*
* @param raw
* The raw item id
* @param cooked
* The cooked item id
* @param burnt
* The burnt item id
* @param level
* The required level
* @param bestLevel
* The level to stop burning
* @param exp
* The experience earned.
*/
private Food(int index, int raw, int cooked, int burnt, int level, int bestLevel,
double exp) {
this.index = index;
this.raw = raw;
this.cooked = cooked;
this.burnt = burnt;
this.level = level;
this.bestLevel = bestLevel;
this.exp = exp;
}
/**
* A map of object ids to foods.
*/
private static Map<Integer, Food> foods = new HashMap<>();
/**
* Gets a food by an object id.
*
* @param object
* The object id.
* @return The food, or <code>null</code> if the object is not a food.
*/
public static Food forId(int object) {
return foods.get(object);
}
/**
* Populates the tree map.
*/
static {
for (Food food : Food.values()) {
foods.put(food.raw, food);
}
}
/**
* Gets the raw item id
*
* @return The item id
*/
public int getRaw() {
return raw;
}
public int getIndex() {
return index;
}
/**
* Gets the cooked item id
*
* @return The item id
*/
public int getCooked() {
return cooked;
}
/**
* Gets the burnt item id
*
* @return The item id
*/
public int getBurnt() {
return burnt;
}
/**
* Gets the required level
*
* @return The level
*/
public int getLevel() {
return level;
}
/**
* Gets the best level
*
* @return The level
*/
public int getBestLevel() {
return bestLevel;
}
/**
* Gets the experience
*
* @return The experience
*/
public double getExp() {
return exp;
}
}
@Override
public boolean canProduce() {
return true;
}
@Override
public Animation getAnimation() {
return Animation.create(1248);
}
@Override
public Item[] getConsumedItems() {
return new Item[] { new Item(food.getRaw()) };
}
@Override
public int getCycleCount() {
return 3;
}
@Override
public double getExperience() {
return food.getExp();
}
@Override
public Graphic getGraphic() {
return null;
}
@Override
public String getLevelTooLowMessage() {
return "You need a Cooking level of " + getRequiredLevel() + " to cook this.";
}
@Override
public int getProductionCount() {
return productionCount;
}
@Override
public int getRequiredLevel() {
return food.getLevel();
}
@Override
public Item[] getRewards() {
//return new Item[] { new Item(food.getItem()[foodIndex])};
final double burnBonus = 3.0;
double burn_chance = 55.0 - burnBonus;
final double lev_needed = food.getLevel();
final double burn_stop = food.getBestLevel();
final double multi_a = burn_stop - lev_needed;
final double burn_dec = burn_chance / multi_a;
final double multi_b = Skills.COOKING - lev_needed;
burn_chance -= multi_b * burn_dec;
final double randNum = cookingRandom.nextDouble() * 100.0;
if (burn_chance <= randNum) {
return new Item[] { new Item(food.getCooked())};
} else {
return new Item[] { new Item(food.getBurnt())};
}
}
@Override
public int getSkill() {
return Skills.COOKING;
}
@Override
public String getSuccessfulProductionMessage() {
return "You successfully cook the food.";
}
}
heres the error
Code:
SEVERE: Exception handling packet.
java.lang.ClassCastException: org.rs2server.rs2.model.skills.CookingAction$Food cannot be cast to java.lang.Integer
at org.rs2server.rs2.packet.CloseInterfacePacketHandler.handle(CloseInterfacePacketHandler.java:309)
at org.rs2server.rs2.net.PacketManager.handle(PacketManager.java:73)
at org.rs2server.rs2.task.impl.SessionMessageTask.execute(SessionMessageTask.java:39)
at org.rs2server.rs2.GameEngine$1.run(GameEngine.java:105)
at org.rs2server.rs2.GameEngine$5.run(GameEngine.java:178)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(Unknown Source)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)