1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-19 19:25:48 +00:00

Some minor improvements

This commit is contained in:
TheBusyBiscuit 2020-03-18 14:20:49 +01:00
parent c0d67fb3f2
commit 3cd31e2c2f
16 changed files with 238 additions and 131 deletions

View File

@ -49,6 +49,8 @@
* Multiblocks that use Fences or Trap doors now accept all wood types
* Added Makeshift Smeltery
* Added Tree Growth Accelerator
* Added "Glass to Glass Panes" recipe to the Electric Press
* The Lumber Axe can now strip logs too
#### Changes
* Removed some deprecated parts of the API
@ -68,6 +70,7 @@
* Fixed #1706
* Fixed #1710
* Fixed #1711
* Fixed Slimefun Guide showing shaped recipes incorrectly
## Release Candidate 9 (07 Mar 2020)

View File

@ -0,0 +1,72 @@
package io.github.thebusybiscuit.slimefun4.core.services;
import java.util.LinkedList;
import java.util.List;
import java.util.Optional;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.Recipe;
import org.bukkit.inventory.RecipeChoice;
import org.bukkit.inventory.ShapedRecipe;
import org.bukkit.plugin.Plugin;
import io.github.thebusybiscuit.cscorelib2.recipes.MinecraftRecipe;
import io.github.thebusybiscuit.cscorelib2.recipes.RecipeSnapshot;
import io.github.thebusybiscuit.slimefun4.implementation.guide.ChestSlimefunGuide;
/**
* This Service is responsible for accessing a {@link RecipeSnapshot}.
* This snapshot contains a compiled list of all recipes that could be found on the
* Server at the time the Service was loaded.
*
* This Service is primarily used by the {@link ChestSlimefunGuide}.
*
* @author TheBusyBiscuit
*
*/
public class MinecraftRecipeService {
private final Plugin plugin;
private RecipeSnapshot snapshot;
public MinecraftRecipeService(Plugin plugin) {
this.plugin = plugin;
}
public void load() {
snapshot = new RecipeSnapshot(plugin);
}
public Optional<ItemStack> getFurnaceOutput(ItemStack input) {
return snapshot.getRecipeOutput(MinecraftRecipe.FURNACE, input);
}
public RecipeChoice[] getRecipeShape(Recipe recipe) {
if (recipe instanceof ShapedRecipe) {
List<RecipeChoice> choices = new LinkedList<>();
for (String row : ((ShapedRecipe) recipe).getShape()) {
int columns = row.toCharArray().length;
for (char key : row.toCharArray()) {
choices.add(((ShapedRecipe) recipe).getChoiceMap().get(key));
}
while (columns < 3) {
choices.add(null);
columns++;
}
}
return choices.toArray(new RecipeChoice[0]);
}
else {
return snapshot.getRecipeInput(recipe);
}
}
public Recipe[] getRecipesFor(ItemStack item) {
return snapshot.getRecipesFor(item).toArray(new Recipe[0]);
}
}

View File

