Skip to content

Commit

Permalink
Use delegation... this is gonna be a long pr
Browse files Browse the repository at this point in the history
  • Loading branch information
Intybyte committed Oct 22, 2024
1 parent 6f2f30d commit a62ecff
Show file tree
Hide file tree
Showing 21 changed files with 80 additions and 54 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,13 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.32</version>
<scope>provided</scope>
</dependency>

<!-- Third party plugin integrations / soft dependencies -->
<dependency>
<groupId>com.sk89q.worldedit</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public SlimefunItem(ItemGroup itemGroup, SlimefunItemStack item, RecipeType reci
Validate.notNull(recipeType, "'recipeType' is not allowed to be null!");

this.itemGroup = itemGroup;
this.itemStackTemplate = item;
this.itemStackTemplate = item.getDelegate();
this.id = item.getItemId();
this.recipeType = recipeType;
this.recipe = recipe;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import lombok.experimental.Delegate;
import org.apache.commons.lang.Validate;
import org.bukkit.ChatColor;
import org.bukkit.Color;
Expand Down Expand Up @@ -41,7 +42,10 @@
* @author Walshy
*
*/
public class SlimefunItemStack extends ItemStack {
public class SlimefunItemStack {

@Delegate
private ItemStack delegate;

private String id;
private ItemMetaSnapshot itemMetaSnapshot;
Expand All @@ -50,7 +54,7 @@ public class SlimefunItemStack extends ItemStack {
private String texture = null;

public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item) {
super(item);
delegate = new ItemStack(item);

Validate.notNull(id, "The Item id must never be null!");
Validate.isTrue(id.equals(id.toUpperCase(Locale.ROOT)), "Slimefun Item Ids must be uppercase! (e.g. 'MY_ITEM_ID')");
Expand All @@ -61,7 +65,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item) {

this.id = id;

ItemMeta meta = getItemMeta();
ItemMeta meta = delegate.getItemMeta();

Slimefun.getItemDataService().setItemData(meta, id);
Slimefun.getItemTextureService().setTexture(meta, id);
Expand All @@ -72,7 +76,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item) {
public SlimefunItemStack(@Nonnull String id, @Nonnull ItemStack item, @Nonnull Consumer<ItemMeta> consumer) {
this(id, item);

ItemMeta im = getItemMeta();
ItemMeta im = delegate.getItemMeta();
consumer.accept(im);
setItemMeta(im);
}
Expand Down Expand Up @@ -166,7 +170,7 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull Color color, @Nonnull Poti
}

public SlimefunItemStack(@Nonnull SlimefunItemStack item, int amount) {
this(item.getItemId(), item);
this(item.getItemId(), item.getDelegate());
setAmount(amount);
}

Expand Down Expand Up @@ -239,24 +243,21 @@ public SlimefunItemStack(@Nonnull String id, @Nonnull String texture, @Nonnull C
return itemMetaSnapshot;
}

@Override
public boolean setItemMeta(ItemMeta meta) {
validate();
itemMetaSnapshot = new ItemMetaSnapshot(meta);

return super.setItemMeta(meta);
return delegate.setItemMeta(meta);
}

@Override
public void setType(Material type) {
validate();
super.setType(type);
delegate.setType(type);
}

@Override
public void setAmount(int amount) {
validate();
super.setAmount(amount);
delegate.setAmount(amount);
}

private void validate() {
Expand Down Expand Up @@ -306,13 +307,13 @@ public void lock() {
}

@Override
public ItemStack clone() {
return new SlimefunItemStack(id, super.clone());
public SlimefunItemStack clone() {
return new SlimefunItemStack(id, delegate.clone());
}

@Override
public String toString() {
return "SlimefunItemStack (" + id + (getAmount() > 1 ? (" x " + getAmount()) : "") + ')';
return "SlimefunItemStack (" + id + (delegate.getAmount() > 1 ? (" x " + delegate.getAmount()) : "") + ')';
}

/**
Expand All @@ -332,4 +333,8 @@ public final int hashCode() {
// We don't want people to override this, it should use the super method
return super.hashCode();
}

public ItemStack getDelegate() {
return delegate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class RecipeType implements Keyed {
public static final RecipeType ENHANCED_CRAFTING_TABLE = new RecipeType(new NamespacedKey(Slimefun.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(Slimefun.instance(), "juicer"), SlimefunItems.JUICER, "", "&a&oUsed for Juice Creation");

public static final RecipeType ANCIENT_ALTAR = new RecipeType(new NamespacedKey(Slimefun.instance(), "ancient_altar"), SlimefunItems.ANCIENT_ALTAR, (recipe, output) -> {
public static final RecipeType ANCIENT_ALTAR = new RecipeType(new NamespacedKey(Slimefun.instance(), "ancient_altar"), SlimefunItems.ANCIENT_ALTAR.getDelegate(), (recipe, output) -> {
AltarRecipe altarRecipe = new AltarRecipe(Arrays.asList(recipe), output);
AncientAltar altar = ((AncientAltar) SlimefunItems.ANCIENT_ALTAR.getItem());
altar.getRecipes().add(altarRecipe);
Expand Down Expand Up @@ -91,7 +91,7 @@ public RecipeType(ItemStack item, String machine) {
}

public RecipeType(NamespacedKey key, SlimefunItemStack slimefunItem, String... lore) {
this(key, slimefunItem, null, lore);
this(key, slimefunItem.getDelegate(), null, lore);
}

public RecipeType(NamespacedKey key, ItemStack item, BiConsumer<ItemStack[], ItemStack> callback, String... lore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void onExecute(CommandSender sender, String[] args) {
}

Slimefun.runSync(() -> {
ItemStack item = SlimefunItems.RESTORED_BACKPACK.clone();
ItemStack item = SlimefunItems.RESTORED_BACKPACK.clone().getDelegate();
Slimefun.getBackpackListener().setBackpackId(backpackOwner, item, 2, id);
player.getInventory().addItem(item);
Slimefun.getLocalization().sendMessage(sender, "commands.backpack.restored-backpack-given");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DebugFishCommand extends SubCommand {
@Override
public void onExecute(CommandSender sender, String[] args) {
if (sender instanceof Player player && sender.hasPermission("slimefun.debugging")) {
player.getInventory().addItem(SlimefunItems.DEBUG_FISH.clone());
player.getInventory().addItem(SlimefunItems.DEBUG_FISH.clone().getDelegate());
} else {
Slimefun.getLocalization().sendMessage(sender, "messages.no-permission", true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected void registerDefaultFuelTypes() {
registerFuel(new MachineFuel(4, new ItemStack(Material.SHROOMLIGHT)));
registerFuel(new MachineFuel(2, new ItemStack(Material.CRIMSON_FUNGUS)));
registerFuel(new MachineFuel(2, new ItemStack(Material.WARPED_FUNGUS)));
registerFuel(new MachineFuel(16, SlimefunItems.STRANGE_NETHER_GOO));
registerFuel(new MachineFuel(16, SlimefunItems.STRANGE_NETHER_GOO.getDelegate()));

if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
registerFuel(new MachineFuel(2, new ItemStack(Material.GLOW_BERRIES)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public CombustionGenerator(ItemGroup itemGroup, SlimefunItemStack item, RecipeTy

@Override
protected void registerDefaultFuelTypes() {
registerFuel(new MachineFuel(30, SlimefunItems.OIL_BUCKET));
registerFuel(new MachineFuel(90, SlimefunItems.FUEL_BUCKET));
registerFuel(new MachineFuel(30, SlimefunItems.OIL_BUCKET.getDelegate()));
registerFuel(new MachineFuel(90, SlimefunItems.FUEL_BUCKET.getDelegate()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {
ItemStack item = menu.getItemInSlot(slot);

if (item != null && item.getType().getMaxDurability() > 0 && ((Damageable) item.getItemMeta()).getDamage() > 0) {
if (SlimefunUtils.isItemSimilar(ductTape, SlimefunItems.DUCT_TAPE, true, false)) {
if (SlimefunUtils.isItemSimilar(ductTape, SlimefunItems.DUCT_TAPE.getDelegate(), true, false)) {
ItemStack repairedItem = repair(item);

if (!menu.fits(repairedItem, getOutputSlots())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,25 +62,25 @@ protected void registerDefaultRecipes() {
recipeList.add(new ItemStack(Material.BUCKET));

recipeList.add(new ItemStack(Material.COOKED_BEEF));
recipeList.add(SlimefunItems.BEEF_JERKY);
recipeList.add(SlimefunItems.BEEF_JERKY.getDelegate());

recipeList.add(new ItemStack(Material.COOKED_PORKCHOP));
recipeList.add(SlimefunItems.PORK_JERKY);
recipeList.add(SlimefunItems.PORK_JERKY.getDelegate());

recipeList.add(new ItemStack(Material.COOKED_CHICKEN));
recipeList.add(SlimefunItems.CHICKEN_JERKY);
recipeList.add(SlimefunItems.CHICKEN_JERKY.getDelegate());

recipeList.add(new ItemStack(Material.COOKED_MUTTON));
recipeList.add(SlimefunItems.MUTTON_JERKY);
recipeList.add(SlimefunItems.MUTTON_JERKY.getDelegate());

recipeList.add(new ItemStack(Material.COOKED_RABBIT));
recipeList.add(SlimefunItems.RABBIT_JERKY);
recipeList.add(SlimefunItems.RABBIT_JERKY.getDelegate());

recipeList.add(new ItemStack(Material.COOKED_COD));
recipeList.add(SlimefunItems.FISH_JERKY);
recipeList.add(SlimefunItems.FISH_JERKY.getDelegate());

recipeList.add(new ItemStack(Material.COOKED_SALMON));
recipeList.add(SlimefunItems.FISH_JERKY);
recipeList.add(SlimefunItems.FISH_JERKY.getDelegate());

if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) {
recipeList.add(new ItemStack(Material.MUD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ public CarbonPress(ItemGroup itemGroup, SlimefunItemStack item, RecipeType recip
@Override
protected void registerDefaultRecipes() {
registerRecipe(15, new ItemStack[] { new ItemStack(Material.CHARCOAL, 4) }, new ItemStack[] { new ItemStack(Material.COAL) });
registerRecipe(20, new ItemStack[] { new ItemStack(Material.COAL, 8) }, new ItemStack[] { SlimefunItems.CARBON });
registerRecipe(180, new ItemStack[] { new ItemStack(Material.COAL_BLOCK, 8) }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.CARBON, 9) });
registerRecipe(30, new ItemStack[] { new CustomItemStack(SlimefunItems.CARBON, 4) }, new ItemStack[] { SlimefunItems.COMPRESSED_CARBON });
registerRecipe(60, new ItemStack[] { SlimefunItems.CARBON_CHUNK, SlimefunItems.SYNTHETIC_DIAMOND }, new ItemStack[] { SlimefunItems.RAW_CARBONADO });
registerRecipe(60, new ItemStack[] { SlimefunItems.CARBON_CHUNK }, new ItemStack[] { SlimefunItems.SYNTHETIC_DIAMOND });
registerRecipe(90, new ItemStack[] { SlimefunItems.RAW_CARBONADO }, new ItemStack[] { SlimefunItems.CARBONADO });
registerRecipe(20, new ItemStack[] { new ItemStack(Material.COAL, 8) }, new ItemStack[] { SlimefunItems.CARBON.getDelegate() });
registerRecipe(180, new ItemStack[] { new ItemStack(Material.COAL_BLOCK, 8) }, new ItemStack[] { new SlimefunItemStack(SlimefunItems.CARBON, 9).getDelegate() });
registerRecipe(30, new ItemStack[] { new CustomItemStack(SlimefunItems.CARBON.getDelegate(), 4) }, new ItemStack[] { SlimefunItems.COMPRESSED_CARBON.getDelegate() });
registerRecipe(60, new ItemStack[] { SlimefunItems.CARBON_CHUNK.getDelegate(), SlimefunItems.SYNTHETIC_DIAMOND.getDelegate() }, new ItemStack[] { SlimefunItems.RAW_CARBONADO.getDelegate() });
registerRecipe(60, new ItemStack[] { SlimefunItems.CARBON_CHUNK.getDelegate() }, new ItemStack[] { SlimefunItems.SYNTHETIC_DIAMOND.getDelegate() });
registerRecipe(90, new ItemStack[] { SlimefunItems.RAW_CARBONADO.getDelegate() }, new ItemStack[] { SlimefunItems.CARBONADO.getDelegate() });
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,21 @@ protected MachineRecipe findNextRecipe(BlockMenu menu) {
for (int slot : getInputSlots()) {
ItemStack input = menu.getItemInSlot(slot);
MachineRecipe recipe = null;
if (SlimefunUtils.isItemSimilar(input, SlimefunItems.SIFTED_ORE, true, false)) {
if (SlimefunUtils.isItemSimilar(input, SlimefunItems.SIFTED_ORE.getDelegate(), true, false)) {
if (!legacyMode && !hasFreeSlot(menu)) {
return null;
}

recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { SlimefunItems.SIFTED_ORE }, new ItemStack[] { oreWasher.getRandomDust() });
recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { SlimefunItems.SIFTED_ORE.getDelegate() }, new ItemStack[] { oreWasher.getRandomDust() });

if (!legacyMode || menu.fits(recipe.getOutput()[0], getOutputSlots())) {
menu.consumeItem(slot);
return recipe;
}
} else if (SlimefunUtils.isItemSimilar(input, SlimefunItems.PULVERIZED_ORE, true)) {
recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { SlimefunItems.PULVERIZED_ORE }, new ItemStack[] { SlimefunItems.PURE_ORE_CLUSTER });
} else if (SlimefunUtils.isItemSimilar(input, SlimefunItems.PULVERIZED_ORE.getDelegate(), true)) {
recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { SlimefunItems.PULVERIZED_ORE.getDelegate() }, new ItemStack[] { SlimefunItems.PURE_ORE_CLUSTER.getDelegate() });
} else if (SlimefunUtils.isItemSimilar(input, new ItemStack(Material.SAND), true)) {
recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { new ItemStack(Material.SAND) }, new ItemStack[] { SlimefunItems.SALT });
recipe = new MachineRecipe(4 / getSpeed(), new ItemStack[] { new ItemStack(Material.SAND) }, new ItemStack[] { SlimefunItems.SALT.getDelegate() });
}

if (recipe != null && menu.fits(recipe.getOutput()[0], getOutputSlots())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ public List<ItemStack> getDisplayRecipes() {
protected void registerDefaultRecipes() {
// this is an extra recipe on top of PostSetup.loadSmelteryRecipes() for converting
// Vanilla Gold Ingot to Slimefun gold dust and Vanilla Copper Ingot into Slimefun copper dust
registerRecipe(3, new ItemStack(Material.GOLD_INGOT), SlimefunItems.GOLD_DUST);
registerRecipe(3, new ItemStack(Material.GOLD_INGOT), SlimefunItems.GOLD_DUST.getDelegate());

if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) {
registerRecipe(3, new ItemStack(Material.COPPER_INGOT), SlimefunItems.COPPER_DUST);
registerRecipe(3, new ItemStack(Material.COPPER_INGOT), SlimefunItems.COPPER_DUST.getDelegate());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ElectricPress(ItemGroup itemGroup, SlimefunItemStack item, RecipeType rec

@Override
protected void registerDefaultRecipes() {
addRecipe(4, new SlimefunItemStack(SlimefunItems.STONE_CHUNK, 3), new ItemStack(Material.COBBLESTONE));
addRecipe(4, new SlimefunItemStack(SlimefunItems.STONE_CHUNK, 3).getDelegate(), 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(4, new ItemStack(Material.SNOWBALL, 4), new ItemStack(Material.SNOW_BLOCK));
Expand All @@ -44,15 +44,15 @@ protected void registerDefaultRecipes() {
addRecipe(3, new ItemStack(Material.CLAY_BALL, 4), new ItemStack(Material.CLAY));
addRecipe(3, new ItemStack(Material.BRICK, 4), new ItemStack(Material.BRICKS));

addRecipe(6, SlimefunItems.COPPER_INGOT, new CustomItemStack(SlimefunItems.COPPER_WIRE, 3));
addRecipe(6, SlimefunItems.COPPER_INGOT.getDelegate(), new CustomItemStack(SlimefunItems.COPPER_WIRE.getDelegate(), 3));
addRecipe(16, new SlimefunItemStack(SlimefunItems.STEEL_INGOT, 8), SlimefunItems.STEEL_PLATE);
addRecipe(18, new SlimefunItemStack(SlimefunItems.REINFORCED_ALLOY_INGOT, 8), SlimefunItems.REINFORCED_PLATE);

addRecipe(8, new ItemStack(Material.NETHER_WART), new CustomItemStack(SlimefunItems.MAGIC_LUMP_1, 2));
addRecipe(8, new ItemStack(Material.NETHER_WART), new CustomItemStack(SlimefunItems.MAGIC_LUMP_1.getDelegate(), 2));
addRecipe(10, new SlimefunItemStack(SlimefunItems.MAGIC_LUMP_1, 4), SlimefunItems.MAGIC_LUMP_2);
addRecipe(12, new SlimefunItemStack(SlimefunItems.MAGIC_LUMP_2, 4), SlimefunItems.MAGIC_LUMP_3);

addRecipe(10, new ItemStack(Material.ENDER_EYE), new CustomItemStack(SlimefunItems.ENDER_LUMP_1, 2));
addRecipe(10, new ItemStack(Material.ENDER_EYE), new CustomItemStack(SlimefunItems.ENDER_LUMP_1.getDelegate(), 2));
addRecipe(12, new SlimefunItemStack(SlimefunItems.ENDER_LUMP_1, 4), SlimefunItems.ENDER_LUMP_2);
addRecipe(14, new SlimefunItemStack(SlimefunItems.ENDER_LUMP_2, 4), SlimefunItems.ENDER_LUMP_3);

Expand Down Expand Up @@ -92,6 +92,11 @@ private void addRecipe(int seconds, ItemStack input, ItemStack output) {
registerRecipe(seconds, new ItemStack[] { input }, new ItemStack[] { output });
}

@ParametersAreNonnullByDefault
private void addRecipe(int seconds, SlimefunItemStack sfi1, SlimefunItemStack sfi2) {
registerRecipe(seconds, sfi1.getDelegate(), sfi2.getDelegate());
}

@Override
public ItemStack getProgressBar() {
return new ItemStack(Material.IRON_HOE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ private void produceFlasks(@Nonnull Location location, int experiencePoints) {
for (int level = 0; level < getStoredExperience(location); level = level + 10) {
if (menu.fits(SlimefunItems.FILLED_FLASK_OF_KNOWLEDGE, getOutputSlots())) {
withdrawn = withdrawn + 10;
menu.pushItem(SlimefunItems.FILLED_FLASK_OF_KNOWLEDGE.clone(), getOutputSlots());
menu.pushItem(SlimefunItems.FILLED_FLASK_OF_KNOWLEDGE.getDelegate(), getOutputSlots());
} else {
// There is no room for more bottles, so lets stop checking if more will fit.
break;
Expand Down
Loading

0 comments on commit a62ecff

Please sign in to comment.