diff --git a/src/main/java/cn/nukkit/block/BlockCopperBulb.java b/src/main/java/cn/nukkit/block/BlockCopperBulb.java index 456ed242a..c97d5e4f2 100644 --- a/src/main/java/cn/nukkit/block/BlockCopperBulb.java +++ b/src/main/java/cn/nukkit/block/BlockCopperBulb.java @@ -1,9 +1,11 @@ package cn.nukkit.block; +import cn.nukkit.block.properties.enums.OxidizationLevel; import cn.nukkit.item.Item; import cn.nukkit.item.ItemBlock; import cn.nukkit.utils.BlockColor; +import org.jetbrains.annotations.NotNull; public class BlockCopperBulb extends BlockCopperBulbBase { @@ -41,4 +43,9 @@ public BlockColor getColor() { public int getLightLevel() { return this.isLit() ? 15 : 0; } + + @Override + public @NotNull OxidizationLevel getOxidizationLevel() { + return OxidizationLevel.UNAFFECTED; + } } \ No newline at end of file diff --git a/src/main/java/cn/nukkit/block/BlockCopperBulbBase.java b/src/main/java/cn/nukkit/block/BlockCopperBulbBase.java index a2cf590ae..40a961791 100644 --- a/src/main/java/cn/nukkit/block/BlockCopperBulbBase.java +++ b/src/main/java/cn/nukkit/block/BlockCopperBulbBase.java @@ -1,15 +1,18 @@ package cn.nukkit.block; import cn.nukkit.Player; +import cn.nukkit.block.properties.enums.OxidizationLevel; import cn.nukkit.event.redstone.RedstoneUpdateEvent; import cn.nukkit.item.Item; import cn.nukkit.level.Level; import cn.nukkit.math.BlockFace; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; /** * @author glorydark */ -public abstract class BlockCopperBulbBase extends BlockSolidMeta { +public abstract class BlockCopperBulbBase extends BlockSolidMeta implements Oxidizable, Waxable { public static final int LIT_BIT = 0x01; // 0001 @@ -23,39 +26,45 @@ public BlockCopperBulbBase(int meta) { super(meta); } - @Override - public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) { - if (this.level.isBlockPowered(this.getLocation())) { - this.setLit(true); - this.setPowered(true); - } - return this.getLevel().setBlock(this, this, true, true); - } - @Override public int onUpdate(int type) { - if (type == Level.BLOCK_UPDATE_NORMAL || type == Level.BLOCK_UPDATE_REDSTONE) { - // Redstone event + Oxidizable.super.onUpdate(type); + + if (type == Level.BLOCK_UPDATE_REDSTONE) { RedstoneUpdateEvent ev = new RedstoneUpdateEvent(this); getLevel().getServer().getPluginManager().callEvent(ev); + if (ev.isCancelled()) { return 0; } - if (this.level.isBlockPowered(this.getLocation())) { - this.setLit(true); + + if ((this.level.isBlockPowered(this))) { + this.setLit(!(isLit())); this.setPowered(true); - this.level.setBlock(this, this, true); - return type; - } else if (this.isLit() || this.isPowered()) { - this.setLit(false); + this.getLevel().setBlock(this, this, true, true); + return 1; + } + + if(isPowered()) { this.setPowered(false); - this.level.setBlock(this, this, true); - return type; + this.getLevel().setBlock(this, this, true, true); + return 1; } } return 0; } + @Override + public boolean onActivate(@NotNull Item item, Player player) { + return Waxable.super.onActivate(item, player) + || Oxidizable.super.onActivate(item, player); + } + + @Override + public boolean canBeActivated() { + return true; + } + @Override public double getHardness() { return 0.3D; @@ -81,4 +90,58 @@ public boolean isPowered() { public void setPowered(boolean lit) { this.setDamage(POWERED_BIT, lit ? 1 : 0); } + + @Override + public boolean isWaxed() { + return false; + } + + @Override + public Block getStateWithOxidizationLevel(@NotNull OxidizationLevel oxidizationLevel) { + BlockCopperBulbBase bulb = (BlockCopperBulbBase) Block.get((getCopperId(isWaxed(), oxidizationLevel))); + bulb.setDamage(getDamage()); + return bulb; + } + + @Override + public boolean setOxidizationLevel(@NotNull OxidizationLevel oxidizationLevel) { + if (getOxidizationLevel().equals(oxidizationLevel)) { + return true; + } + + BlockCopperBulbBase bulb = (BlockCopperBulbBase) Block.get((getCopperId(isWaxed(), oxidizationLevel))); + bulb.setDamage(getDamage()); + + return getValidLevel().setBlock(this, bulb); + } + + @Override + public boolean setWaxed(boolean waxed) { + if (isWaxed() == waxed) { + return true; + } + + BlockCopperBulbBase bulb = (BlockCopperBulbBase) Block.get((getCopperId(waxed, getOxidizationLevel()))); + bulb.setDamage(getDamage()); + + return getValidLevel().setBlock(this, bulb); + } + + protected int getCopperId(boolean waxed, @Nullable OxidizationLevel oxidizationLevel) { + if (oxidizationLevel == null) { + return getId(); + } + switch (oxidizationLevel) { + case UNAFFECTED: + return waxed? WAXED_COPPER_BULB : COPPER_BULB; + case EXPOSED: + return waxed? WAXED_EXPOSED_COPPER_BULB : EXPOSED_COPPER_BULB; + case WEATHERED: + return waxed? WAXED_WEATHERED_COPPER_BULB : WEATHERED_COPPER_BULB; + case OXIDIZED: + return waxed? WAXED_OXIDIZED_COPPER_BULB : OXIDIZED_COPPER_BULB; + default: + return getId(); + } + } } diff --git a/src/main/java/cn/nukkit/block/BlockExposedCopperBulb.java b/src/main/java/cn/nukkit/block/BlockExposedCopperBulb.java index f43943ce3..98ee99871 100644 --- a/src/main/java/cn/nukkit/block/BlockExposedCopperBulb.java +++ b/src/main/java/cn/nukkit/block/BlockExposedCopperBulb.java @@ -1,6 +1,8 @@ package cn.nukkit.block; +import cn.nukkit.block.properties.enums.OxidizationLevel; import cn.nukkit.utils.BlockColor; +import org.jetbrains.annotations.NotNull; public class BlockExposedCopperBulb extends BlockCopperBulbBase { @@ -31,4 +33,9 @@ public BlockColor getColor() { public int getLightLevel() { return this.isLit() ? 12 : 0; } + + @Override + public @NotNull OxidizationLevel getOxidizationLevel() { + return OxidizationLevel.EXPOSED; + } } \ No newline at end of file diff --git a/src/main/java/cn/nukkit/block/BlockOxidizedCopperBulb.java b/src/main/java/cn/nukkit/block/BlockOxidizedCopperBulb.java index 7fc34dcc3..b9bfb1885 100644 --- a/src/main/java/cn/nukkit/block/BlockOxidizedCopperBulb.java +++ b/src/main/java/cn/nukkit/block/BlockOxidizedCopperBulb.java @@ -1,6 +1,8 @@ package cn.nukkit.block; +import cn.nukkit.block.properties.enums.OxidizationLevel; import cn.nukkit.utils.BlockColor; +import org.jetbrains.annotations.NotNull; public class BlockOxidizedCopperBulb extends BlockCopperBulbBase { @@ -31,4 +33,9 @@ public BlockColor getColor() { public int getLightLevel() { return this.isLit() ? 4 : 0; } + + @Override + public @NotNull OxidizationLevel getOxidizationLevel() { + return OxidizationLevel.OXIDIZED; + } } \ No newline at end of file diff --git a/src/main/java/cn/nukkit/block/BlockWaxedCopperBulb.java b/src/main/java/cn/nukkit/block/BlockWaxedCopperBulb.java index cf2215a64..25f9debb1 100644 --- a/src/main/java/cn/nukkit/block/BlockWaxedCopperBulb.java +++ b/src/main/java/cn/nukkit/block/BlockWaxedCopperBulb.java @@ -1,6 +1,8 @@ package cn.nukkit.block; +import cn.nukkit.block.properties.enums.OxidizationLevel; import cn.nukkit.utils.BlockColor; +import org.jetbrains.annotations.NotNull; public class BlockWaxedCopperBulb extends BlockCopperBulbBase { @@ -31,4 +33,14 @@ public BlockColor getColor() { public int getLightLevel() { return this.isLit() ? 15 : 0; } + + @Override + public @NotNull OxidizationLevel getOxidizationLevel() { + return OxidizationLevel.UNAFFECTED; + } + + @Override + public boolean isWaxed() { + return true; + } } \ No newline at end of file diff --git a/src/main/java/cn/nukkit/block/BlockWaxedExposedCopperBulb.java b/src/main/java/cn/nukkit/block/BlockWaxedExposedCopperBulb.java index fb29dd48a..0a1ac06d0 100644 --- a/src/main/java/cn/nukkit/block/BlockWaxedExposedCopperBulb.java +++ b/src/main/java/cn/nukkit/block/BlockWaxedExposedCopperBulb.java @@ -1,6 +1,8 @@ package cn.nukkit.block; +import cn.nukkit.block.properties.enums.OxidizationLevel; import cn.nukkit.utils.BlockColor; +import org.jetbrains.annotations.NotNull; public class BlockWaxedExposedCopperBulb extends BlockCopperBulbBase { @@ -31,4 +33,14 @@ public BlockColor getColor() { public int getLightLevel() { return this.isLit() ? 12 : 0; } + + @Override + public @NotNull OxidizationLevel getOxidizationLevel() { + return OxidizationLevel.EXPOSED; + } + + @Override + public boolean isWaxed() { + return true; + } } \ No newline at end of file diff --git a/src/main/java/cn/nukkit/block/BlockWaxedOxidizedCopperBulb.java b/src/main/java/cn/nukkit/block/BlockWaxedOxidizedCopperBulb.java index 75ec5cc04..6279182cf 100644 --- a/src/main/java/cn/nukkit/block/BlockWaxedOxidizedCopperBulb.java +++ b/src/main/java/cn/nukkit/block/BlockWaxedOxidizedCopperBulb.java @@ -1,6 +1,8 @@ package cn.nukkit.block; +import cn.nukkit.block.properties.enums.OxidizationLevel; import cn.nukkit.utils.BlockColor; +import org.jetbrains.annotations.NotNull; public class BlockWaxedOxidizedCopperBulb extends BlockCopperBulbBase { @@ -31,4 +33,14 @@ public BlockColor getColor() { public int getLightLevel() { return this.isLit() ? 4 : 0; } + + @Override + public @NotNull OxidizationLevel getOxidizationLevel() { + return OxidizationLevel.OXIDIZED; + } + + @Override + public boolean isWaxed() { + return true; + } } \ No newline at end of file diff --git a/src/main/java/cn/nukkit/block/BlockWaxedWeatheredCopperBulb.java b/src/main/java/cn/nukkit/block/BlockWaxedWeatheredCopperBulb.java index 6fbbcb0d5..5fd7e348c 100644 --- a/src/main/java/cn/nukkit/block/BlockWaxedWeatheredCopperBulb.java +++ b/src/main/java/cn/nukkit/block/BlockWaxedWeatheredCopperBulb.java @@ -1,6 +1,8 @@ package cn.nukkit.block; +import cn.nukkit.block.properties.enums.OxidizationLevel; import cn.nukkit.utils.BlockColor; +import org.jetbrains.annotations.NotNull; public class BlockWaxedWeatheredCopperBulb extends BlockCopperBulbBase { @@ -31,4 +33,14 @@ public BlockColor getColor() { public int getLightLevel() { return this.isLit() ? 8 : 0; } + + @Override + public @NotNull OxidizationLevel getOxidizationLevel() { + return OxidizationLevel.WEATHERED; + } + + @Override + public boolean isWaxed() { + return true; + } } \ No newline at end of file diff --git a/src/main/java/cn/nukkit/block/BlockWeatheredCopperBulb.java b/src/main/java/cn/nukkit/block/BlockWeatheredCopperBulb.java index e849bdb23..41747fac0 100644 --- a/src/main/java/cn/nukkit/block/BlockWeatheredCopperBulb.java +++ b/src/main/java/cn/nukkit/block/BlockWeatheredCopperBulb.java @@ -1,6 +1,8 @@ package cn.nukkit.block; +import cn.nukkit.block.properties.enums.OxidizationLevel; import cn.nukkit.utils.BlockColor; +import org.jetbrains.annotations.NotNull; public class BlockWeatheredCopperBulb extends BlockCopperBulbBase { @@ -31,4 +33,9 @@ public BlockColor getColor() { public int getLightLevel() { return this.isLit() ? 8 : 0; } + + @Override + public @NotNull OxidizationLevel getOxidizationLevel() { + return OxidizationLevel.WEATHERED; + } } \ No newline at end of file