Skip to content

Commit

Permalink
Updated to new Block Handler system
Browse files Browse the repository at this point in the history
  • Loading branch information
TheBusyBiscuit committed Apr 9, 2021
1 parent 2d3a859 commit 7c92625
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -105,7 +105,7 @@
<dependency>
<groupId>com.github.TheBusyBiscuit</groupId>
<artifactId>Slimefun4</artifactId>
<version>RC-20</version>
<version>RC-21</version>
<scope>provided</scope>
<exclusions>
<exclusion>
Expand Down
Expand Up @@ -10,8 +10,10 @@
import org.bukkit.event.block.BlockPlaceEvent;
import org.bukkit.inventory.ItemStack;

import io.github.thebusybiscuit.slimefun4.core.handlers.BlockBreakHandler;
import io.github.thebusybiscuit.slimefun4.core.handlers.BlockPlaceHandler;
import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems;
import io.github.thebusybiscuit.slimefun4.implementation.handlers.SimpleBlockBreakHandler;
import io.github.thebusybiscuit.slimefun4.utils.ColoredMaterial;
import me.mrCookieSlime.Slimefun.Lists.RecipeType;
import me.mrCookieSlime.Slimefun.Objects.SlimefunItem.SlimefunItem;
Expand Down Expand Up @@ -40,40 +42,8 @@ SlimefunItems.WITHER_PROOF_OBSIDIAN, getSmallerEnderChest(c1, c2, c3), SlimefunI

int[] slots = IntStream.range(0, size).toArray();

addItemHandler(new BlockPlaceHandler(false) {

@Override
public void onPlayerPlace(BlockPlaceEvent e) {
int yaw = 0;

EnderChest chest = (EnderChest) e.getBlock().getBlockData();

switch (chest.getFacing()) {
case NORTH:
yaw = 180;
break;
case SOUTH:
yaw = 0;
break;
case WEST:
yaw = 90;
break;
case EAST:
yaw = -90;
break;
default:
break;
}

BlockStorage.addBlockInfo(e.getBlock(), "yaw", String.valueOf(yaw));
ColorIndicator.updateIndicator(e.getBlock(), c1, c2, c3, yaw + 45);
}
});

SlimefunItem.registerBlockHandler(getId(), (p, b, tool, reason) -> {
ColorIndicator.removeIndicator(b);
return true;
});
addItemHandler(onBlockBreak());
addItemHandler(onBlockPlace(c1, c2, c3));

new BlockMenuPreset(getId(), "&eEnder Chest", true) {

Expand All @@ -82,7 +52,6 @@ public void init() {
setSize(size);

addMenuOpeningHandler(p -> p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_OPEN, 1.8F, 1.6F));

addMenuCloseHandler(p -> p.playSound(p.getLocation(), Sound.BLOCK_ENDER_CHEST_CLOSE, 1.8F, 1.6F));
}

Expand All @@ -102,6 +71,51 @@ public boolean canOpen(Block b, Player p) {
EnderChest chest = (EnderChest) b.getBlockData();

switch (chest.getFacing()) {
case NORTH:
yaw = 180;
break;
case SOUTH:
yaw = 0;
break;
case WEST:
yaw = 90;
break;
case EAST:
yaw = -90;
break;
default:
break;
}

BlockStorage.addBlockInfo(b, "yaw", String.valueOf(yaw));
}

ColorIndicator.updateIndicator(b, c1, c2, c3, yaw + 45);
return true;
}
};
}

private BlockBreakHandler onBlockBreak() {
return new SimpleBlockBreakHandler() {

@Override
public void onBlockBreak(Block b) {
ColorIndicator.removeIndicator(b);
}
};
}

private BlockPlaceHandler onBlockPlace(int c1, int c2, int c3) {
return new BlockPlaceHandler(false) {

@Override
public void onPlayerPlace(BlockPlaceEvent e) {
int yaw = 0;

EnderChest chest = (EnderChest) e.getBlock().getBlockData();

switch (chest.getFacing()) {
case NORTH:
yaw = 180;
break;
Expand All @@ -116,13 +130,10 @@ public boolean canOpen(Block b, Player p) {
break;
default:
break;
}

BlockStorage.addBlockInfo(b, "yaw", String.valueOf(yaw));
}

ColorIndicator.updateIndicator(b, c1, c2, c3, yaw + 45);
return true;
BlockStorage.addBlockInfo(e.getBlock(), "yaw", String.valueOf(yaw));
ColorIndicator.updateIndicator(e.getBlock(), c1, c2, c3, yaw + 45);
}
};
}
Expand Down

This file was deleted.

0 comments on commit 7c92625

Please sign in to comment.