1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Many more fixes

This commit is contained in:
TheBusyBiscuit 2021-02-06 01:54:08 +01:00
parent 340005109b
commit e8a67cdd6a
6 changed files with 34 additions and 13 deletions

View File

@ -343,7 +343,7 @@
<dependency>
<groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>CS-CoreLib2</artifactId>
<version>0.29.6</version>
<version>0.30.0</version>
<scope>compile</scope>
</dependency>
<dependency>

View File

@ -10,6 +10,8 @@ import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.NamespacedKey;
import org.bukkit.Server;
import org.bukkit.inventory.FurnaceRecipe;
import org.bukkit.inventory.ItemStack;
@ -160,4 +162,16 @@ public class MinecraftRecipeService {
}
}
@Nullable
public Recipe getRecipe(@Nonnull NamespacedKey key) {
Validate.notNull(key, "The NamespacedKey should not be null");
if (snapshot != null) {
// We operate on a cached HashMap which is much faster than Bukkit's method.
return snapshot.getRecipe(key);
} else {
return Bukkit.getRecipe(key);
}
}
}

View File

@ -10,6 +10,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Particle;
@ -24,7 +25,6 @@ import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import io.github.thebusybiscuit.cscorelib2.data.PersistentDataAPI;
import io.github.thebusybiscuit.cscorelib2.inventory.InvUtils;
import io.github.thebusybiscuit.cscorelib2.item.CustomItem;
import io.github.thebusybiscuit.cscorelib2.protection.ProtectableAction;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
@ -148,7 +148,8 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
if (craft(inv, recipe)) {
// We are done crafting!
b.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, b.getLocation(), 16);
Location loc = b.getLocation().add(0.5, 0.8, 0.5);
b.getWorld().spawnParticle(Particle.VILLAGER_HAPPY, loc, 6);
removeCharge(b.getLocation(), getEnergyConsumption());
}
}
@ -239,8 +240,10 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
@ParametersAreNonnullByDefault
protected boolean matchesAny(Inventory inv, Map<Integer, Integer> itemQuantities, Predicate<ItemStack> predicate) {
for (int slot = 0; slot < inv.getSize(); slot++) {
ItemStack item = inv.getItem(slot);
ItemStack[] contents = inv.getContents();
for (int slot = 0; slot < contents.length; slot++) {
ItemStack item = contents[slot];
if (item != null) {
int amount = itemQuantities.getOrDefault(slot, item.getAmount());
@ -260,7 +263,8 @@ public abstract class AbstractAutoCrafter extends SlimefunItem implements Energy
Validate.notNull(inv, "The Inventory must not be null");
Validate.notNull(recipe, "The Recipe shall not be null");
if (InvUtils.fits(inv, recipe.getResult())) {
// Check if we have an empty slot
if (inv.firstEmpty() != -1) {
Map<Integer, Integer> itemQuantities = new HashMap<>();
for (Predicate<ItemStack> predicate : recipe.getInputs()) {

View File

@ -68,7 +68,7 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
@SuppressWarnings("deprecation")
NamespacedKey key = new NamespacedKey(values[0], values[1]);
return Bukkit.getRecipe(key);
return SlimefunPlugin.getMinecraftRecipeService().getRecipe(key);
}
}
@ -115,7 +115,7 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
private void offerRecipe(Player p, Block b, List<Recipe> recipes, int index, ChestMenu menu, AsyncRecipeChoiceTask task) {
Validate.isTrue(index >= 0 && index < recipes.size(), "page must be between 0 and " + (recipes.size() - 1));
menu.addItem(46, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.size()));
menu.replaceExistingItem(46, ChestMenuUtils.getPreviousButton(p, index + 1, recipes.size()));
menu.addMenuClickHandler(46, (pl, slot, item, action) -> {
if (index > 0) {
pl.playSound(pl.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
@ -125,7 +125,7 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
return false;
});
menu.addItem(52, ChestMenuUtils.getNextButton(p, index + 1, recipes.size()));
menu.replaceExistingItem(52, ChestMenuUtils.getNextButton(p, index + 1, recipes.size()));
menu.addMenuClickHandler(52, (pl, slot, item, action) -> {
if (index < (recipes.size() - 1)) {
pl.playSound(pl.getLocation(), Sound.UI_BUTTON_CLICK, 1, 1);
@ -137,7 +137,7 @@ public class VanillaAutoCrafter extends AbstractAutoCrafter {
AbstractRecipe recipe = AbstractRecipe.of(recipes.get(index));
menu.addItem(49, new CustomItem(Material.CRAFTING_TABLE, ChatColor.GREEN + SlimefunPlugin.getLocalization().getMessage(p, "messages.auto-crafting.select")));
menu.replaceExistingItem(49, new CustomItem(Material.CRAFTING_TABLE, ChatColor.GREEN + SlimefunPlugin.getLocalization().getMessage(p, "messages.auto-crafting.select")));
menu.addMenuClickHandler(49, (pl, slot, item, action) -> {
setSelectedRecipe(b, recipe);
pl.closeInventory();

View File

@ -70,7 +70,9 @@ class VanillaRecipe extends AbstractRecipe {
@Override
public void show(@Nonnull ChestMenu menu, @Nonnull AsyncRecipeChoiceTask task) {
menu.addItem(24, getResult().clone(), ChestMenuUtils.getEmptyClickHandler());
menu.replaceExistingItem(24, getResult().clone());
menu.addMenuClickHandler(24, ChestMenuUtils.getEmptyClickHandler());
RecipeChoice[] choices = SlimefunPlugin.getMinecraftRecipeService().getRecipeShape(recipe);
ItemStack[] items = new ItemStack[9];
@ -93,7 +95,8 @@ class VanillaRecipe extends AbstractRecipe {
}
for (int i = 0; i < 9; i++) {
menu.addItem(slots[i], items[i], ChestMenuUtils.getEmptyClickHandler());
menu.replaceExistingItem(slots[i], items[i]);
menu.addMenuClickHandler(slots[i], ChestMenuUtils.getEmptyClickHandler());
}
}

View File

@ -60,7 +60,7 @@ public interface InventoryBlock {
@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.inventory.bypass") || (SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.ACCESS_INVENTORIES) && Slimefun.hasUnlocked(p, item, false));
return p.hasPermission("slimefun.inventory.bypass") || (SlimefunPlugin.getProtectionManager().hasPermission(p, b.getLocation(), ProtectableAction.INTERACT_BLOCK) && Slimefun.hasUnlocked(p, item, false));
}
};
}