Skip to content

Commit

Permalink
Try to fix drop air on Explosive Pickaxe
Browse files Browse the repository at this point in the history
  • Loading branch information
StarWishsama committed Feb 2, 2020
1 parent d2c2ce5 commit 59127df
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 87 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.mrCookieSlime</groupId>
<artifactId>Slimefun</artifactId>
<version>4.2-git-20200201</version>
<version>4.2-UNOFFCIAL-20200202</version>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void saveAllPlayers() {
}

if (players > 0) {
Slimefun.getLogger().log(Level.INFO, "Auto-Saved Player Data for {0} Player(s)!", players);
Slimefun.getLogger().log(Level.INFO, "自动储存了 {0} 个玩家的数据!", players);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public void onBlockBreak(BlockBreakEvent e) {
return;
}
}
else if (item != null) {
else if (item.getType() != Material.AIR) {
for (ItemHandler handler : SlimefunItem.getHandlers(BlockBreakHandler.class)) {
if (((BlockBreakHandler) handler).onBlockBreak(e, item, fortune, drops)) break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,87 +25,87 @@
import me.mrCookieSlime.Slimefun.api.SlimefunItemStack;

public class ExplosivePickaxe extends SimpleSlimefunItem<BlockBreakHandler> implements NotPlaceable, DamageableItem {
private boolean damageOnUse;
public ExplosivePickaxe(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, String[] keys, Object[] values) {
super(category, item, recipeType, recipe, keys, values);
}

@Override
protected boolean areItemHandlersPrivate() {
return false;
}
@Override
public BlockBreakHandler getItemHandler() {
return (e, item, fortune, drops) -> {
if (isItem(item)) {
if (Slimefun.hasUnlocked(e.getPlayer(), this, true)) {
e.getBlock().getWorld().createExplosion(e.getBlock().getLocation(), 0.0F);
e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1F);
for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
if (x == 0 && y == 0 && z == 0) {
continue;
}
Block b = e.getBlock().getRelative(x, y, z);
if (b.getType() != Material.AIR && !b.isLiquid() && !MaterialCollections.getAllUnbreakableBlocks().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), ProtectableAction.BREAK_BLOCK)) {
SlimefunPlugin.getProtectionManager().logAction(e.getPlayer(), b, ProtectableAction.BREAK_BLOCK);

b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
SlimefunItem sfItem = BlockStorage.check(b);
boolean allow = false;
if (sfItem != null && !(sfItem instanceof HandledBlock)) {
SlimefunBlockHandler handler = SlimefunPlugin.getRegistry().getBlockHandlers().get(sfItem.getID());
if (handler != null) {
allow = handler.onBreak(e.getPlayer(), e.getBlock(), sfItem, UnregisterReason.PLAYER_BREAK);
}
if (allow) {
drops.add(BlockStorage.retrieve(e.getBlock()));
}
}
else if (b.getType() == Material.PLAYER_HEAD) {
b.breakNaturally();
}
else if (b.getType().name().endsWith("_SHULKER_BOX")) {
b.breakNaturally();
}
else {
for (ItemStack drop : b.getDrops(getItem())) {
b.getWorld().dropItemNaturally(b.getLocation(), (b.getType().toString().endsWith("_ORE") && b.getType() != Material.IRON_ORE && b.getType() != Material.GOLD_ORE) ? new CustomItem(drop, fortune): drop);
}
b.setType(Material.AIR);
}
damageItem(e.getPlayer(), item);
}
}
}
}
}
return true;
}
else return false;
};
}
@Override
public void postRegister() {
damageOnUse = ((boolean) Slimefun.getItemValue(getID(), "damage-on-use"));
}

@Override
public boolean isDamageable() {
return damageOnUse;
}

}

private boolean damageOnUse;

public ExplosivePickaxe(Category category, SlimefunItemStack item, RecipeType recipeType, ItemStack[] recipe, String[] keys, Object[] values) {
super(category, item, recipeType, recipe, keys, values);
}

@Override
protected boolean areItemHandlersPrivate() {
return false;
}

@Override
public BlockBreakHandler getItemHandler() {
return (e, item, fortune, drops) -> {
if (isItem(item)) {
if (Slimefun.hasUnlocked(e.getPlayer(), this, true)) {
e.getBlock().getWorld().createExplosion(e.getBlock().getLocation(), 0.0F);
e.getBlock().getWorld().playSound(e.getBlock().getLocation(), Sound.ENTITY_GENERIC_EXPLODE, 0.3F, 1F);

for (int x = -1; x <= 1; x++) {
for (int y = -1; y <= 1; y++) {
for (int z = -1; z <= 1; z++) {
if (x == 0 && y == 0 && z == 0) {
continue;
}

Block b = e.getBlock().getRelative(x, y, z);

if (b.getType() != Material.AIR && !b.isLiquid() && !MaterialCollections.getAllUnbreakableBlocks().contains(b.getType()) && SlimefunPlugin.getProtectionManager().hasPermission(e.getPlayer(), b.getLocation(), ProtectableAction.BREAK_BLOCK)) {
SlimefunPlugin.getProtectionManager().logAction(e.getPlayer(), b, ProtectableAction.BREAK_BLOCK);

b.getWorld().playEffect(b.getLocation(), Effect.STEP_SOUND, b.getType());
SlimefunItem sfItem = BlockStorage.check(b);
boolean allow = false;

if (sfItem != null && !(sfItem instanceof HandledBlock)) {
SlimefunBlockHandler handler = SlimefunPlugin.getRegistry().getBlockHandlers().get(sfItem.getID());

if (handler != null) {
allow = handler.onBreak(e.getPlayer(), e.getBlock(), sfItem, UnregisterReason.PLAYER_BREAK);
}

if (allow) {
drops.add(BlockStorage.retrieve(e.getBlock()));
}
}
else if (b.getType() == Material.PLAYER_HEAD) {
b.breakNaturally();
}
else if (b.getType().name().endsWith("_SHULKER_BOX")) {
b.breakNaturally();
}
else {
for (ItemStack drop : b.getDrops(getItem())) {
b.getWorld().dropItemNaturally(b.getLocation(), (b.getType().toString().endsWith("_ORE") && b.getType() != Material.IRON_ORE && b.getType() != Material.GOLD_ORE) ? new CustomItem(drop, fortune): drop);
}
b.setType(Material.AIR);
}

damageItem(e.getPlayer(), item);
}
}
}
}
}

return true;
}
else return false;
};
}

@Override
public void postRegister() {
damageOnUse = ((boolean) Slimefun.getItemValue(getID(), "damage-on-use"));
}

@Override
public boolean isDamageable() {
return damageOnUse;
}

}

0 comments on commit 59127df

Please sign in to comment.