moved code to new structure
This commit is contained in:
30
src/main/java/de/steev/bm/Interaction/Death.java
Normal file
30
src/main/java/de/steev/bm/Interaction/Death.java
Normal file
@ -0,0 +1,30 @@
|
||||
package de.steev.bm.Interaction;
|
||||
|
||||
import de.steev.bm.BetterMinecraft;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.entity.EntityDeathEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class Death {
|
||||
/**
|
||||
* handles animal loot drops only works as array
|
||||
* @param amount the drop amount
|
||||
* @param drops the dropping items
|
||||
* @param plugin plugin reference
|
||||
*/
|
||||
public static void onAnimalDeath(int[] amount, Material[] drops, BetterMinecraft plugin, EntityDeathEvent event){
|
||||
|
||||
// Random Drop amount generation DO NOT TOUCH!!!!
|
||||
int i1_amnt = ThreadLocalRandom.current().nextInt(1, amount[0] + 1);
|
||||
int i2_amnt = ThreadLocalRandom.current().nextInt(1, amount[1] + 1);
|
||||
|
||||
// Clears Vanilla drops
|
||||
event.getDrops().clear();
|
||||
|
||||
// Drops specified amount of the specified items
|
||||
for(int i = 0; i < i1_amnt; i++) { event.getEntity().getLocation().getWorld().dropItem(event.getEntity().getLocation(), new ItemStack(drops[0])); }
|
||||
for(int i = 0; i < i2_amnt; i++) { event.getEntity().getLocation().getWorld().dropItem(event.getEntity().getLocation(), new ItemStack(drops[1])); }
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package de.steev.bm.Interaction;
|
||||
|
||||
import de.steev.bm.BetterMinecraft;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
|
||||
public class Item_Recipy_Override {
|
||||
|
||||
BetterMinecraft plugin;
|
||||
NamespacedKey item;
|
||||
static ShapedRecipe rec_item;
|
||||
|
||||
/**
|
||||
* Overrides vanilla recipes
|
||||
* @param plugin Plugin Reference
|
||||
* @param Item Item name
|
||||
* @param result the dropping item
|
||||
* @param amount the droprate
|
||||
*/
|
||||
public Item_Recipy_Override(BetterMinecraft plugin, String Item, Material result, int amount){
|
||||
this.plugin = plugin;
|
||||
item = new NamespacedKey(plugin, Item);
|
||||
ItemStack itemStack = new ItemStack(result);
|
||||
itemStack.setAmount(amount);
|
||||
|
||||
rec_item = new ShapedRecipe(item, itemStack);
|
||||
}
|
||||
|
||||
/**
|
||||
* registers recipe to bukkit recipe handler
|
||||
* @param ing Ingredience reference
|
||||
* @param mat material ing will reference
|
||||
* @param rec the recipe shape
|
||||
*/
|
||||
public static void register_recipy(char[] ing, Material[] mat, String[] rec){
|
||||
//Recipe shapes
|
||||
rec_item.shape(rec[0], rec[1], rec[2]);
|
||||
|
||||
for(int i = 0; i < ing.length; i++) {
|
||||
// Material Definitions
|
||||
rec_item.setIngredient(ing[i], mat[i]);
|
||||
}
|
||||
|
||||
// Add recipes to Server
|
||||
Bukkit.addRecipe(rec_item);
|
||||
}
|
||||
}
|
46
src/main/java/de/steev/bm/Interaction/replanting.java
Normal file
46
src/main/java/de/steev/bm/Interaction/replanting.java
Normal file
@ -0,0 +1,46 @@
|
||||
package de.steev.bm.Interaction;
|
||||
|
||||
import de.steev.bm.BetterMinecraft;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.Ageable;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class replanting {
|
||||
|
||||
private BetterMinecraft plugin;
|
||||
|
||||
/**
|
||||
* event constructor
|
||||
* @param plugin plugin instance
|
||||
*/
|
||||
public replanting(BetterMinecraft plugin) {
|
||||
plugin.getLogger().info("replanting handler Registered");
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* simplified function for handling replanting works only with arrays
|
||||
* @param item the material of each drop
|
||||
* @param amount the drop amount of each item
|
||||
*/
|
||||
public static void planting(Material[] item, int[] amount, Block target){
|
||||
Ageable crop = (Ageable) target.getBlockData();
|
||||
Location loc = target.getLocation().clone().add(0.5, 0.5, 0.5);
|
||||
|
||||
// TODO: validate if code may throw errors
|
||||
|
||||
if(crop.getAge() == crop.getMaximumAge()){
|
||||
for(int i = 0; i < amount[0]; i++) {
|
||||
target.getLocation().getWorld().dropItem(loc, new ItemStack(item[0]));
|
||||
}
|
||||
|
||||
for(int i = 0; i < amount[1]; i++) {
|
||||
target.getLocation().getWorld().dropItem(loc, new ItemStack(item[1]));
|
||||
}
|
||||
crop.setAge(0);
|
||||
target.setBlockData(crop);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user