@ -35,6 +35,7 @@ public class Translators {
// Translators - Italian
addTranslator("xXDOTTORXx", EmbeddedLanguage.ITALIAN, true);
addTranslator("Sfiguz7", EmbeddedLanguage.ITALIAN, false);
// Translators - Latvian
addTranslator("AgnisT", "NIKNAIZ", EmbeddedLanguage.LATVIAN, true);

View File

@ -353,7 +353,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
return;
}
Recipe[] recipes = SlimefunPlugin.getMinecraftRecipes().getRecipesFor(item).toArray(new Recipe[0]);
Recipe[] recipes = SlimefunPlugin.getMinecraftRecipes().getRecipesFor(item);
if (recipes.length == 0) {
return;
@ -375,7 +375,7 @@ public class ChestSlimefunGuide implements SlimefunGuideImplementation {
if (optional.isPresent()) {
MinecraftRecipe<?> mcRecipe = optional.get();
RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipes().getRecipeInput(recipe);
RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipes().getRecipeShape(recipe);
if (choices.length == 1 && choices[0] instanceof MaterialChoice) {
recipeItems[4] = new ItemStack(((MaterialChoice) choices[0]).getChoices().get(0));

View File

@ -5,10 +5,8 @@ import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.slimefun4.core.attributes.RecipeDisplayItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public abstract class ElectricIngotFactory extends AContainer implements RecipeDisplayItem {
@ -17,19 +15,6 @@ public abstract class ElectricIngotFactory extends AContainer implements RecipeD
super(category, item, recipeType, recipe);
}
@Override
protected void registerDefaultRecipes() {
registerRecipe(new MachineRecipe(8, new ItemStack[] { SlimefunItems.ALUMINUM_DUST }, new ItemStack[] { SlimefunItems.ALUMINUM_INGOT }));
registerRecipe(new MachineRecipe(8, new ItemStack[] { SlimefunItems.COPPER_DUST }, new ItemStack[] { SlimefunItems.COPPER_INGOT }));
registerRecipe(new MachineRecipe(8, new ItemStack[] { SlimefunItems.GOLD_DUST }, new ItemStack[] { SlimefunItems.GOLD_4K }));
registerRecipe(new MachineRecipe(8, new ItemStack[] { SlimefunItems.IRON_DUST }, new ItemStack[] { new ItemStack(Material.IRON_INGOT) }));
registerRecipe(new MachineRecipe(8, new ItemStack[] { SlimefunItems.LEAD_DUST }, new ItemStack[] { SlimefunItems.LEAD_INGOT }));
registerRecipe(new MachineRecipe(8, new ItemStack[] { SlimefunItems.MAGNESIUM_DUST }, new ItemStack[] { SlimefunItems.MAGNESIUM_INGOT }));
registerRecipe(new MachineRecipe(8, new ItemStack[] { SlimefunItems.SILVER_DUST }, new ItemStack[] { SlimefunItems.SILVER_INGOT }));
registerRecipe(new MachineRecipe(8, new ItemStack[] { SlimefunItems.TIN_DUST }, new ItemStack[] { SlimefunItems.TIN_INGOT }));
registerRecipe(new MachineRecipe(8, new ItemStack[] { SlimefunItems.ZINC_DUST }, new ItemStack[] { SlimefunItems.ZINC_INGOT }));
}
@Override
public String getMachineIdentifier() {
return "ELECTRIC_INGOT_FACTORY";

View File

@ -9,7 +9,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.MachineRecipe;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public abstract class ElectricPress extends AContainer implements RecipeDisplayItem {
@ -20,51 +19,59 @@ public abstract class ElectricPress extends AContainer implements RecipeDisplayI
@Override
protected void registerDefaultRecipes() {
registerRecipe(new MachineRecipe(4, new ItemStack[] { new CustomItem(SlimefunItems.STONE_CHUNK, 3) }, new ItemStack[] { new ItemStack(Material.COBBLESTONE) }));
registerRecipe(new MachineRecipe(4, new ItemStack[] { new ItemStack(Material.FLINT, 6) }, new ItemStack[] { new ItemStack(Material.COBBLESTONE) }));
addRecipe(4, new CustomItem(SlimefunItems.STONE_CHUNK, 3), new ItemStack(Material.COBBLESTONE));
addRecipe(4, new ItemStack(Material.FLINT, 6), new ItemStack(Material.COBBLESTONE));
addRecipe(5, new ItemStack(Material.GLASS), new ItemStack(Material.GLASS_PANE, 3));
addRecipe(6, SlimefunItems.COPPER_INGOT, new CustomItem(SlimefunItems.COPPER_WIRE, 3));
addRecipe(16, new CustomItem(SlimefunItems.STEEL_INGOT, 8), SlimefunItems.STEEL_PLATE);
addRecipe(18, new CustomItem(SlimefunItems.REINFORCED_ALLOY_INGOT, 8), SlimefunItems.REINFORCED_PLATE);
registerRecipe(new MachineRecipe(6, new ItemStack[] { SlimefunItems.COPPER_INGOT }, new ItemStack[] { new CustomItem(SlimefunItems.COPPER_WIRE, 3) }));
registerRecipe(new MachineRecipe(16, new ItemStack[] { new CustomItem(SlimefunItems.STEEL_INGOT, 8) }, new ItemStack[] { SlimefunItems.STEEL_PLATE }));
registerRecipe(new MachineRecipe(18, new ItemStack[] { new CustomItem(SlimefunItems.REINFORCED_ALLOY_INGOT, 8) }, new ItemStack[] { SlimefunItems.REINFORCED_PLATE }));
addRecipe(8, new ItemStack(Material.NETHER_WART), new CustomItem(SlimefunItems.MAGIC_LUMP_1, 2));
addRecipe(10, new CustomItem(SlimefunItems.MAGIC_LUMP_1, 4), SlimefunItems.MAGIC_LUMP_2);
addRecipe(12, new CustomItem(SlimefunItems.MAGIC_LUMP_2, 4), SlimefunItems.MAGIC_LUMP_3);
registerRecipe(new MachineRecipe(8, new ItemStack[] { new ItemStack(Material.NETHER_WART) }, new ItemStack[] { new CustomItem(SlimefunItems.MAGIC_LUMP_1, 2) }));
registerRecipe(new MachineRecipe(10, new ItemStack[] { new CustomItem(SlimefunItems.MAGIC_LUMP_1, 4) }, new ItemStack[] { SlimefunItems.MAGIC_LUMP_2 }));
registerRecipe(new MachineRecipe(12, new ItemStack[] { new CustomItem(SlimefunItems.MAGIC_LUMP_2, 4) }, new ItemStack[] { SlimefunItems.MAGIC_LUMP_3 }));
addRecipe(10, new ItemStack(Material.ENDER_EYE), new CustomItem(SlimefunItems.ENDER_LUMP_1, 2));
addRecipe(12, new CustomItem(SlimefunItems.ENDER_LUMP_1, 4), SlimefunItems.ENDER_LUMP_2);
addRecipe(14, new CustomItem(SlimefunItems.ENDER_LUMP_2, 4), SlimefunItems.ENDER_LUMP_3);
registerRecipe(new MachineRecipe(10, new ItemStack[] { new ItemStack(Material.ENDER_EYE) }, new ItemStack[] { new CustomItem(SlimefunItems.ENDER_LUMP_1, 2) }));
registerRecipe(new MachineRecipe(12, new ItemStack[] { new CustomItem(SlimefunItems.ENDER_LUMP_1, 4) }, new ItemStack[] { SlimefunItems.ENDER_LUMP_2 }));
registerRecipe(new MachineRecipe(14, new ItemStack[] { new CustomItem(SlimefunItems.ENDER_LUMP_2, 4) }, new ItemStack[] { SlimefunItems.ENDER_LUMP_3 }));
addRecipe(18, new CustomItem(SlimefunItems.TINY_URANIUM, 9), SlimefunItems.SMALL_URANIUM);
addRecipe(24, new CustomItem(SlimefunItems.SMALL_URANIUM, 4), SlimefunItems.URANIUM);
registerRecipe(new MachineRecipe(18, new ItemStack[] { new CustomItem(SlimefunItems.TINY_URANIUM, 9) }, new ItemStack[] { SlimefunItems.SMALL_URANIUM }));
registerRecipe(new MachineRecipe(24, new ItemStack[] { new CustomItem(SlimefunItems.SMALL_URANIUM, 4) }, new ItemStack[] { SlimefunItems.URANIUM }));
addRecipe(4, new ItemStack(Material.QUARTZ, 4), new ItemStack(Material.QUARTZ_BLOCK));
addRecipe(4, new ItemStack(Material.IRON_NUGGET, 9), new ItemStack(Material.IRON_INGOT));
addRecipe(4, new ItemStack(Material.GOLD_NUGGET, 9), new ItemStack(Material.GOLD_INGOT));
addRecipe(4, new ItemStack(Material.COAL, 9), new ItemStack(Material.COAL_BLOCK));
registerRecipe(new MachineRecipe(4, new ItemStack[] { new ItemStack(Material.QUARTZ, 4) }, new ItemStack[] { new ItemStack(Material.QUARTZ_BLOCK) }));
registerRecipe(new MachineRecipe(4, new ItemStack[] { new ItemStack(Material.IRON_NUGGET, 9) }, new ItemStack[] { new ItemStack(Material.IRON_INGOT) }));
registerRecipe(new MachineRecipe(4, new ItemStack[] { new ItemStack(Material.GOLD_NUGGET, 9) }, new ItemStack[] { new ItemStack(Material.GOLD_INGOT) }));
registerRecipe(new MachineRecipe(4, new ItemStack[] { new ItemStack(Material.COAL, 9) }, new ItemStack[] { new ItemStack(Material.COAL_BLOCK) }));
addRecipe(5, new ItemStack(Material.IRON_INGOT, 9), new ItemStack(Material.IRON_BLOCK));
addRecipe(5, new ItemStack(Material.GOLD_INGOT, 9), new ItemStack(Material.GOLD_BLOCK));
registerRecipe(new MachineRecipe(5, new ItemStack[] { new ItemStack(Material.IRON_INGOT, 9) }, new ItemStack[] { new ItemStack(Material.IRON_BLOCK) }));
registerRecipe(new MachineRecipe(5, new ItemStack[] { new ItemStack(Material.GOLD_INGOT, 9) }, new ItemStack[] { new ItemStack(Material.GOLD_BLOCK) }));
addRecipe(6, new ItemStack(Material.REDSTONE, 9), new ItemStack(Material.REDSTONE_BLOCK));
addRecipe(6, new ItemStack(Material.LAPIS_LAZULI, 9), new ItemStack(Material.LAPIS_BLOCK));
registerRecipe(new MachineRecipe(6, new ItemStack[] { new ItemStack(Material.REDSTONE, 9) }, new ItemStack[] { new ItemStack(Material.REDSTONE_BLOCK) }));
registerRecipe(new MachineRecipe(6, new ItemStack[] { new ItemStack(Material.LAPIS_LAZULI, 9) }, new ItemStack[] { new ItemStack(Material.LAPIS_BLOCK) }));
addRecipe(8, new ItemStack(Material.EMERALD, 9), new ItemStack(Material.EMERALD_BLOCK));
addRecipe(8, new ItemStack(Material.DIAMOND, 9), new ItemStack(Material.DIAMOND_BLOCK));
}
private void addRecipe(int seconds, ItemStack input, ItemStack output) {
registerRecipe(new MachineRecipe(8, new ItemStack[] { new ItemStack(Material.EMERALD, 9) }, new ItemStack[] { new ItemStack(Material.EMERALD_BLOCK) }));
registerRecipe(new MachineRecipe(8, new ItemStack[] { new ItemStack(Material.DIAMOND, 9) }, new ItemStack[] { new ItemStack(Material.DIAMOND_BLOCK) }));
}
@Override
public String getInventoryTitle() {
return "&eElectric Press";
}
@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.IRON_HOE);
}
@Override
public String getMachineIdentifier() {
return "ELECTRIC_PRESS";
}
}

View File

@ -30,18 +30,7 @@ public class MakeshiftSmeltery extends MultiBlockMachine {
null, new ItemStack(Material.OAK_FENCE), null,
new ItemStack(Material.BRICKS), new CustomItem(Material.DISPENSER, "Dispenser (Facing up)"), new ItemStack(Material.BRICKS),
null, new ItemStack(Material.FLINT_AND_STEEL), null
},
new ItemStack[] {
SlimefunItems.IRON_DUST, new ItemStack(Material.IRON_INGOT),
SlimefunItems.GOLD_DUST, SlimefunItems.GOLD_4K,
SlimefunItems.COPPER_DUST, SlimefunItems.COPPER_INGOT,
SlimefunItems.TIN_DUST, SlimefunItems.TIN_INGOT,
SlimefunItems.SILVER_DUST, SlimefunItems.SILVER_INGOT,
SlimefunItems.MAGNESIUM_DUST, SlimefunItems.MAGNESIUM_INGOT,
SlimefunItems.ALUMINUM_DUST, SlimefunItems.ALUMINUM_INGOT,
SlimefunItems.LEAD_DUST, SlimefunItems.LEAD_INGOT,
SlimefunItems.ZINC_DUST, SlimefunItems.ZINC_INGOT
}, BlockFace.DOWN);
}, new ItemStack[0], BlockFace.DOWN);
}
@Override

