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

Small improvements

This commit is contained in:
TheBusyBiscuit 2020-09-05 14:45:42 +02:00
parent 8061df9b5e
commit ec9133cf8a
6 changed files with 46 additions and 31 deletions

View File

@ -60,6 +60,8 @@
* (API) Rewritten Block-Energy API
* Removed "durability" setting from cargo nodes
* Small performance improvements for radiation
* Small performance improvements for Auto Disenchanters
* Magnesium Salt in Magnesium-Salt generators now lasts longer
#### Fixes
* Fixed Programmable Androids rotating in the wrong direction

View File

@ -1,6 +1,7 @@
package io.github.thebusybiscuit.slimefun4.implementation.items;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.inventory.ItemStack;
@ -68,7 +69,7 @@ public class RadioactiveItem extends SlimefunItem implements Radioactive, NotPla
* The recipe output
*/
@ParametersAreNonnullByDefault
public RadioactiveItem(Category category, Radioactivity radioactivity, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, ItemStack recipeOutput) {
public RadioactiveItem(Category category, Radioactivity radioactivity, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, @Nullable ItemStack recipeOutput) {
super(category, item, recipeType, recipe, recipeOutput);
this.radioactivity = radioactivity;

View File

@ -6,6 +6,7 @@ import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import io.github.thebusybiscuit.slimefun4.api.items.ItemSetting;
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
@ -51,12 +52,14 @@ public class SolarHelmet extends SlimefunItem {
* The {@link Player} wearing this {@link SolarHelmet}
*/
public void rechargeItems(@Nonnull Player p) {
recharge(p.getInventory().getHelmet());
recharge(p.getInventory().getChestplate());
recharge(p.getInventory().getLeggings());
recharge(p.getInventory().getBoots());
recharge(p.getInventory().getItemInMainHand());
recharge(p.getInventory().getItemInOffHand());
PlayerInventory inv = p.getInventory();
recharge(inv.getHelmet());
recharge(inv.getChestplate());
recharge(inv.getLeggings());
recharge(inv.getBoots());
recharge(inv.getItemInMainHand());
recharge(inv.getItemInOffHand());
}
private void recharge(@Nullable ItemStack item) {

View File

@ -18,7 +18,7 @@ public abstract class MagnesiumGenerator extends AGenerator {
@Override
protected void registerDefaultFuelTypes() {
registerFuel(new MachineFuel(12, SlimefunItems.MAGNESIUM_SALT));
registerFuel(new MachineFuel(20, SlimefunItems.MAGNESIUM_SALT));
}
@Override

View File

@ -81,7 +81,7 @@ public class AutoDisenchanter extends AContainer {
ItemStack target = menu.getItemInSlot(slot == getInputSlots()[0] ? getInputSlots()[1] : getInputSlots()[0]);
// Disenchanting
if (item != null && target != null && target.getType() == Material.BOOK) {
if (target != null && target.getType() == Material.BOOK) {
int amount = 0;
for (Map.Entry<Enchantment, Integer> entry : item.getEnchantments().entrySet()) {
@ -145,14 +145,18 @@ public class AutoDisenchanter extends AContainer {
}
private boolean isDisenchantable(ItemStack item) {
SlimefunItem sfItem = null;
// stops endless checks of getByItem for empty book stacks.
if (item != null && item.getType() != Material.BOOK) {
sfItem = SlimefunItem.getByItem(item);
if (item == null) {
return false;
}
// stops endless checks of getByItem for books
else if (item.getType() != Material.BOOK) {
SlimefunItem sfItem = SlimefunItem.getByItem(item);
return sfItem == null || sfItem.isDisenchantable();
}
else {
return true;
}
return sfItem == null || sfItem.isDisenchantable();
}
@Override

View File

@ -41,19 +41,19 @@ public class SlimefunItemStack extends CustomItem {
private boolean locked = false;
private String texture = null;
public SlimefunItemStack(String id, Material type, String name, String... lore) {
public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nullable String name, String... lore) {
super(type, name, lore);
setItemId(id);
}
public SlimefunItemStack(String id, Material type, Color color, String name, String... lore) {
public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nonnull Color color, @Nullable String name, String... lore) {
super(new ItemStack(type), color, name, lore);
setItemId(id);
}
public SlimefunItemStack(String id, Color color, PotionEffect effect, String name, String... lore) {
public SlimefunItemStack(@Nonnull String id, @Nonnull Color color, @Nonnull PotionEffect effect, @Nullable String name, String... lore) {
super(Material.POTION, im -> {
if (name != null) {
im.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
@ -82,30 +82,30 @@ public class SlimefunItemStack extends CustomItem {
setItemId(id);
}
public SlimefunItemStack(String id, ItemStack item, String name, String... lore) {
public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nullable String name, String... lore) {
super(item, name, lore);
setItemId(id);
}
public SlimefunItemStack(String id, ItemStack item) {
public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item) {
super(item);
setItemId(id);
}
public SlimefunItemStack(SlimefunItemStack item, int amount) {
public SlimefunItemStack(@Nonnull SlimefunItemStack item, int amount) {
this(item.getItemId(), item);
setAmount(amount);
}
public SlimefunItemStack(String id, ItemStack item, Consumer<ItemMeta> consumer) {
public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nonnull Consumer<ItemMeta> consumer) {
super(item, consumer);
setItemId(id);
}
public SlimefunItemStack(String id, Material type, String name, Consumer<ItemMeta> consumer) {
public SlimefunItemStack(@Nonnull String id, @Nonnull Material type, @Nullable String name, @Nonnull Consumer<ItemMeta> consumer) {
super(type, meta -> {
if (name != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
@ -117,18 +117,18 @@ public class SlimefunItemStack extends CustomItem {
setItemId(id);
}
public SlimefunItemStack(String id, String texture, String name, String... lore) {
public SlimefunItemStack(@Nonnull String id, @Nonnull String texture, @Nullable String name, String... lore) {
super(getSkull(id, texture), name, lore);
this.texture = getTexture(id, texture);
setItemId(id);
}
public SlimefunItemStack(String id, HeadTexture head, String name, String... lore) {
public SlimefunItemStack(@Nonnull String id, @Nonnull HeadTexture head, @Nullable String name, String... lore) {
this(id, head.getTexture(), name, lore);
}
public SlimefunItemStack(String id, String texture, String name, Consumer<ItemMeta> consumer) {
public SlimefunItemStack(@Nonnull String id, @Nonnull String texture, @Nullable String name, @Nonnull Consumer<ItemMeta> consumer) {
super(getSkull(id, texture), meta -> {
if (name != null) {
meta.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
@ -142,7 +142,7 @@ public class SlimefunItemStack extends CustomItem {
setItemId(id);
}
public SlimefunItemStack(String id, String texture, Consumer<ItemMeta> consumer) {
public SlimefunItemStack(@Nonnull String id, @Nonnull String texture, @Nonnull Consumer<ItemMeta> consumer) {
super(getSkull(id, texture), consumer);
this.texture = getTexture(id, texture);
@ -202,11 +202,13 @@ public class SlimefunItemStack extends CustomItem {
*
* @return The {@link SlimefunItem} this {@link SlimefunItem} represents, casted to the given type
*/
public <T extends SlimefunItem> T getItem(Class<T> type) {
@Nullable
public <T extends SlimefunItem> T getItem(@Nonnull Class<T> type) {
SlimefunItem item = getItem();
return type.isInstance(item) ? type.cast(item) : null;
}
@Nonnull
public ImmutableItemMeta getImmutableMeta() {
return immutableMeta;
}
@ -251,20 +253,23 @@ public class SlimefunItemStack extends CustomItem {
return "SlimefunItemStack (" + id + (getAmount() > 1 ? (" x " + getAmount()) : "") + ')';
}
@Nonnull
public Optional<String> getSkullTexture() {
return Optional.ofNullable(texture);
}
@Nullable
public String getDisplayName() {
if (immutableMeta == null) {
// Just to be extra safe
return null;
}
return immutableMeta.getDisplayName().orElse(null);
}
private static ItemStack getSkull(String id, String texture) {
@Nonnull
private static ItemStack getSkull(@Nonnull String id, @Nonnull String texture) {
if (SlimefunPlugin.getMinecraftVersion() == MinecraftVersion.UNIT_TEST) {
return new ItemStack(Material.PLAYER_HEAD);
}
@ -276,7 +281,7 @@ public class SlimefunItemStack extends CustomItem {
private static String getTexture(@Nonnull String id, @Nonnull String texture) {
Validate.notNull(id, "The id cannot be null");
Validate.notNull(texture, "The texture cannot be null");
if (texture.startsWith("ey")) {
return texture;
}