Skip to content

Commit

Permalink
✨ feat(Tesseract Binder): Added a binding tool for Tesseracts instead…
Browse files Browse the repository at this point in the history
… of binding directly
  • Loading branch information
ProfElements committed Apr 9, 2021
1 parent fdfec4d commit 2d2d05b
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 56 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Most of these could possibly be overpowered or heavily underpowered.
- **Angel Gem** - Permanent Creative Flight, it has some speed settings.
- **Scoop** - The only way to get naturals Bees. Scoop them into item form.
- **Dimensional Home** - Gives you a small home in another dimension to teleport to and from. (it sends to you back to your bed spawn if you are in the dimension.)
- **Tesseract Binder** - Binds Tesseract in a better manner then binding themselves via direct linking

## Bees
- **Bee** - A Natural Bee, for each one -2 seconds to resource creation time in Material Hive.
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/me/profelements/dynatech/DynaTechItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,17 @@ private DynaTechItems() {}
"&f&oPowerup!"
);

public static final SlimefunItemStack TESSERACT_BINDER = new SlimefunItemStack("TESSERACT_BINDER",
Material.NETHERITE_HOE,
"&6Tesseract Binder",
"",
"&f Used to bind 2 Tesseract together.",
"",
"&fRight click to get Location of Tesseract",
"&fCrouch Right Click to bind location to Tesseract",
""
);

//Machines
public static final SlimefunItemStack AUTO_KITCHEN = new SlimefunItemStack("AUTO_KITCHEN",
Material.SMOKER,
Expand Down Expand Up @@ -398,11 +409,9 @@ private DynaTechItems() {}
);

