Skip to content

Commit

Permalink
Update code for Slimefun vDEV 586+
Browse files Browse the repository at this point in the history
If it still doesn't work, consider turn on backward compatiblity.
  • Loading branch information
nahkd authored and nahkd committed Jul 22, 2020
1 parent 35113fa commit 7c94a87
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 116 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.nahkd.spigot.sfaddons</groupId>
<artifactId>Endrex</artifactId>
<version>1.0.1-b2</version>
<version>1.0.3-b1</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,46 +1,46 @@
package me.nahkd.spigot.sfaddons.endrex.handlers;

import java.util.List;
import java.util.Optional;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import me.mrCookieSlime.Slimefun.SlimefunPlugin;
import me.nahkd.spigot.sfaddons.endrex.items.mysterious.MysteriousEquipment;
import me.nahkd.spigot.sfaddons.endrex.utils.InventoryUtils;

public class InventoryEventsHandlers implements Listener {

@EventHandler
public void click(InventoryClickEvent event) {
if (event.getClickedInventory() != event.getInventory()) return;
switch (event.getView().getTitle()) {
case "Slimefun Guide": return;
}

ItemStack itemStack = event.getCurrentItem();
if (!InventoryUtils.isNotAir(itemStack)) return;
ItemMeta meta = itemStack.getItemMeta();
Optional<String> id = SlimefunPlugin.getItemDataService().getItemData(meta);
if (id.isPresent() && MysteriousEquipment.getMappedItems().containsKey(id.get())) {
MysteriousEquipment equipment = MysteriousEquipment.getMappedItems().get(id.get());
if (meta.getLore().get(0).equals("§7Click to unlock")) {
// Add crap to the item
List<String> lore = meta.getLore();
lore.set(0, "§7§oMagically created");
meta.setLore(lore);

equipment.applyEnchantment(meta);

itemStack.setItemMeta(meta);
event.setCurrentItem(new ItemStack(itemStack));
event.setCancelled(true);
}
}
}

}
package me.nahkd.spigot.sfaddons.endrex.handlers;

import java.util.List;
import java.util.Optional;

import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryClickEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import me.nahkd.spigot.sfaddons.endrex.items.mysterious.MysteriousEquipment;
import me.nahkd.spigot.sfaddons.endrex.utils.InventoryUtils;

