diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlock.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlock.java index 988564bde..04b346843 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlock.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlock.java @@ -69,7 +69,7 @@ public BWBlock(net.minecraft.block.Block block) { public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) { this.mcBlock = block; components.add(new BWBlockTransform(this, world, pos)); - components.add(new BlockProperty.Opacity().setOpacity(mcBlock.getMaterial().isOpaque() ? 1 : 0)); + components.add(new BlockProperty.Opacity()).setOpacity(() -> mcBlock.getMaterial().isOpaque() ? 1 : 0); Optional.of(components.add(new BlockProperty.Replaceable())) .filter(r -> block != Blocks.air) .ifPresent(r -> r.setReplaceable(() -> mcBlock.isReplaceable(blockAccess(), xi(), yi(), zi()))); diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/ProxyMaterial.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/ProxyMaterial.java index 149dcc155..91361cbf3 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/ProxyMaterial.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/ProxyMaterial.java @@ -45,6 +45,11 @@ public ProxyMaterial(MapColor color, Optional opacity, Op this.replaceable = replaceable; } + @Override + public boolean getCanBlockGrass() { + return opacity.isPresent() ? opacity.get().isOpaque() : super.isOpaque(); + } + @Override public boolean isOpaque() { return opacity.isPresent() ? opacity.get().isOpaque() : super.isOpaque(); diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlock.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlock.java index 3a50b3f47..839543baa 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlock.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlock.java @@ -74,7 +74,7 @@ public BWBlock(net.minecraft.block.Block block) { public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) { this.mcBlock = block; components.add(new BWBlockTransform(this, world, pos)); - components.add(new BlockProperty.Opacity().setOpacity(mcBlock.getMaterial().blocksLight() ? 1 : 0)); + components.add(new BlockProperty.Opacity()).setOpacity(() -> mcBlock.getMaterial().isOpaque() ? 1 : 0); Optional.of(components.add(new BlockProperty.Replaceable())) .filter(r -> block != Blocks.air) .ifPresent(r -> r.setReplaceable(() -> mcBlock.isReplaceable((net.minecraft.world.World) blockAccess(), blockPos()))); diff --git a/src/main/java/nova/core/block/component/BlockProperty.java b/src/main/java/nova/core/block/component/BlockProperty.java index e1be8267e..b7336d1e1 100644 --- a/src/main/java/nova/core/block/component/BlockProperty.java +++ b/src/main/java/nova/core/block/component/BlockProperty.java @@ -30,6 +30,7 @@ import java.util.Map; import java.util.Optional; import java.util.function.BooleanSupplier; +import java.util.function.DoubleSupplier; /** * Block properties. @@ -46,7 +47,7 @@ public interface BlockProperty { */ @UnsidedComponent public static class Hardness extends Component implements BlockProperty { - private double hardness = 1.0; + private DoubleSupplier hardness = () -> 1; /** * Sets the breaking difficulty. @@ -54,18 +55,28 @@ public static class Hardness extends Component implements BlockProperty { * @param hardness The breaking difficulty. * @return This instance for chaining if desired. */ - public Hardness setHardness(double hardness) { + public Hardness setHardness(DoubleSupplier hardness) { this.hardness = hardness; return this; } + /** + * Sets the breaking difficulty. + * + * @param hardness The breaking difficulty. + * @return This instance for chaining if desired. + */ + public Hardness setHardness(double hardness) { + return this.setHardness(() -> hardness); + } + /** * Gets the breaking difficulty. * * @return The breaking difficulty. */ public double getHardness() { - return hardness; + return hardness.getAsDouble(); } } @@ -77,7 +88,7 @@ public double getHardness() { */ @UnsidedComponent public static class Resistance extends Component implements BlockProperty { - private double resistance = 1.0; + private DoubleSupplier resistance = () -> 1; /** * Sets the blast resistance @@ -85,18 +96,28 @@ public static class Resistance extends Component implements BlockProperty { * @param resistance The blast resistance. * @return This instance for chaining if desired. */ - public Resistance setResistance(double resistance) { + public Resistance setResistance(DoubleSupplier resistance) { this.resistance = resistance; return this; } + /** + * Sets the blast resistance + * + * @param resistance The blast resistance. + * @return This instance for chaining if desired. + */ + public Resistance setResistance(double resistance) { + return this.setResistance(() -> resistance); + } + /** * Gets the blast resistance. * * @return The blast resistance. */ public double getResistance() { - return resistance; + return resistance.getAsDouble(); } } @@ -176,10 +197,13 @@ public enum BlockSoundTrigger { @SidedComponent @SuppressWarnings("deprecation") public static class Opacity extends Component implements BlockProperty { + private static final DoubleSupplier TRANSPARENT = () -> 0; + private static final DoubleSupplier OPAQUE = () -> 1; + /** * This value determines if the block should allow light through itself or not. */ - private double opacity = 1; + private DoubleSupplier opacity = OPAQUE; /** * Sets that the block should allow light through @@ -187,7 +211,7 @@ public static class Opacity extends Component implements BlockProperty { * @return This instance for chaining if desired. */ public Opacity setTransparent() { - opacity = 0; + opacity = TRANSPARENT; return this; } @@ -197,7 +221,7 @@ public Opacity setTransparent() { * @return This instance for chaining if desired. */ public Opacity setOpaque() { - opacity = 1; + opacity = OPAQUE; return this; } @@ -207,18 +231,28 @@ public Opacity setOpaque() { * @param opacity The block's opacity * @return This instance for chaining if desired. */ - public Opacity setOpacity(double opacity) { - this.opacity = MathUtil.clamp(opacity, 0, 1); + public Opacity setOpacity(DoubleSupplier opacity) { + this.opacity = opacity; return this; } + /** + * Sets if light should be transmitted through this block + * + * @param opacity The block's opacity + * @return This instance for chaining if desired. + */ + public Opacity setOpacity(double opacity) { + return this.setOpacity(opacity <= 0 ? TRANSPARENT : (opacity >= 1 ? OPAQUE : () -> opacity)); + } + /** * This value determines if the block should allow light through itself or not. * * @return The block's opacity */ public double getOpacity() { - return opacity; + return MathUtil.clamp(opacity.getAsDouble(), 0, 1); } /** @@ -227,7 +261,7 @@ public double getOpacity() { * @return If the block should allow light through */ public boolean isTransparent() { - return opacity < 1; + return getOpacity() < 1; } /** @@ -236,7 +270,7 @@ public boolean isTransparent() { * @return If the block should disallow light through */ public boolean isOpaque() { - return opacity == 1; + return getOpacity() == 1; } } diff --git a/src/test/java/nova/core/block/component/BlockPropertyTest.java b/src/test/java/nova/core/block/component/BlockPropertyTest.java index 16532cc18..ced3e6c1b 100644 --- a/src/test/java/nova/core/block/component/BlockPropertyTest.java +++ b/src/test/java/nova/core/block/component/BlockPropertyTest.java @@ -32,14 +32,20 @@ public class BlockPropertyTest { @Test public void testHardness() { - BlockProperty.Hardness hardness = new BlockProperty.Hardness().setHardness(1.0); + BlockProperty.Hardness hardness = new BlockProperty.Hardness(); assertThat(hardness.getHardness()).isEqualTo(1.0); + + hardness.setHardness(10.0); + assertThat(hardness.getHardness()).isEqualTo(10.0); } @Test public void testResistance() { - BlockProperty.Resistance resistance = new BlockProperty.Resistance().setResistance(1.0); + BlockProperty.Resistance resistance = new BlockProperty.Resistance(); assertThat(resistance.getResistance()).isEqualTo(1.0); + + resistance.setResistance(10.0); + assertThat(resistance.getResistance()).isEqualTo(10.0); } @Test @@ -74,6 +80,16 @@ public void testOpacity() { assertThat(opacity.getOpacity()).isEqualTo(0.5); assertThat(opacity.isOpaque()).isFalse(); assertThat(opacity.isTransparent()).isTrue(); + + opacity.setOpacity(-0.5); + assertThat(opacity.getOpacity()).isEqualTo(0.0); + assertThat(opacity.isOpaque()).isFalse(); + assertThat(opacity.isTransparent()).isTrue(); + + opacity.setOpacity(1.5); + assertThat(opacity.getOpacity()).isEqualTo(1.0); + assertThat(opacity.isOpaque()).isTrue(); + assertThat(opacity.isTransparent()).isFalse(); } @Test