public static final SlimefunItemStack TESSERACT = new SlimefunItemStack("TESSERACT",
Material.RESPAWN_ANCHOR,
Material.PURPUR_BLOCK,
"&6Tesseract",
"",
"&4&oCURRENTLY EXPERMENTAL. Very weird to setup",
"",
"&fTransfers Items and Energy Wirelessly",
"&fThese are even 2-way!",
"Right Click on another Tesseract to connect!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import io.github.thebusybiscuit.slimefun4.api.events.PlayerRightClickEvent;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetComponent;
import io.github.thebusybiscuit.slimefun4.core.attributes.EnergyNetProvider;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
Expand Down Expand Up @@ -48,7 +47,7 @@
import net.md_5.bungee.api.ChatColor;

public class Tesseract extends SlimefunItem implements EnergyNetComponent {
protected static final NamespacedKey WIRELESS_LOCATION_KEY = new NamespacedKey(DynaTech.getInstance(), "tesseract-pair-location");
public static final NamespacedKey WIRELESS_LOCATION_KEY = new NamespacedKey(DynaTech.getInstance(), "tesseract-pair-location");
private final int capacity;
private final int energyRate;

Expand All @@ -58,7 +57,7 @@ public Tesseract(Category category, int capacity, int energyRate, SlimefunItemSt
this.capacity = capacity;
this.energyRate = energyRate;

addItemHandler(onBlockBreak(), onBlockPlace(), onRightClick());
addItemHandler(onBlockBreak());

new BlockMenuPreset("TESSERACT", "Tesseract") {

Expand Down Expand Up @@ -109,53 +108,6 @@ public void tick(Block block, SlimefunItem sfItem, Config data) {
});
}

private ItemHandler onRightClick() {
return new ItemUseHandler() {

@Override
public void onRightClick(PlayerRightClickEvent event) {

Optional<Block> blockClicked = event.getClickedBlock();
Optional<SlimefunItem> sfBlockClicked = event.getSlimefunBlock();
if (blockClicked.isPresent() && sfBlockClicked.isPresent()) {
Location blockLoc = blockClicked.get().getLocation();
SlimefunItem sfBlock = sfBlockClicked.get();
ItemStack item = event.getItem();


if (sfBlock != null && sfBlock.getId().equals(DynaTechItems.TESSERACT.getItemId()) && blockLoc != null) {
event.cancel();
ItemMeta im = item.getItemMeta();
String locationString = LocationToString(blockLoc);

PersistentDataAPI.setString(im, WIRELESS_LOCATION_KEY, locationString);
item.setItemMeta(im);
setItemLore(item, blockLoc);
}
}
}
};
}

private ItemHandler onBlockPlace() {
return new BlockPlaceHandler(false) {
@Override
public void onPlayerPlace(BlockPlaceEvent event) {


Location blockLoc = event.getBlockPlaced().getLocation();
ItemStack item = event.getItemInHand();
String locationString = PersistentDataAPI.getString(item.getItemMeta(), WIRELESS_LOCATION_KEY);

if (item != null && item.getType() == DynaTechItems.TESSERACT.getType() && item.hasItemMeta() && locationString != null) {
BlockStorage.addBlockInfo(blockLoc, "tesseract-pair-location", locationString);

}
}

};
}

private ItemHandler onBlockBreak() {
return new BlockBreakHandler(false, false) {

Expand Down Expand Up @@ -271,7 +223,7 @@ public int getEnergyRate() {
return energyRate;
}

private void setItemLore(ItemStack item, Location l) {
public static void setItemLore(ItemStack item, Location l) {
ItemMeta im = item.getItemMeta();
List<String> lore = im.getLore();
for (int i = 0; i < lore.size(); i++) {
Expand All @@ -287,11 +239,11 @@ private void setItemLore(ItemStack item, Location l) {

}

private String LocationToString(Location l) {
public static String LocationToString(Location l) {
return l.getWorld().getName()+";"+l.getBlockX()+";"+l.getBlockY()+";"+l.getBlockZ();
}

private static final Location StringToLocation(String locString) {
public static final Location StringToLocation(String locString) {
String[] locComponents = locString.split(";");
return new Location(Bukkit.getWorld(locComponents[0]), Double.parseDouble(locComponents[1]), Double.parseDouble(locComponents[2]), Double.parseDouble(locComponents[3]));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package me.profelements.dynatech.items.tools;

import java.util.Optional;

import org.bukkit.Location;
import org.bukkit.block.Block;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;

import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.Category;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;
import me.mrCookieSlime.Slimefun.cscorelib2.data.PersistentDataAPI;
import me.profelements.dynatech.DynaTechItems;
import me.profelements.dynatech.items.electric.transfer.Tesseract;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;

public class TesseractBinder extends SlimefunItem {
public TesseractBinder(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
super(category, item, recipeType, recipe);

addItemHandler(bindTesseract());
}

private ItemUseHandler bindTesseract() {
return e -> {
e.cancel();

Optional<Block> block = e.getClickedBlock();
Optional<SlimefunItem> sfBlock = e.getSlimefunBlock();
if (block.isPresent() && sfBlock.isPresent()) {
Location blockLocation = block.get().getLocation();
SlimefunItem sfItem = sfBlock.get();
ItemStack item = e.getItem();

if (e.getPlayer().isSneaking()) {
String locString = PersistentDataAPI.getString(item.getItemMeta(), Tesseract.WIRELESS_LOCATION_KEY);
if (item != null && BlockStorage.checkID(blockLocation).equals(DynaTechItems.TESSERACT.getItemId()) && item.hasItemMeta() && locString != null) {
BlockStorage.addBlockInfo(blockLocation, "tesseract-pair-location", locString);
e.getPlayer().spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(ChatColor.WHITE + "Tesseract Connected!"));
}
} else if (sfBlock != null && sfItem.getId().equals(DynaTechItems.TESSERACT.getItemId()) && blockLocation != null) {
ItemMeta im = item.getItemMeta();
String locString = Tesseract.LocationToString(blockLocation);

PersistentDataAPI.setString(im, Tesseract.WIRELESS_LOCATION_KEY, locString);
item.setItemMeta(im);
Tesseract.setItemLore(item, blockLocation);
}

}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import me.profelements.dynatech.items.tools.InventoryFilter;
import me.profelements.dynatech.items.tools.Orechid;
import me.profelements.dynatech.items.tools.Scoop;
import me.profelements.dynatech.items.tools.TesseractBinder;

import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
Expand Down Expand Up @@ -222,6 +223,14 @@ SlimefunItems.COBALT_PICKAXE, new ItemStack(Material.NETHER_STAR), SlimefunItems
}, new PotionEffect[] {new PotionEffect(PotionEffectType.FAST_DIGGING, 20*15, 1, true) }
).register(plugin);

new TesseractBinder(DynaTechItems.DynaTechGeneral, DynaTechItems.TESSERACT_BINDER, RecipeType.MAGIC_WORKBENCH,
new ItemStack[] {
null, DynaTechItems.TESSERACTING_OBJ, null,
null, DynaTechItems.STAINLESS_STEEL, null,
null, DynaTechItems.STAINLESS_STEEL, null,
}
).register(plugin);

if (DynaTech.isInfinityExpansionInstalled()) {
new MobDataCard("Vex", MobDataTier.HOSTILE, new ItemStack[] {
new SlimefunItemStack(DynaTechItems.VEX_GEM, 16), new SlimefunItemStack(DynaTechItems.GHOSTLY_ESSENCE, 16), new SlimefunItemStack(DynaTechItems.VEX_GEM, 16),
Expand Down

0 comments on commit 2d2d05b

Please sign in to comment.