Skip to content

Commit

Permalink
Merge pull request #45 from BeepoWuff/cauldron-xp
Browse files Browse the repository at this point in the history
Implement Cauldron XP Reward
  • Loading branch information
WolfyScript authored Jan 3, 2022
2 parents 86f09ce + e7362e5 commit c1229f5
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class RecipeCacheCauldron extends RecipeCache<CustomRecipeCauldron> {

private int cookingTime;
private int waterLevel;
private float xp;
private int xp;
private CustomItem handItem;
private Ingredient ingredients;
private boolean dropItems;
Expand Down Expand Up @@ -106,11 +106,11 @@ public void setWaterLevel(int waterLevel) {
this.waterLevel = waterLevel;
}

public float getXp() {
public int getXp() {
return xp;
}

public void setXp(float xp) {
public void setXp(int xp) {
this.xp = xp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.bukkit.block.BlockFace;
import org.bukkit.block.data.Levelled;
import org.bukkit.block.data.type.Campfire;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.ExperienceOrb;
import org.bukkit.util.Vector;
import org.bukkit.util.io.BukkitObjectInputStream;
import org.bukkit.util.io.BukkitObjectOutputStream;
Expand Down Expand Up @@ -112,7 +114,15 @@ public Cauldrons(CustomCrafting customCrafting) {
}
recipe.getResult().executeExtensions(loc.clone(), true, null);
if (event.dropItems()) {
world.dropItemNaturally(loc.clone().add(0.0, 0.5, 0.0), event.getResult().create());
var dropLocation = loc.clone().add(0.0, 0.5, 0.0);

world.dropItemNaturally(dropLocation, event.getResult().create());

if (recipe.getXp() > 0) {
ExperienceOrb orb = (ExperienceOrb) dropLocation.getWorld().spawnEntity(dropLocation, EntityType.EXPERIENCE_ORB);
orb.setExperience(recipe.getXp());
}

return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public void onInit() {
hashMap.put("%xp%", cache.getRecipeCreatorCache().getCauldronCache().getXp());
return itemStack;
}, (guiHandler, player, s, args) -> {
float xp;
int xp;
try {
xp = Float.parseFloat(args[0]);
xp = Integer.parseInt(args[0]);
} catch (NumberFormatException e) {
api.getChat().sendKey(player, getCluster(), "valid_number");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ public void onInteract(PlayerInteractEvent event) {
for (Cauldron cauldron : cauldrons.getCauldrons().get(block.getLocation())) {
if (cauldron.isDone() && !cauldron.dropItems()) {
ItemStack handItem = event.getItem();
CustomItem required = cauldron.getRecipe().getHandItem();
CustomRecipeCauldron recipe = cauldron.getRecipe();
CustomItem required = recipe.getHandItem();
event.setUseItemInHand(Event.Result.DENY);
event.setUseInteractedBlock(Event.Result.DENY);
if (!ItemUtils.isAirOrNull(handItem)) {
if (!ItemUtils.isAirOrNull(required) && required.isSimilar(handItem, cauldron.getRecipe().isExactMeta())) {
if (!ItemUtils.isAirOrNull(required) && required.isSimilar(handItem, recipe.isExactMeta())) {
handItem.setAmount(handItem.getAmount() - 1);
} else if (!ItemUtils.isAirOrNull(required)) {
return;
Expand All @@ -119,6 +120,9 @@ public void onInteract(PlayerInteractEvent event) {
} else {
player.getWorld().dropItemNaturally(player.getLocation(), result);
}
if (recipe.getXp() > 0) {
player.giveExp(recipe.getXp());
}
cauldron.setForRemoval(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class CustomRecipeCauldron extends CustomRecipe<CustomRecipeCauldron> {

private int cookingTime;
private int waterLevel;
private float xp;
private int xp;
private CustomItem handItem;
private Ingredient ingredients;
private boolean dropItems;
Expand All @@ -59,7 +59,7 @@ public class CustomRecipeCauldron extends CustomRecipe<CustomRecipeCauldron> {

public CustomRecipeCauldron(NamespacedKey namespacedKey, JsonNode node) {
super(namespacedKey, node);
this.xp = node.path("exp").floatValue();
this.xp = node.path("exp").asInt(0);
this.cookingTime = node.path("cookingTime").asInt(60);
this.waterLevel = node.path("waterLevel").asInt(1);
this.needsWater = node.path("water").asBoolean(true);
Expand Down Expand Up @@ -130,11 +130,11 @@ public void setNeedsWater(boolean needsWater) {
this.needsWater = needsWater;
}

public float getXp() {
public int getXp() {
return xp;
}

public void setXp(float xp) {
public void setXp(int xp) {
this.xp = xp;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang/de_DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -2148,7 +2148,7 @@
"",
"&eDie Menge an Erfahrungspunkte, die du erhältst, wenn das Rezept fertig ist."
],
"message": "&3Gebe die Menge an Erfahrung ein. Beispielsweise: 0.5"
"message": "&3Gebe die Menge an Erfahrung ein. Beispielsweise: 2"
},
"cookingTime": {
"name": "&6Kochzeit",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -2445,7 +2445,7 @@
"",
"&eThe amount xp you get when the recipe is done."
],
"message": "&3Type in the amount of experience. e.g. 0.5"
"message": "&3Type in the amount of experience. e.g. 2"
},
"cookingTime": {
"name": "&6Cooking Time",
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/lang/zh_CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2039,7 +2039,7 @@
"",
"&e配方完成后你获得的经验值."
],
"message": "&3输入配方完成后你获得的经验值.如: 0.5"
"message": "&3输入配方完成后你获得的经验值.如: 2"
},
"cookingTime": {
"name": "&6烹饪时间",
Expand Down

0 comments on commit c1229f5

Please sign in to comment.