View File

@ -2,9 +2,13 @@ package io.github.thebusybiscuit.slimefun4.implementation.items.tools;
import java.util.List;
import org.bukkit.Axis;
import org.bukkit.Effect;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.Tag;
import org.bukkit.block.Block;
import org.bukkit.block.data.Orientable;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
@ -17,18 +21,21 @@ import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.interfaces.NotPlaceable;
import me.mrCookieSlime.Slimefun.Objects.handlers.BlockBreakHandler;
import me.mrCookieSlime.Slimefun.Objects.handlers.ItemUseHandler;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class LumberAxe extends SimpleSlimefunItem<BlockBreakHandler> implements NotPlaceable {
public class LumberAxe extends SimpleSlimefunItem<ItemUseHandler> implements NotPlaceable {
public LumberAxe(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);
}
@Override
public BlockBreakHandler getItemHandler() {
return new BlockBreakHandler() {
public void preRegister() {
super.preRegister();
addItemHandler(new BlockBreakHandler() {
@Override
public boolean isPrivate() {
@ -64,7 +71,42 @@ public class LumberAxe extends SimpleSlimefunItem<BlockBreakHandler> implements
}
else return false;
}
});
}
@Override
public ItemUseHandler getItemHandler() {
return e -> {
if (e.getClickedBlock().isPresent()) {
Block block = e.getClickedBlock().get();
if (isUnstrippedLog(block)) {
List<Block> logs = Vein.find(block, 20, this::isUnstrippedLog);
if (logs.contains(block)) {
logs.remove(block);
}
for (Block b : logs) {
Material type = b.getType();
if (SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b, ProtectableAction.BREAK_BLOCK)) {
b.getWorld().playSound(b.getLocation(), Sound.ITEM_AXE_STRIP, 1, 1);
Axis axis = ((Orientable) b.getBlockData()).getAxis();
b.setType(Material.valueOf("STRIPPED_" + type.name()));
Orientable orientable = (Orientable) b.getBlockData();
orientable.setAxis(axis);
b.setBlockData(orientable);
}
}
}
}
};
}
private boolean isUnstrippedLog(Block block) {
return Tag.LOGS.isTagged(block.getType()) && !block.getType().name().startsWith("STRIPPED_");
}
}

