Skip to content
This repository has been archived by the owner on Jan 22, 2021. It is now read-only.

Glass cutter #48

Merged
merged 14 commits into from
Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/main/java/dev/j3fftw/litexpansion/GlowEnchant.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ public boolean canEnchantItem(ItemStack item) {
final ItemMeta itemMeta = item.getItemMeta();
final Optional<String> id = SlimefunPlugin.getItemDataService().getItemData(itemMeta);
if (id.isPresent()) {
return id.get().equals(Items.ADVANCED_CIRCUIT.getItemId())
|| id.get().equals(Items.NANO_BLADE.getItemId());
return (id.get().equals(Items.ADVANCED_CIRCUIT.getItemId()))
|| (id.get().equals(Items.NANO_BLADE.getItemId()))
|| (id.get().equals(Items.GLASS_CUTTER.getItemId()));
NCBPFluffyBear marked this conversation as resolved.
Show resolved Hide resolved
}
}
return false;
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/dev/j3fftw/litexpansion/ItemSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.j3fftw.litexpansion.items.CargoConfigurator;
import dev.j3fftw.litexpansion.items.FoodSynthesizer;
import dev.j3fftw.litexpansion.items.GlassCutter;
import dev.j3fftw.litexpansion.items.MagThor;
import dev.j3fftw.litexpansion.items.Thorium;
import dev.j3fftw.litexpansion.machine.AdvancedSolarPanel;
Expand All @@ -10,6 +11,7 @@
import dev.j3fftw.litexpansion.machine.RubberSynthesizer;
import dev.j3fftw.litexpansion.machine.ScrapMachine;
import dev.j3fftw.litexpansion.weapons.NanoBlade;
import io.github.thebusybiscuit.slimefun4.api.SlimefunAddon;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.items.blocks.UnplaceableBlock;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
Expand All @@ -27,6 +29,7 @@ final class ItemSetup {
protected static final ItemSetup INSTANCE = new ItemSetup();
private final ItemStack glass = new ItemStack(Material.GLASS);
private boolean initialised;
private final SlimefunAddon plugin = LiteXpansion.getInstance();

private ItemSetup() {}

Expand All @@ -45,7 +48,8 @@ public void init() {
}

private void registerTools() {
new CargoConfigurator().register(LiteXpansion.getInstance());
new CargoConfigurator().register(plugin);
new GlassCutter().register(plugin);
}

private void registerMachines() {
Expand Down Expand Up @@ -128,8 +132,8 @@ private void registerMiscItems() {
registerRecipe(Items.REFINED_IRON, Items.MACHINE_BLOCK);

// Resources
new MagThor().register(LiteXpansion.getInstance());
new Thorium().register(LiteXpansion.getInstance());
new MagThor().register(plugin);
new Thorium().register(plugin);
}

private void registerEndgameItems() {
Expand All @@ -147,7 +151,7 @@ Items.ADVANCED_ALLOY, new ItemStack(Material.DIAMOND), Items.ADVANCED_ALLOY,
Items.IRIDIUM, Items.ADVANCED_ALLOY, Items.IRIDIUM
);

new NanoBlade().register(LiteXpansion.getInstance());
new NanoBlade().register(plugin);
}

private void registerCarbonStuff() {
Expand All @@ -165,9 +169,9 @@ private void registerCarbonStuff() {
}

private void registerSolarPanels() {
new AdvancedSolarPanel(AdvancedSolarPanel.Type.ADVANCED).register(LiteXpansion.getInstance());
new AdvancedSolarPanel(AdvancedSolarPanel.Type.HYBRID).register(LiteXpansion.getInstance());
new AdvancedSolarPanel(AdvancedSolarPanel.Type.ULTIMATE).register(LiteXpansion.getInstance());
new AdvancedSolarPanel(AdvancedSolarPanel.Type.ADVANCED).register(plugin);
new AdvancedSolarPanel(AdvancedSolarPanel.Type.HYBRID).register(plugin);
new AdvancedSolarPanel(AdvancedSolarPanel.Type.ULTIMATE).register(plugin);
}

//Register Items
Expand All @@ -180,7 +184,7 @@ private void registerItem(@Nonnull SlimefunItemStack result, @Nonnull RecipeType
null, items[0], null,
null, null, null
};
new SlimefunItem(Items.LITEXPANSION, result, type, recipe).register(LiteXpansion.getInstance());
new SlimefunItem(Items.LITEXPANSION, result, type, recipe).register(plugin);

// make shapeless
for (int i = 0; i < 9; i++) {
Expand All @@ -199,7 +203,7 @@ private void registerItem(@Nonnull SlimefunItemStack result, @Nonnull RecipeType
} else
recipe = items;

new SlimefunItem(Items.LITEXPANSION, result, type, recipe).register(LiteXpansion.getInstance());
new SlimefunItem(Items.LITEXPANSION, result, type, recipe).register(plugin);
}

private void registerNonPlaceableItem(@Nonnull SlimefunItemStack result, @Nonnull RecipeType type,
Expand All @@ -211,7 +215,7 @@ private void registerNonPlaceableItem(@Nonnull SlimefunItemStack result, @Nonnul
null, items[0], null,
null, null, null
};
new UnplaceableBlock(Items.LITEXPANSION, result, type, recipe).register(LiteXpansion.getInstance());
new UnplaceableBlock(Items.LITEXPANSION, result, type, recipe).register(plugin);

// make shapeless
for (int i = 0; i < 9; i++) {
Expand All @@ -230,7 +234,7 @@ private void registerNonPlaceableItem(@Nonnull SlimefunItemStack result, @Nonnul
} else
recipe = items;

new UnplaceableBlock(Items.LITEXPANSION, result, type, recipe).register(LiteXpansion.getInstance());
new UnplaceableBlock(Items.LITEXPANSION, result, type, recipe).register(plugin);
}

// Haha shapeless recipe bitches!!!! <3 <3 <3
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/dev/j3fftw/litexpansion/Items.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

public final class Items {

private static final Enchantment glowEnchant = Enchantment.getByKey(Constants.GLOW_ENCHANT);

// Category
public static final Category LITEXPANSION = new Category(
new NamespacedKey(LiteXpansion.getInstance(), "litexpansion"),
Expand Down Expand Up @@ -62,6 +64,16 @@ public final class Items {
"&6Wrench"
);

public static final SlimefunItemStack GLASS_CUTTER = new SlimefunItemStack(
"GLASS_CUTTER",
Material.GHAST_TEAR,
"&bGlass Cutter",
"",
"&7Cuts glass quickly",
"",
"&c&o&8\u21E8 &e\u26A1 &70 / 300 J"
);

public static final SlimefunItemStack TREETAP = new SlimefunItemStack(
"TREETAP",
Material.WOODEN_HOE,
Expand Down Expand Up @@ -340,7 +352,8 @@ public final class Items {
);

static {
ADVANCED_CIRCUIT.addEnchantment(Enchantment.getByKey(Constants.GLOW_ENCHANT), 1);
ADVANCED_CIRCUIT.addEnchantment(glowEnchant, 1);
GLASS_CUTTER.addEnchantment(glowEnchant, 1);
}
NCBPFluffyBear marked this conversation as resolved.
Show resolved Hide resolved

private Items() {}
Expand Down
78 changes: 78 additions & 0 deletions src/main/java/dev/j3fftw/litexpansion/items/GlassCutter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package dev.j3fftw.litexpansion.items;

import dev.j3fftw.litexpansion.Items;
import dev.j3fftw.litexpansion.LiteXpansion;
import io.github.thebusybiscuit.slimefun4.core.attributes.Rechargeable;
import io.github.thebusybiscuit.slimefun4.core.handlers.ItemUseHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunPlugin;
import io.github.thebusybiscuit.slimefun4.implementation.items.SimpleSlimefunItem;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
import me.mrCookieSlime.Slimefun.api.BlockStorage;
import me.mrCookieSlime.Slimefun.cscorelib2.protection.ProtectableAction;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;

/**
* The {@link GlassCutter} is a {@link SimpleSlimefunItem} that breaks
* glass and glass panes quickly.
*
* @author FluffyBear
*
*/
public class GlassCutter extends SimpleSlimefunItem<ItemUseHandler> implements Listener, Rechargeable {

NCBPFluffyBear marked this conversation as resolved.
Show resolved Hide resolved
public GlassCutter() {
super(Items.LITEXPANSION, Items.GLASS_CUTTER, RecipeType.ENHANCED_CRAFTING_TABLE, new ItemStack[] {
Items.REFINED_IRON, Items.REFINED_IRON, Items.REFINED_IRON,
new ItemStack(Material.SHEARS), Items.ADVANCED_CIRCUIT, new ItemStack(Material.SHEARS),
null, Items.CARBON_PLATE, null
});
NCBPFluffyBear marked this conversation as resolved.
Show resolved Hide resolved

Bukkit.getPluginManager().registerEvents(this, LiteXpansion.getInstance());
}

public ItemUseHandler getItemHandler() {
return e -> e.setUseBlock(Event.Result.DENY);
}

@EventHandler
@SuppressWarnings("ConstantConditions")
public void onGlassCut(PlayerInteractEvent e) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you just use the ItemUseHandler

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an advantage to using an item handler than an event except neatness

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it saves code and not having to run the same shit twice for no reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there no left click interact event, only right click

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right click has slower interaction speed, so no fun

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still maintain this should be in w handler. Right click makes more sense to begin with and it saves doing isItem

Block block = e.getClickedBlock();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final

if (e.getAction() == Action.LEFT_CLICK_BLOCK && isItem(e.getItem())
&& SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(),
block.getLocation(), ProtectableAction.BREAK_BLOCK)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Closing bracket and brace on new line

e.setCancelled(true);

SlimefunItem slimefunItem = BlockStorage.check(e.getClickedBlock());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final


if (slimefunItem != null) {
NCBPFluffyBear marked this conversation as resolved.
Show resolved Hide resolved
return;
}

if ((block.getType() == Material.GLASS
|| block.getType().name().endsWith("_GLASS")
|| block.getType().name().endsWith("_PANE"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should really be _GLASS_PANE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont work with clear glass pane @J3fftw1

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already fixed it

&& removeItemCharge(e.getItem(), 0.5F)
) {
block.getLocation().getWorld().dropItemNaturally(block.getLocation(),
new ItemStack(block.getType()));
block.setType(Material.AIR);
}
NCBPFluffyBear marked this conversation as resolved.
Show resolved Hide resolved
}
}

@Override
public float getMaxItemCharge(ItemStack itemStack) {
return 300;
}
}