Skip to content

Commit

Permalink
🐛 fix(Tesseract, Wireless Item Input, Wireless Item Output): Do not h…
Browse files Browse the repository at this point in the history
…ardcode Items for block menus. Fixes #223
  • Loading branch information
ProfElements committed Sep 19, 2024
1 parent 9c72805 commit 831b4c0
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public Tesseract(ItemGroup itemGroup, int capacity, int energyRate, SlimefunItem

addItemHandler(onBlockBreak());

new BlockMenuPreset("TESSERACT", "Tesseract") {
new BlockMenuPreset(Items.Keys.TESSERACT.asSlimefunId(), "Tesseract") {

@Override
public void init() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import me.mrCookieSlime.Slimefun.api.inventory.BlockMenuPreset;
import me.mrCookieSlime.Slimefun.api.inventory.DirtyChestMenu;
import me.mrCookieSlime.Slimefun.api.item_transport.ItemTransportFlow;
import me.profelements.dynatech.registries.Items;

import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.block.Block;
Expand All @@ -32,30 +34,31 @@

public class WirelessItemInput extends SlimefunItem implements EnergyNetComponent {

private final int capacity;

public WirelessItemInput(ItemGroup itemGroup, int capacity, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe) {
private final int capacity;

public WirelessItemInput(ItemGroup itemGroup, int capacity, SlimefunItemStack item, RecipeType recipeType,
ItemStack[] recipe) {
super(itemGroup, item, recipeType, recipe);

this.capacity = capacity;

addItemHandler(onBlockBreak());
new BlockMenuPreset("WIRELESS_ITEM_INPUT", "Wireless Item Input") {

new BlockMenuPreset(Items.Keys.WIRELESS_ITEM_INPUT.asSlimefunId(), "Wireless Item Input") {

@Override
public void init() {
constructMenu(this);
}

@Override
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.inventory.bypass") || Slimefun.getProtectionManager().hasPermission(p, b.getLocation(), Interaction.INTERACT_BLOCK);
public boolean canOpen(Block b, Player p) {
return p.hasPermission("slimefun.inventory.bypass") || Slimefun.getProtectionManager().hasPermission(p,
b.getLocation(), Interaction.INTERACT_BLOCK);


}

@Override
@Override
public int[] getSlotsAccessedByItemTransport(ItemTransportFlow flow) {
return new int[0];
}
Expand All @@ -66,52 +69,51 @@ public int[] getSlotsAccessedByItemTransport(DirtyChestMenu menu, ItemTransportF
return getInputSlots();
} else {
return getOutputSlots();
}
}
}
};
}

@Override
public void preRegister() {
addItemHandler(new BlockTicker(){
addItemHandler(new BlockTicker() {

@Override
public boolean isSynchronized() {
return false;
}
@Override
public boolean isSynchronized() {
return false;
}

@Override
public void tick(Block block, SlimefunItem sfItem, Config data) {
@Override
public void tick(Block block, SlimefunItem sfItem, Config data) {
WirelessItemInput.this.tick(block);

}


});
}

});
}

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

@Override
public void onPlayerBreak(BlockBreakEvent event, ItemStack block, List<ItemStack> drops) {
@Override
public void onPlayerBreak(BlockBreakEvent event, ItemStack block, List<ItemStack> drops) {
BlockMenu inv = BlockStorage.getInventory(event.getBlock());

if (inv != null) {
inv.dropItems(event.getBlock().getLocation(), getInputSlots());
inv.dropItems(event.getBlock().getLocation(), getOutputSlots());

}

BlockStorage.clearBlockInfo(event.getBlock().getLocation());
}

BlockStorage.clearBlockInfo(event.getBlock().getLocation());
}

};
}

protected void tick(Block b) {
BlockMenu menu = BlockStorage.getInventory(b);
updateKnowledgePane(menu, getCharge(b.getLocation()));
BlockMenu menu = BlockStorage.getInventory(b);
updateKnowledgePane(menu, getCharge(b.getLocation()));
}

private void updateKnowledgePane(BlockMenu menu, int currentCharge) {
Expand All @@ -121,32 +123,33 @@ private void updateKnowledgePane(BlockMenu menu, int currentCharge) {

lore.clear();
lore.add(" ");
lore.add(ChatColor.WHITE +"Current Power: " + currentCharge);
lore.add(ChatColor.WHITE +"Current Status: Interesting.");
lore.add(ChatColor.WHITE + "Current Power: " + currentCharge);
lore.add(ChatColor.WHITE + "Current Status: Interesting.");

im.setLore(lore);
knowledgePane.setItemMeta(im);
}

//Boilerplate for machines.
// Boilerplate for machines.
public void constructMenu(BlockMenuPreset preset) {
preset.drawBackground(ChestMenuUtils.getInputSlotTexture(), getBorder());
preset.addItem(4, new CustomItemStack(Material.PURPLE_STAINED_GLASS_PANE, "&fKnowledge Pane"), ChestMenuUtils.getEmptyClickHandler());
preset.addItem(4, new CustomItemStack(Material.PURPLE_STAINED_GLASS_PANE, "&fKnowledge Pane"),
ChestMenuUtils.getEmptyClickHandler());
}


public int[] getBorder() {
return new int[] {0,1,2,3,5,6,7,8,45,46,47,48,49,50,51,52,53};
return new int[] { 0, 1, 2, 3, 5, 6, 7, 8, 45, 46, 47, 48, 49, 50, 51, 52, 53 };
}

public int[] getInputSlots() {
return new int[] {9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44};
return new int[] { 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44 };
}

public int[] getOutputSlots() {
return new int[0];
return new int[0];
}

@Override
public int getCapacity() {
return capacity;
Expand All @@ -158,9 +161,3 @@ public EnergyNetComponentType getEnergyComponentType() {
}

}






Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public WirelessItemOutput(ItemGroup itemGroup, int capacity, SlimefunItemStack i

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

new BlockMenuPreset("WIRELESS_ITEM_OUTPUT", "Wireless Item Output") {
new BlockMenuPreset(Items.Keys.WIRELESS_ITEM_OUTPUT.asSlimefunId(), "Wireless Item Output") {
@Override
public void init() {
constructMenu(this);
Expand Down

0 comments on commit 831b4c0

Please sign in to comment.