public class InventoryEventsHandlers implements Listener {

@EventHandler
public void click(InventoryClickEvent event) {
if (event.getClickedInventory() != event.getInventory()) return;
switch (event.getView().getTitle()) {
case "Slimefun Guide": return;
}

ItemStack itemStack = event.getCurrentItem();
if (!InventoryUtils.isNotAir(itemStack)) return;
ItemMeta meta = itemStack.getItemMeta();
Optional<String> id = SlimefunPlugin.getItemDataService().getItemData(meta);
if (id.isPresent() && MysteriousEquipment.getMappedItems().containsKey(id.get())) {
MysteriousEquipment equipment = MysteriousEquipment.getMappedItems().get(id.get());
if (meta.getLore().get(0).equals("§7Click to unlock")) {
// Add crap to the item
List<String> lore = meta.getLore();
lore.set(0, "§7§oMagically created");
meta.setLore(lore);

equipment.applyEnchantment(meta);

itemStack.setItemMeta(meta);
event.setCurrentItem(new ItemStack(itemStack));
event.setCancelled(true);
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

public class EndrexResourceItem extends EndrexItem {

private final SlimefunItemStack item;
// private final SlimefunItemStack item;
private boolean applyRecipe;
private RecipeDisplayItem machine;
private ItemStack recipeOutput;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,68 +1,68 @@
package me.nahkd.spigot.sfaddons.endrex.structures;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import org.bukkit.inventory.ItemStack;

import me.mrCookieSlime.Slimefun.Lists.SlimefunItems;
import me.mrCookieSlime.Slimefun.cscorelib2.item.CustomItem;
import me.nahkd.spigot.sfaddons.endrex.Endrex;
import me.nahkd.spigot.sfaddons.endrex.items.EndrexItems;
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.VectorInt;
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.Schematic;
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.loot.LootTableEntry;

public class MysteryBoxesGenerator extends StructuresGenerator {

Schematic schem;
List<LootTableEntry> lootTable;

public MysteryBoxesGenerator() {
schem = Endrex.getSchematic("structures/other/mysterybox.nsm");
lootTable = Arrays.asList(
new LootTableEntry(0.02, new ItemStack(Material.ENDER_PEARL, 3)),
new LootTableEntry(0.03, new ItemStack(Material.ENDER_PEARL, 2)),
new LootTableEntry(0.03, new ItemStack(Material.ENDER_PEARL, 1)),

new LootTableEntry(0.02, new ItemStack(Material.EXPERIENCE_BOTTLE, 6)),
new LootTableEntry(0.02, new ItemStack(Material.EXPERIENCE_BOTTLE, 3)),
new LootTableEntry(0.03, new ItemStack(Material.EXPERIENCE_BOTTLE, 2)),

new LootTableEntry(0.02, new CustomItem(EndrexItems.ENDERIUM.getItem(), 1)),
new LootTableEntry(0.01, new CustomItem(EndrexItems.ENDERIUM.getItem(), 2)),

new LootTableEntry(0.04, new ItemStack(Material.DIAMOND, 1)),
new LootTableEntry(0.03, new ItemStack(Material.DIAMOND, 2)),
new LootTableEntry(0.01, EndrexItems.ENDERIUM_SWORD.getItem()),
new LootTableEntry(0.02, EndrexItems.MASK_OF_ENDER.getItem()),
new LootTableEntry(0.02, SlimefunItems.RUNE_AIR),
new LootTableEntry(0.03, SlimefunItems.RUNE_ENDER),
new LootTableEntry(0.02, SlimefunItems.GOLD_16K),
new LootTableEntry(0.01, SlimefunItems.BLANK_RUNE)
);
}

@Override
public void generateStructure(World world, Chunk newChunk, Random rand) {
if (world.getEnvironment() != Environment.THE_END) return;
if (newChunk.getX() >= -32 && newChunk.getZ() >= -32 && newChunk.getX() <= 32 && newChunk.getZ() <= 32) return;
int mx = rand.nextInt(13);
for (int i = 0; i < mx; i++) rand.nextInt();
double hit = rand.nextDouble();
if (hit <= 0.03) {
int genX = rand.nextInt(9) + (newChunk.getX() * 16),
genZ = rand.nextInt(9) + (newChunk.getZ() * 16),
y = 100 + rand.nextInt(32);
if (world.getBlockAt(genX, y, genZ).getBiome() == Biome.SMALL_END_ISLANDS) return;
schem.pasteSchematic(world, new VectorInt(genX, y, genZ), lootTable);
}
}

}
package me.nahkd.spigot.sfaddons.endrex.structures;

import java.util.Arrays;
import java.util.List;
import java.util.Random;

import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.World.Environment;
import org.bukkit.block.Biome;
import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import me.mrCookieSlime.Slimefun.cscorelib2.item.CustomItem;
import me.nahkd.spigot.sfaddons.endrex.Endrex;
import me.nahkd.spigot.sfaddons.endrex.items.EndrexItems;
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.VectorInt;
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.Schematic;
import me.nahkd.spigot.sfaddons.endrex.nahkdschem2.loot.LootTableEntry;

public class MysteryBoxesGenerator extends StructuresGenerator {

Schematic schem;
List<LootTableEntry> lootTable;

public MysteryBoxesGenerator() {
schem = Endrex.getSchematic("structures/other/mysterybox.nsm");
lootTable = Arrays.asList(
new LootTableEntry(0.02, new ItemStack(Material.ENDER_PEARL, 3)),
new LootTableEntry(0.03, new ItemStack(Material.ENDER_PEARL, 2)),
new LootTableEntry(0.03, new ItemStack(Material.ENDER_PEARL, 1)),

new LootTableEntry(0.02, new ItemStack(Material.EXPERIENCE_BOTTLE, 6)),
new LootTableEntry(0.02, new ItemStack(Material.EXPERIENCE_BOTTLE, 3)),
new LootTableEntry(0.03, new ItemStack(Material.EXPERIENCE_BOTTLE, 2)),

new LootTableEntry(0.02, new CustomItem(EndrexItems.ENDERIUM.getItem(), 1)),
new LootTableEntry(0.01, new CustomItem(EndrexItems.ENDERIUM.getItem(), 2)),

new LootTableEntry(0.04, new ItemStack(Material.DIAMOND, 1)),
new LootTableEntry(0.03, new ItemStack(Material.DIAMOND, 2)),
new LootTableEntry(0.01, EndrexItems.ENDERIUM_SWORD.getItem()),
new LootTableEntry(0.02, EndrexItems.MASK_OF_ENDER.getItem()),
new LootTableEntry(0.02, SlimefunItems.AIR_RUNE),
new LootTableEntry(0.03, SlimefunItems.ENDER_RUNE),
new LootTableEntry(0.02, SlimefunItems.GOLD_16K),
new LootTableEntry(0.01, SlimefunItems.BLANK_RUNE)
);
}

@Override
public void generateStructure(World world, Chunk newChunk, Random rand) {
if (world.getEnvironment() != Environment.THE_END) return;
if (newChunk.getX() >= -32 && newChunk.getZ() >= -32 && newChunk.getX() <= 32 && newChunk.getZ() <= 32) return;
int mx = rand.nextInt(13);
for (int i = 0; i < mx; i++) rand.nextInt();
double hit = rand.nextDouble();
if (hit <= 0.03) {
int genX = rand.nextInt(9) + (newChunk.getX() * 16),
genZ = rand.nextInt(9) + (newChunk.getZ() * 16),
y = 100 + rand.nextInt(32);
if (world.getBlockAt(genX, y, genZ).getBiome() == Biome.SMALL_END_ISLANDS) return;
schem.pasteSchematic(world, new VectorInt(genX, y, genZ), lootTable);
}
}

}

0 comments on commit 7c94a87

Please sign in to comment.