View File

@ -9,7 +9,6 @@ import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.cscorelib2.recipes.MinecraftRecipe;
import io.github.thebusybiscuit.slimefun4.core.attributes.DamageableItem;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
@ -48,7 +47,7 @@ public class SmeltersPickaxe extends SimpleSlimefunItem<BlockBreakHandler> imple
ItemStack output = drop;
output.setAmount(fortune);
Optional<ItemStack> furnaceOutput = SlimefunPlugin.getMinecraftRecipes().getRecipeOutput(MinecraftRecipe.FURNACE, drop);
Optional<ItemStack> furnaceOutput = SlimefunPlugin.getMinecraftRecipes().getFurnaceOutput(drop);
if (furnaceOutput.isPresent()) {
e.getBlock().getWorld().playEffect(e.getBlock().getLocation(), Effect.MOBSPAWNER_FLAMES, 1);
output.setType(furnaceOutput.get().getType());

View File

@ -11,7 +11,6 @@ import org.bukkit.event.inventory.FurnaceSmeltEvent;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.recipes.MinecraftRecipe;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.EnhancedFurnace;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
@ -51,7 +50,7 @@ public class EnhancedFurnaceListener implements Listener {
Optional<ItemStack> result = Optional.ofNullable(furnace.getInventory().getResult());
if (!result.isPresent()) {
result = SlimefunPlugin.getMinecraftRecipes().getRecipeOutput(MinecraftRecipe.FURNACE, furnace.getInventory().getSmelting());
result = SlimefunPlugin.getMinecraftRecipes().getFurnaceOutput(furnace.getInventory().getSmelting());
}
if (result.isPresent()) {

View File

@ -7,7 +7,6 @@ import java.util.Random;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.enchantments.Enchantment;
@ -35,10 +34,10 @@ import org.bukkit.util.Vector;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.materials.MaterialCollections;
import io.github.thebusybiscuit.slimefun4.implementation.items.magical.Talisman;
import io.github.thebusybiscuit.slimefun4.utils.PatternUtils;
import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.api.Slimefun;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class TalismanListener implements Listener {
@ -51,24 +50,33 @@ public class TalismanListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onDamageGet(EntityDamageEvent e) {
if (e.getEntity() instanceof Player) {
if (e.getCause() == DamageCause.LAVA) Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_LAVA);
if (e.getCause() == DamageCause.DROWNING) Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_WATER);
if (e.getCause() == DamageCause.FALL) Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_ANGEL);
if (e.getCause() == DamageCause.FIRE) Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_FIRE);
if (e.getCause() == DamageCause.ENTITY_ATTACK) Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_WARRIOR);
if (e.getCause() == DamageCause.ENTITY_ATTACK) Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_KNIGHT);
if (e.getCause() == DamageCause.PROJECTILE && ((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile && Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_WHIRLWIND)) {
Vector direction = ((Player) e.getEntity()).getEyeLocation().getDirection().multiply(2.0);
Projectile projectile = (Projectile) e.getEntity().getWorld().spawnEntity(((LivingEntity) e.getEntity()).getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), ((EntityDamageByEntityEvent) e).getDamager().getType());
projectile.setVelocity(direction);
((EntityDamageByEntityEvent) e).getDamager().remove();
if (e.getCause() == DamageCause.LAVA) Talisman.checkFor(e, SlimefunItems.TALISMAN_LAVA);
if (e.getCause() == DamageCause.DROWNING) Talisman.checkFor(e, SlimefunItems.TALISMAN_WATER);
if (e.getCause() == DamageCause.FALL) Talisman.checkFor(e, SlimefunItems.TALISMAN_ANGEL);
if (e.getCause() == DamageCause.FIRE) Talisman.checkFor(e, SlimefunItems.TALISMAN_FIRE);
if (e.getCause() == DamageCause.ENTITY_ATTACK) {
Talisman.checkFor(e, SlimefunItems.TALISMAN_KNIGHT);
Talisman.checkFor(e, SlimefunItems.TALISMAN_WARRIOR);
}
if (e.getCause() == DamageCause.PROJECTILE && ((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) ((EntityDamageByEntityEvent) e).getDamager();
if (Talisman.checkFor(e, SlimefunItems.TALISMAN_WHIRLWIND)) {
Vector direction = ((Player) e.getEntity()).getEyeLocation().getDirection().multiply(2.0);
Projectile clone = (Projectile) e.getEntity().getWorld().spawnEntity(((LivingEntity) e.getEntity()).getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), projectile.getType());
clone.setShooter(projectile.getShooter());
clone.setVelocity(direction);
projectile.remove();
}
}
}
}
@EventHandler(ignoreCancelled = true)
public void onKill(EntityDeathEvent e) {
if (e.getEntity().getKiller() != null && !(e.getEntity() instanceof Player) && !e.getEntity().getCanPickupItems() && Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_HUNTER)) {
if (e.getEntity().getKiller() != null && !(e.getEntity() instanceof Player) && !e.getEntity().getCanPickupItems() && Talisman.checkFor(e, SlimefunItems.TALISMAN_HUNTER)) {
List<ItemStack> extraDrops = new ArrayList<>(e.getDrops());
if (e.getEntity() instanceof ChestedHorse) {
@ -88,7 +96,7 @@ public class TalismanListener implements Listener {
@EventHandler
public void onItemBreak(PlayerItemBreakEvent e) {
if (Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_ANVIL)) {
if (Talisman.checkFor(e, SlimefunItems.TALISMAN_ANVIL)) {
PlayerInventory inv = e.getPlayer().getInventory();
int slot = inv.getHeldItemSlot();
@ -119,7 +127,7 @@ public class TalismanListener implements Listener {
@EventHandler
public void onSprint(PlayerToggleSprintEvent e) {
if (e.isSprinting()) {
Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_TRAVELLER);
Talisman.checkFor(e, SlimefunItems.TALISMAN_TRAVELLER);
}
}
@ -127,7 +135,7 @@ public class TalismanListener implements Listener {
public void onEnchant(EnchantItemEvent e) {
Random random = ThreadLocalRandom.current();
if (Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_MAGICIAN)) {
if (Talisman.checkFor(e, SlimefunItems.TALISMAN_MAGICIAN)) {
List<String> enchantments = new LinkedList<>();
for (Enchantment en : Enchantment.values()) {
@ -143,7 +151,7 @@ public class TalismanListener implements Listener {
e.getEnchantsToAdd().put(Enchantment.getByKey(NamespacedKey.minecraft(enchantSplit[0])), Integer.parseInt(enchantSplit[1]));
}
if (!e.getEnchantsToAdd().containsKey(Enchantment.SILK_TOUCH) && Enchantment.LOOT_BONUS_BLOCKS.canEnchantItem(e.getItem()) && Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_WIZARD)) {
if (!e.getEnchantsToAdd().containsKey(Enchantment.SILK_TOUCH) && Enchantment.LOOT_BONUS_BLOCKS.canEnchantItem(e.getItem()) && Talisman.checkFor(e, SlimefunItems.TALISMAN_WIZARD)) {
Set<Enchantment> enchantments = e.getEnchantsToAdd().keySet();
for (Enchantment en : enchantments) {
@ -176,7 +184,7 @@ public class TalismanListener implements Listener {
fortune = (e.getBlock().getType() == Material.LAPIS_ORE ? 4 + random.nextInt(5) : 1) * (fortune + 1);
}
if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && MaterialCollections.getAllOres().contains(e.getBlock().getType()) && Talisman.checkFor(e, (SlimefunItemStack) SlimefunItems.TALISMAN_MINER)) {
if (!item.getEnchantments().containsKey(Enchantment.SILK_TOUCH) && MaterialCollections.getAllOres().contains(e.getBlock().getType()) && Talisman.checkFor(e, SlimefunItems.TALISMAN_MINER)) {
for (ItemStack drop : drops) {
if (!drop.getType().isBlock()) {
int amount = Math.max(1, (fortune * 2) - drop.getAmount());

View File

@ -25,6 +25,7 @@ import com.google.gson.JsonParser;
import io.github.thebusybiscuit.slimefun4.implementation.items.electric.machines.AutomatedCraftingChamber;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.EnhancedCraftingTable;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.GrindStone;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.MakeshiftSmeltery;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.OreCrusher;
import io.github.thebusybiscuit.slimefun4.implementation.items.multiblocks.Smeltery;
import me.mrCookieSlime.CSCoreLibPlugin.general.Inventory.Item.CustomItemSerializer;
@ -34,7 +35,6 @@ import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.abstractItems.AContainer;
import me.mrCookieSlime.Slimefun.Setup.SlimefunManager;
import me.mrCookieSlime.Slimefun.api.Slimefun;
public final class PostSetup {
@ -63,6 +63,20 @@ public final class PostSetup {
}
}
public static void setupItemSettings() {
for (World world : Bukkit.getWorlds()) {
SlimefunPlugin.getWhitelist().setDefaultValue(world.getName() + ".enabled-items.SLIMEFUN_GUIDE", true);
}
Slimefun.setItemVariable("ORE_CRUSHER", "double-ores", true);
for (Enchantment enchantment : Enchantment.values()) {
for (int i = 1; i <= enchantment.getMaxLevel(); i++) {
Slimefun.setItemVariable("MAGICIAN_TALISMAN", "allow-enchantments." + enchantment.getKey().getKey() + ".level." + i, true);
}
}
}
public static void loadItems() {
Iterator<SlimefunItem> iterator = SlimefunPlugin.getRegistry().getEnabledSlimefunItems().iterator();
@ -159,25 +173,19 @@ public final class PostSetup {
else {
if (input[0] != null && recipe[0] != null) {
List<ItemStack> inputs = new ArrayList<>();
boolean dust = false;
for (ItemStack item : input) {
if (item != null) {
inputs.add(item);
if (SlimefunManager.isItemSimilar(item, SlimefunItems.ALUMINUM_DUST, true)) dust = true;
if (SlimefunManager.isItemSimilar(item, SlimefunItems.COPPER_DUST, true)) dust = true;
if (SlimefunManager.isItemSimilar(item, SlimefunItems.GOLD_DUST, true)) dust = true;
if (SlimefunManager.isItemSimilar(item, SlimefunItems.IRON_DUST, true)) dust = true;
if (SlimefunManager.isItemSimilar(item, SlimefunItems.LEAD_DUST, true)) dust = true;
if (SlimefunManager.isItemSimilar(item, SlimefunItems.MAGNESIUM_DUST, true)) dust = true;
if (SlimefunManager.isItemSimilar(item, SlimefunItems.SILVER_DUST, true)) dust = true;
if (SlimefunManager.isItemSimilar(item, SlimefunItems.TIN_DUST, true)) dust = true;
if (SlimefunManager.isItemSimilar(item, SlimefunItems.ZINC_DUST, true)) dust = true;
}
}
// We want to exclude Dust to Ingot Recipes
if (!(dust && inputs.size() == 1)) {
if (inputs.size() == 1 && isDust(inputs.get(0))) {
((MakeshiftSmeltery) SlimefunItems.MAKESHIFT_SMELTERY.getItem()).addRecipe(new ItemStack[] { inputs.get(0) }, recipe[0]);
registerMachineRecipe("ELECTRIC_INGOT_FACTORY", 8, new ItemStack[] { inputs.get(0) }, new ItemStack[] { recipe[0] });
}
else {
registerMachineRecipe("ELECTRIC_SMELTERY", 12, inputs.toArray(new ItemStack[0]), new ItemStack[] { recipe[0] });
}
}
@ -219,6 +227,11 @@ public final class PostSetup {
SlimefunPlugin.getWhitelist().save();
}
private static boolean isDust(ItemStack item) {
SlimefunItem sfItem = SlimefunItem.getByItem(item);
return sfItem != null && sfItem.getID().endsWith("_DUST");
}
private static void registerMachineRecipe(String machine, int seconds, ItemStack[] input, ItemStack[] output) {
for (SlimefunItem item : SlimefunPlugin.getRegistry().getEnabledSlimefunItems()) {
if (item instanceof AContainer && ((AContainer) item).getMachineIdentifier().equals(machine)) {
@ -226,18 +239,4 @@ public final class PostSetup {
}
}
}
public static void setupItemSettings() {
for (World world : Bukkit.getWorlds()) {
SlimefunPlugin.getWhitelist().setDefaultValue(world.getName() + ".enabled-items.SLIMEFUN_GUIDE", true);
}
Slimefun.setItemVariable("ORE_CRUSHER", "double-ores", true);
for (Enchantment enchantment : Enchantment.values()) {
for (int i = 1; i <= enchantment.getMaxLevel(); i++) {
Slimefun.setItemVariable("MAGICIAN_TALISMAN", "allow-enchantments." + enchantment.getKey().getKey() + ".level." + i, true);
}
}
}
}

View File

@ -352,7 +352,7 @@ public final class SlimefunItemSetup {
new ItemStack[] {null, null, null, new ItemStack(Material.STONE), new ItemStack(Material.BOWL), new ItemStack(Material.STONE), new ItemStack(Material.STONE), new ItemStack(Material.STONE), new ItemStack(Material.STONE)})
.register(plugin);
new NetherGoldPan(Categories.TOOLS, (SlimefunItemStack) SlimefunItems.NETHER_GOLD_PAN, RecipeType.ENHANCED_CRAFTING_TABLE,
new NetherGoldPan(Categories.TOOLS, SlimefunItems.NETHER_GOLD_PAN, RecipeType.ENHANCED_CRAFTING_TABLE,
new ItemStack[] {null, null, null, new ItemStack(Material.NETHER_BRICK), SlimefunItems.GOLD_PAN, new ItemStack(Material.NETHER_BRICK), new ItemStack(Material.NETHER_BRICK), new ItemStack(Material.NETHER_BRICK), new ItemStack(Material.NETHER_BRICK)})
.register(plugin);

View File

@ -31,17 +31,17 @@ import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
public class RecipeType implements Keyed {
public static final RecipeType MULTIBLOCK = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "multiblock"), new CustomItem(Material.BRICKS, "&bMultiBlock", "", "&a&oBuild it in the World"));
public static final RecipeType ARMOR_FORGE = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "armor_forge"), (SlimefunItemStack) SlimefunItems.ARMOR_FORGE, "", "&a&oCraft it in an Armor Forge");
public static final RecipeType GRIND_STONE = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "grind_stone"), (SlimefunItemStack) SlimefunItems.GRIND_STONE, "", "&a&oGrind it using the Grind Stone");
public static final RecipeType SMELTERY = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "smeltery"), (SlimefunItemStack) SlimefunItems.SMELTERY, "", "&a&oSmelt it using a Smeltery");
public static final RecipeType ORE_CRUSHER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "ore_crusher"), (SlimefunItemStack) SlimefunItems.ORE_CRUSHER, "", "&a&oCrush it using the Ore Crusher");
public static final RecipeType GOLD_PAN = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "gold_pan"), (SlimefunItemStack) SlimefunItems.GOLD_PAN, "", "&a&oUse a Gold Pan on Gravel to obtain this Item");
public static final RecipeType COMPRESSOR = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "compressor"), (SlimefunItemStack) SlimefunItems.COMPRESSOR, "", "&a&oCompress it using the Compressor");
public static final RecipeType PRESSURE_CHAMBER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "pressure_chamber"), (SlimefunItemStack) SlimefunItems.PRESSURE_CHAMBER, "", "&a&oCompress it using the Pressure Chamber");
public static final RecipeType MAGIC_WORKBENCH = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "magic_workbench"), (SlimefunItemStack) SlimefunItems.MAGIC_WORKBENCH, "", "&a&oCraft it in a Magic Workbench");
public static final RecipeType ORE_WASHER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "ore_washer"), (SlimefunItemStack) SlimefunItems.ORE_WASHER, "", "&a&oWash it in an Ore Washer");
public static final RecipeType ENHANCED_CRAFTING_TABLE = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "enhanced_crafting_table"), (SlimefunItemStack) SlimefunItems.ENHANCED_CRAFTING_TABLE, "", "&a&oA regular Crafting Table cannot", "&a&ohold this massive Amount of Power...");
public static final RecipeType JUICER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "juicer"), (SlimefunItemStack) SlimefunItems.JUICER, "", "&a&oUsed for Juice Creation");
public static final RecipeType ARMOR_FORGE = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "armor_forge"), SlimefunItems.ARMOR_FORGE, "", "&a&oCraft it in an Armor Forge");
public static final RecipeType GRIND_STONE = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "grind_stone"), SlimefunItems.GRIND_STONE, "", "&a&oGrind it using the Grind Stone");
public static final RecipeType SMELTERY = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "smeltery"), SlimefunItems.SMELTERY, "", "&a&oSmelt it using a Smeltery");
public static final RecipeType ORE_CRUSHER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "ore_crusher"), SlimefunItems.ORE_CRUSHER, "", "&a&oCrush it using the Ore Crusher");
public static final RecipeType GOLD_PAN = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "gold_pan"), SlimefunItems.GOLD_PAN, "", "&a&oUse a Gold Pan on Gravel to obtain this Item");
public static final RecipeType COMPRESSOR = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "compressor"), SlimefunItems.COMPRESSOR, "", "&a&oCompress it using the Compressor");
public static final RecipeType PRESSURE_CHAMBER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "pressure_chamber"), SlimefunItems.PRESSURE_CHAMBER, "", "&a&oCompress it using the Pressure Chamber");
public static final RecipeType MAGIC_WORKBENCH = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "magic_workbench"), SlimefunItems.MAGIC_WORKBENCH, "", "&a&oCraft it in a Magic Workbench");
public static final RecipeType ORE_WASHER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "ore_washer"), SlimefunItems.ORE_WASHER, "", "&a&oWash it in an Ore Washer");
public static final RecipeType ENHANCED_CRAFTING_TABLE = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "enhanced_crafting_table"), SlimefunItems.ENHANCED_CRAFTING_TABLE, "", "&a&oA regular Crafting Table cannot", "&a&ohold this massive Amount of Power...");
public static final RecipeType JUICER = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "juicer"), SlimefunItems.JUICER, "", "&a&oUsed for Juice Creation");
public static final RecipeType ANCIENT_ALTAR = new RecipeType(new NamespacedKey(SlimefunPlugin.instance, "ancient_altar"), SlimefunItems.ANCIENT_ALTAR, (recipe, output) -> {
AltarRecipe altarRecipe = new AltarRecipe(Arrays.asList(recipe), output);
@ -193,16 +193,16 @@ public class RecipeType implements Keyed {
convertible.sort(Comparator.comparing(recipe -> {
int emptySlots = 9;
for (ItemStack ingredient : recipe) {
if (ingredient != null) {
emptySlots--;
}
}
return emptySlots;
}));
return convertible;
}

View File

@ -461,9 +461,10 @@ public final class SlimefunItems {
public static final ItemStack SILVER_DUST = new SlimefunItemStack("SILVER_DUST", Material.SUGAR, "&6Silver Dust");
public static final ItemStack ALUMINUM_DUST = new SlimefunItemStack("ALUMINUM_DUST", Material.SUGAR, "&6Aluminum Dust");
public static final ItemStack LEAD_DUST = new SlimefunItemStack("LEAD_DUST", Material.GUNPOWDER, "&6Lead Dust");
public static final ItemStack SULFATE = new SlimefunItemStack("SULFATE", Material.GLOWSTONE_DUST, "&6Sulfate");
public static final ItemStack ZINC_DUST = new SlimefunItemStack("ZINC_DUST", Material.SUGAR, "&6Zinc Dust");
public static final ItemStack MAGNESIUM_DUST = new SlimefunItemStack("MAGNESIUM_DUST", Material.SUGAR, "&6Magnesium");
public static final ItemStack SULFATE = new SlimefunItemStack("SULFATE", Material.GLOWSTONE_DUST, "&6Sulfate");
public static final ItemStack SILICON = new SlimefunItemStack("SILICON", Material.FIREWORK_STAR, "&6Silicon");
public static final ItemStack GOLD_24K_BLOCK = new SlimefunItemStack("GOLD_24K_BLOCK", Material.GOLD_BLOCK, "&rGold Block &7(24-Carat)");

View File

@ -14,7 +14,6 @@ import org.bukkit.plugin.java.JavaPlugin;
import io.github.thebusybiscuit.cscorelib2.config.Config;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectionManager;
import io.github.thebusybiscuit.cscorelib2.recipes.RecipeSnapshot;
import io.github.thebusybiscuit.cscorelib2.reflection.ReflectionUtils;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.api.gps.GPSNetwork;
@ -27,6 +26,7 @@ import io.github.thebusybiscuit.slimefun4.core.services.BlockDataService;
import io.github.thebusybiscuit.slimefun4.core.services.CustomItemDataService;
import io.github.thebusybiscuit.slimefun4.core.services.CustomTextureService;
import io.github.thebusybiscuit.slimefun4.core.services.LocalizationService;
import io.github.thebusybiscuit.slimefun4.core.services.MinecraftRecipeService;
import io.github.thebusybiscuit.slimefun4.core.services.PermissionsService;
import io.github.thebusybiscuit.slimefun4.core.services.UpdaterService;
import io.github.thebusybiscuit.slimefun4.core.services.github.GitHubService;
@ -97,15 +97,16 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
// Services - Systems that fulfill certain tasks, treat them as a black box
private final CustomItemDataService itemDataService = new CustomItemDataService(this, "slimefun_item");
private final CustomTextureService textureService = new CustomTextureService(this);
private final BlockDataService blockDataService = new BlockDataService(this, "slimefun_block");
private final CustomTextureService textureService = new CustomTextureService(this);
private final GitHubService gitHubService = new GitHubService("TheBusyBiscuit/Slimefun4");
private final UpdaterService updaterService = new UpdaterService(this, getFile());
private final MetricsService metricsService = new MetricsService(this);
private final AutoSavingService autoSavingService = new AutoSavingService();
private final BackupService backupService = new BackupService();
private final MetricsService metricsService = new MetricsService(this);
private final PermissionsService permissionsService = new PermissionsService(this);
private final ThirdPartyPluginService thirdPartySupportService = new ThirdPartyPluginService(this);
private final MinecraftRecipeService recipeService = new MinecraftRecipeService(this);
private LocalizationService local;
private GPSNetwork gpsNetwork;
@ -114,7 +115,6 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
private TickerTask ticker;
private SlimefunCommand command;
private RecipeSnapshot recipeSnapshot;
private Config researches;
private Config items;
@ -230,7 +230,7 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
ancientAltarListener = new AncientAltarListener();
grapplingHookListener = new GrapplingHookListener();
// Toggleable Listeners for performance
// Toggleable Listeners for performance reasons
if (config.getBoolean("items.talismans")) {
new TalismanListener(this);
}
@ -256,8 +256,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
Slimefun.runSync(() -> {
textureService.register(registry.getAllSlimefunItems());
permissionsService.register(registry.getAllSlimefunItems());
recipeService.load();
recipeSnapshot = new RecipeSnapshot(this);
protections = new ProtectionManager(getServer());
PostSetup.loadItems();
@ -382,8 +382,10 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
@Override
public void onDisable() {
// CS-CoreLib wasn't loaded, just disabling
if (instance == null) return;
// Slimefun never loaded successfully, so we don't even bother doing stuff here
if (instance == null) {
return;
}
Bukkit.getScheduler().cancelTasks(this);
@ -497,8 +499,8 @@ public final class SlimefunPlugin extends JavaPlugin implements SlimefunAddon {
return instance.local;
}
public static RecipeSnapshot getMinecraftRecipes() {
return instance.recipeSnapshot;
public static MinecraftRecipeService getMinecraftRecipes() {
return instance.recipeService;
}
public static CustomItemDataService getItemDataService() {