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 96d0d6593..ec97d9b62 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 @@ -29,6 +29,7 @@ import net.minecraft.util.AxisAlignedBB; import net.minecraft.world.IBlockAccess; import nova.core.block.Block; +import nova.core.block.component.BlockProperty; import nova.core.block.component.LightEmitter; import nova.core.component.misc.Collider; import nova.core.component.renderer.StaticRenderer; @@ -38,6 +39,7 @@ import nova.core.retention.Data; import nova.core.retention.Storable; import nova.core.retention.Store; +import nova.core.sound.Sound; import nova.core.util.shape.Cuboid; import nova.core.world.World; import nova.core.wrapper.mc.forge.v17.util.WrapperEvent; @@ -65,7 +67,17 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) { BlockTransform transform = components.add(new BlockTransform()); transform.setWorld(world); transform.setPosition(pos); - components.add(new LightEmitter()).setEmittedLevel(() -> mcBlock.getLightValue(getMcBlockAccess(), x(), y(), z()) / 15.0F); + + components.add(new BlockProperty.Opacity().setOpacity(mcBlock.getMaterial().isOpaque() ? 1 : 0)); + if (mcBlock.isReplaceable(getMcBlockAccess(), x(), y(), z())) + components.add(BlockProperty.Replaceable.instance()); + + BlockProperty.BlockSound blockSound = components.add(new BlockProperty.BlockSound()); + blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", mcBlock.stepSound.func_150496_b())); + blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", mcBlock.stepSound.getBreakSound())); + blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", mcBlock.stepSound.getStepResourcePath())); + + components.add(new LightEmitter()).setEmittedLevel(() -> mcBlock.getLightValue(getMcBlockAccess(), x(), y(), z()) / 15.0); components.add(new Collider(this)) .setBoundingBox(() -> new Cuboid(mcBlock.getBlockBoundsMinX(), mcBlock.getBlockBoundsMinY(), mcBlock.getBlockBoundsMinZ(), mcBlock.getBlockBoundsMaxX(), mcBlock.getBlockBoundsMaxY(), mcBlock.getBlockBoundsMaxZ())) .setOcclusionBoxes(entity -> { diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlock.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlock.java index f88d1f8cd..7690371cb 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlock.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlock.java @@ -25,6 +25,7 @@ import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.Tessellator; @@ -42,6 +43,7 @@ import nova.core.block.Block; import nova.core.block.BlockFactory; import nova.core.block.Stateful; +import nova.core.block.component.BlockProperty; import nova.core.block.component.LightEmitter; import nova.core.component.Updater; import nova.core.component.misc.Collider; @@ -49,7 +51,9 @@ import nova.core.component.renderer.Renderer; import nova.core.component.renderer.StaticRenderer; import nova.core.retention.Storable; +import nova.core.sound.Sound; import nova.core.util.Direction; +import nova.core.util.math.MathUtil; import nova.core.util.math.MatrixStack; import nova.core.util.shape.Cuboid; import nova.core.wrapper.mc.forge.v17.util.WrapperEvent; @@ -86,11 +90,32 @@ public class FWBlock extends net.minecraft.block.Block implements ISimpleBlockRe private Map harvestedBlocks = new HashMap<>(); - // TODO: Resolve unknown material issue + private static Material getMcMaterial(BlockFactory factory) { + Block dummy = factory.build(); + if (dummy.components.has(BlockProperty.Opacity.class) || dummy.components.has(BlockProperty.Replaceable.class)) { + // TODO allow color selection + return new ProxyMaterial(MapColor.grayColor, + dummy.components.getOp(BlockProperty.Opacity.class), + dummy.components.getOp(BlockProperty.Replaceable.class)); + } else { + return Material.piston; + } + } + public FWBlock(BlockFactory factory) { - super(Material.piston); + //TODO: Hack build() method + super(getMcMaterial(factory)); this.factory = factory; this.dummy = factory.build(); + if (dummy.components.has(BlockProperty.BlockSound.class)) { + this.stepSound = new FWBlockSound(dummy.components.get(BlockProperty.BlockSound.class)); + } else { + BlockProperty.BlockSound properties = dummy.components.add(new BlockProperty.BlockSound()); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", soundTypeStone.getBreakSound())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", soundTypeStone.func_150496_b())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", soundTypeStone.getStepResourcePath())); + this.stepSound = soundTypeStone; + } this.blockClass = dummy.getClass(); this.setBlockName(dummy.getID()); @@ -128,6 +153,13 @@ public Block getBlockInstance(net.minecraft.world.IBlockAccess access, Vector3D private Block getBlockInstance(nova.core.world.World world, Vector3D position) { Block block = factory.build(); block.components.add(new MCBlockTransform(block, world, position)); + if (!block.components.has(BlockProperty.BlockSound.class)) { + BlockProperty.BlockSound properties = block.components.add(new BlockProperty.BlockSound()); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", soundTypeStone.getBreakSound())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", soundTypeStone.func_150496_b())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", soundTypeStone.getStepResourcePath())); + this.stepSound = soundTypeStone; + } return block; } @@ -174,7 +206,15 @@ public boolean hasTileEntity(int metadata) { @Override public TileEntity createTileEntity(World world, int metadata) { - return FWTileLoader.loadTile(dummy.getID()); + FWTile fwTile = FWTileLoader.loadTile(dummy.getID()); + if (!fwTile.block.components.has(BlockProperty.BlockSound.class)) { + BlockProperty.BlockSound properties = fwTile.block.components.add(new BlockProperty.BlockSound()); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", soundTypeStone.getBreakSound())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", soundTypeStone.func_150496_b())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", soundTypeStone.getStepResourcePath())); + this.stepSound = soundTypeStone; + } + return fwTile; } @Override @@ -330,7 +370,7 @@ public int getLightValue(IBlockAccess access, int x, int y, int z) { Optional opEmitter = blockInstance.components.getOp(LightEmitter.class); if (opEmitter.isPresent()) { - return Math.round(opEmitter.get().emittedLevel.get() * 15.0F); + return (int) MathUtil.clamp(Math.round(opEmitter.get().emittedLevel.getAsDouble() * 15), 0, 15); } else { return 0; } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlockSound.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlockSound.java new file mode 100644 index 000000000..e88d46624 --- /dev/null +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWBlockSound.java @@ -0,0 +1,41 @@ +package nova.core.wrapper.mc.forge.v17.wrapper.block.forward; + +import net.minecraft.block.Block; +import nova.core.block.component.BlockProperty; + +/** + * @author winsock, soniex2, ExE Boss + */ +public class FWBlockSound extends Block.SoundType { + private final BlockProperty.BlockSound blockSound; + + /** + * Construct a new FWBlockSound + * @param blockSound The BlockSound to use. + */ + public FWBlockSound(BlockProperty.BlockSound blockSound) { + super("", 1f, 1f); + this.blockSound = blockSound; + } + + @Override + public String getBreakSound() { + return blockSound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK) + .map(sound -> (sound.domain.isEmpty() && !sound.name.contains(".")) ? "dig." + sound.name : sound.getID()) + .orElseGet(super::getBreakSound); + } + + @Override + public String getStepResourcePath() { + return blockSound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK) + .map(sound -> (sound.domain.isEmpty() && !sound.name.contains(".")) ? "step." + sound.name : sound.getID()) + .orElseGet(super::getStepResourcePath); + } + + @Override + public String func_150496_b() { + return blockSound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE) + .map(sound -> sound.domain.isEmpty() ? sound.name : sound.getID()) + .orElseGet(this::getBreakSound); // By default MC uses the block break sound for block placement + } +} diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWTile.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWTile.java index 445ff63ce..636040c19 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWTile.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/FWTile.java @@ -39,9 +39,9 @@ */ public class FWTile extends TileEntity { - private String blockID; - private Block block; - private Data cacheData = null; + protected String blockID; + protected Block block; + protected Data cacheData = null; public FWTile() { 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 new file mode 100644 index 000000000..9dfc41ce6 --- /dev/null +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/forward/ProxyMaterial.java @@ -0,0 +1,36 @@ +package nova.core.wrapper.mc.forge.v17.wrapper.block.forward; + +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import nova.core.block.component.BlockProperty; + +import java.util.Optional; + +/** + * @author soniex2, ExE Boss + */ +public class ProxyMaterial extends Material { + private final Optional opacity; + private final Optional replaceable; + + /** + * Construct a new proxy material. + * @param color The map color. + * @param opacity The Opacity to use. + */ + public ProxyMaterial(MapColor color, Optional opacity, Optional replaceable) { + super(color); + this.opacity = opacity; + this.replaceable = replaceable; + } + + @Override + public boolean isOpaque() { + return opacity.isPresent() ? opacity.get().opacity == 1 : super.isOpaque(); + } + + @Override + public boolean isReplaceable() { + return replaceable.isPresent() || super.isReplaceable(); + } +} diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/world/BWWorld.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/world/BWWorld.java index 28f892222..34f04c275 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/world/BWWorld.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/world/BWWorld.java @@ -150,6 +150,6 @@ public String getID() { @Override public void playSoundAtPosition(Vector3D position, Sound sound) { - world().playSound(position.getX(), position.getY(), position.getZ(), sound.getID(), sound.pitch, sound.volume, false); + world().playSound(position.getX(), position.getY(), position.getZ(), sound.domain.isEmpty() ? sound.name : sound.getID(), sound.pitch, sound.volume, false); } } 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 16e34d321..fc642349d 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 @@ -69,14 +69,16 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) { transform.setWorld(world); transform.setPosition(pos); - components.add(new BlockProperty.Opacity().setLightTransmission(!mcBlock.getMaterial().blocksLight())); + components.add(new BlockProperty.Opacity().setOpacity(mcBlock.getMaterial().blocksLight() ? 1 : 0)); + if (mcBlock.isReplaceable((net.minecraft.world.World) getMcBlockAccess(), new BlockPos(x(), y(), z()))) + components.add(BlockProperty.Replaceable.instance()); BlockProperty.BlockSound blockSound = components.add(new BlockProperty.BlockSound()); blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", mcBlock.stepSound.getPlaceSound())); blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", mcBlock.stepSound.getBreakSound())); blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", mcBlock.stepSound.getStepSound())); - components.add(new LightEmitter()).setEmittedLevel(() -> mcBlock.getLightValue(getMcBlockAccess(), new BlockPos(x(), y(), z())) / 15.0F); + components.add(new LightEmitter()).setEmittedLevel(() -> mcBlock.getLightValue(getMcBlockAccess(), new BlockPos(x(), y(), z())) / 15.0); components.add(new Collider(this)) .setBoundingBox(() -> new Cuboid(mcBlock.getBlockBoundsMinX(), mcBlock.getBlockBoundsMinY(), mcBlock.getBlockBoundsMinZ(), mcBlock.getBlockBoundsMaxX(), mcBlock.getBlockBoundsMaxY(), mcBlock.getBlockBoundsMaxZ())) .setOcclusionBoxes(entity -> { diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlock.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlock.java index 36d9eb71a..26a8df55e 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlock.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlock.java @@ -45,6 +45,7 @@ import nova.core.retention.Storable; import nova.core.sound.Sound; import nova.core.util.Direction; +import nova.core.util.math.MathUtil; import nova.core.util.shape.Cuboid; import nova.core.wrapper.mc.forge.v18.util.WrapperEvent; import nova.internal.core.Game; @@ -76,9 +77,11 @@ public class FWBlock extends net.minecraft.block.Block { private static Material getMcMaterial(BlockFactory factory) { Block dummy = factory.build(); - if (dummy.components.has(BlockProperty.Opacity.class)) { + if (dummy.components.has(BlockProperty.Opacity.class) || dummy.components.has(BlockProperty.Replaceable.class)) { // TODO allow color selection - return new ProxyMaterial(MapColor.grayColor, dummy.components.get(BlockProperty.Opacity.class)); + return new ProxyMaterial(MapColor.grayColor, + dummy.components.getOp(BlockProperty.Opacity.class), + dummy.components.getOp(BlockProperty.Replaceable.class)); } else { return Material.piston; } @@ -133,6 +136,13 @@ private Block getBlockInstance(nova.core.world.World world, Vector3D position) { // TODO: Implement obj args Block block = factory.build(); block.components.add(new MCBlockTransform(block, world, position)); + if (!block.components.has(BlockProperty.BlockSound.class)) { + BlockProperty.BlockSound properties = block.components.add(new BlockProperty.BlockSound()); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", soundTypeStone.getBreakSound())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", soundTypeStone.getPlaceSound())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", soundTypeStone.getStepSound())); + this.stepSound = soundTypeStone; + } return block; } @@ -184,6 +194,13 @@ public TileEntity createTileEntity(World world, IBlockState state) { fwTile.block.components.getOrAdd(new MCBlockTransform(dummy, Game.natives().toNova(world), new Vector3D(lastExtendedStatePos.getX(), lastExtendedStatePos.getY(), lastExtendedStatePos.getZ()))); lastExtendedStatePos = null; } + if (!fwTile.block.components.has(BlockProperty.BlockSound.class)) { + BlockProperty.BlockSound properties = fwTile.block.components.add(new BlockProperty.BlockSound()); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", soundTypeStone.getBreakSound())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", soundTypeStone.getPlaceSound())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", soundTypeStone.getStepSound())); + this.stepSound = soundTypeStone; + } return fwTile; } @@ -312,7 +329,7 @@ public int getLightValue(IBlockAccess access, BlockPos pos) { Optional opEmitter = blockInstance.components.getOp(LightEmitter.class); if (opEmitter.isPresent()) { - return Math.round(opEmitter.get().emittedLevel.get() * 15.0F); + return (int) MathUtil.clamp(Math.round(opEmitter.get().emittedLevel.getAsDouble() * 15), 0, 15); } else { return 0; } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlockSound.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlockSound.java index f7f1326ab..812d5cd4e 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlockSound.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlockSound.java @@ -1,58 +1,41 @@ package nova.core.wrapper.mc.forge.v18.wrapper.block.forward; import net.minecraft.block.Block; -import nova.core.block.component.BlockProperty.BlockSound; -import nova.core.sound.Sound; +import nova.core.block.component.BlockProperty; /** - * @author winsock, soniex2 + * @author winsock, soniex2, ExE Boss */ public class FWBlockSound extends Block.SoundType { - private final BlockSound blockSound; + private final BlockProperty.BlockSound blockSound; /** * Construct a new FWBlockSound * @param blockSound The BlockSound to use. */ - public FWBlockSound(BlockSound blockSound) { + public FWBlockSound(BlockProperty.BlockSound blockSound) { super("", 1f, 1f); this.blockSound = blockSound; } @Override public String getBreakSound() { - if (blockSound.blockSoundSoundMap.containsKey(BlockSound.BlockSoundTrigger.BREAK)) { - Sound sound = blockSound.blockSoundSoundMap.get(BlockSound.BlockSoundTrigger.BREAK); - if (sound.domain.isEmpty() && !sound.name.contains(".")) { - return "dig." + sound.name; - } - return sound.getID(); - } - return super.getBreakSound(); + return blockSound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK) + .map(sound -> (sound.domain.isEmpty() && !sound.name.contains(".")) ? "dig." + sound.name : sound.getID()) + .orElseGet(super::getBreakSound); } @Override public String getStepSound() { - if (blockSound.blockSoundSoundMap.containsKey(BlockSound.BlockSoundTrigger.WALK)) { - Sound sound = blockSound.blockSoundSoundMap.get(BlockSound.BlockSoundTrigger.WALK); - if (sound.domain.isEmpty() && !sound.name.contains(".")) { - return "step." + sound.name; - } - return sound.getID(); - } - return super.getStepSound(); + return blockSound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK) + .map(sound -> (sound.domain.isEmpty() && !sound.name.contains(".")) ? "step." + sound.name : sound.getID()) + .orElseGet(super::getStepSound); } @Override public String getPlaceSound() { - if (blockSound.blockSoundSoundMap.containsKey(BlockSound.BlockSoundTrigger.WALK)) { - Sound sound = blockSound.blockSoundSoundMap.get(BlockSound.BlockSoundTrigger.WALK); - if (sound.domain.isEmpty()) { - return sound.name; - } - return sound.getID(); - } - // By default MC uses the block break sound for block placement - return this.getBreakSound(); + return blockSound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE) + .map(sound -> sound.domain.isEmpty() ? sound.name : sound.getID()) + .orElseGet(this::getBreakSound); // By default MC uses the block break sound for block placement } } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/ProxyMaterial.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/ProxyMaterial.java index a5b6cfc4b..df9f5a92f 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/ProxyMaterial.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/ProxyMaterial.java @@ -3,32 +3,39 @@ import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import nova.core.block.component.BlockProperty; -import nova.core.block.component.BlockProperty.Opacity; + +import java.util.Optional; /** - * @author soniex2 + * @author soniex2, ExE Boss */ public class ProxyMaterial extends Material { - private final Opacity opacity; + private final Optional opacity; + private final Optional replaceable; /** * Construct a new proxy material. * @param color The map color. * @param opacity The Opacity to use. */ - public ProxyMaterial(MapColor color, Opacity opacity) { + public ProxyMaterial(MapColor color, Optional opacity, Optional replaceable) { super(color); this.opacity = opacity; + this.replaceable = replaceable; } @Override public boolean blocksLight() { - return opacity.allowsLightThrough; + return opacity.isPresent() ? opacity.get().opacity == 1 : super.blocksLight(); } @Override public boolean isOpaque() { - return opacity.allowsLightThrough; + return opacity.isPresent() ? opacity.get().opacity == 1 : super.isOpaque(); } + @Override + public boolean isReplaceable() { + return replaceable.isPresent() || super.isReplaceable(); + } } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/world/BWWorld.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/world/BWWorld.java index d53baf619..d1194c62e 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/world/BWWorld.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/world/BWWorld.java @@ -159,6 +159,6 @@ public String getID() { @Override public void playSoundAtPosition(Vector3D position, Sound sound) { - world().playSoundEffect(position.getX(), position.getY(), position.getZ(), sound.getID(), sound.volume, sound.pitch); + world().playSound(position.getX(), position.getY(), position.getZ(), sound.domain.isEmpty() ? sound.name : sound.getID(), sound.volume, sound.pitch, false); } } diff --git a/src/main/java/nova/core/block/component/BlockProperty.java b/src/main/java/nova/core/block/component/BlockProperty.java index 23d8b6ba6..4999d1088 100644 --- a/src/main/java/nova/core/block/component/BlockProperty.java +++ b/src/main/java/nova/core/block/component/BlockProperty.java @@ -1,12 +1,12 @@ package nova.core.block.component; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import nova.core.component.Component; import nova.core.component.SidedComponent; import nova.core.component.UnsidedComponent; import nova.core.sound.Sound; +import java.util.HashMap; +import java.util.Map; import java.util.Optional; /** @@ -85,8 +85,8 @@ public double getResistance() { */ @UnsidedComponent public static class BlockSound extends Component implements BlockProperty { - public BiMap blockSoundSoundMap = HashBiMap.create(); - public Optional> customDefinedSounds; + private final Map blockSounds = new HashMap<>(); + private final Map customSounds = new HashMap<>(); /** * Sets a sound to play on a specified trigger. Note to set a {@link BlockSoundTrigger#CUSTOM_TRIGGER} use {@link BlockSound#setCustomBlockSound(String,Sound)} @@ -96,25 +96,20 @@ public static class BlockSound extends Component implements BlockProperty { * @return This instance for chaining if desired. */ public BlockSound setBlockSound(BlockSoundTrigger trigger, Sound sound) { - if (trigger == BlockSoundTrigger.CUSTOM_TRIGGER) { - return this; - } - blockSoundSoundMap.put(trigger, sound); + if (trigger != BlockSoundTrigger.CUSTOM_TRIGGER) + blockSounds.put(trigger, sound); return this; } /** * Sets a sound to an id of choice * - * @param id The custom id for the sound + * @param customTrigger The custom id for the sound * @param sound The sound to associate with the id * @return This instance for chaining if desired. */ - public BlockSound setCustomBlockSound(String id, Sound sound) { - if (!customDefinedSounds.isPresent()) { - customDefinedSounds = Optional.of(HashBiMap.create()); - } - customDefinedSounds.get().put(id, sound); + public BlockSound setCustomBlockSound(String customTrigger, Sound sound) { + customSounds.put(customTrigger, sound); return this; } @@ -124,30 +119,20 @@ public BlockSound setCustomBlockSound(String id, Sound sound) { * @param trigger The trigger to get the sound for * @return The sound object associated with the trigger */ - public Sound getSound(BlockSoundTrigger trigger) { - if (trigger == BlockSoundTrigger.CUSTOM_TRIGGER) { - return null; - } - if (blockSoundSoundMap.containsKey(trigger)) { - return blockSoundSoundMap.get(trigger); - } - return null; + public Optional getSound(BlockSoundTrigger trigger) { + if (trigger == BlockSoundTrigger.CUSTOM_TRIGGER) + return Optional.empty(); + return Optional.ofNullable(blockSounds.get(trigger)); } /** * Get the sound associated with a custom Id * - * @param customId The custom id of the sound + * @param customTrigger The custom id of the sound * @return The sound object associated with the custom Id */ - public Sound getCustomSound(String customId) { - if (!customDefinedSounds.isPresent()) { - return null; - } - if (customDefinedSounds.get().containsKey(customId)) { - return customDefinedSounds.get().get(customId); - } - return null; + public Optional getCustomSound(String customTrigger) { + return Optional.ofNullable(customSounds.get(customTrigger)); } /** @@ -159,7 +144,6 @@ public enum BlockSoundTrigger { WALK, CUSTOM_TRIGGER } - } /** @@ -169,12 +153,10 @@ public enum BlockSoundTrigger { */ @SidedComponent public static class Opacity extends Component implements BlockProperty { - // TODO maybe consider a double for opacity? Where 0 is 100% transparent and 1 is 100% opaque? - /** - * This boolean determines if the block should allow light through itself or not. + * This value determines if the block should allow light through itself or not. */ - public boolean allowsLightThrough = false; + public double opacity = 1; /** * Sets that the block should allow light through @@ -182,57 +164,49 @@ public static class Opacity extends Component implements BlockProperty { * @return This instance for chaining if desired. */ public Opacity setTransparent() { - allowsLightThrough = true; + opacity = 0; return this; } /** * Sets if light should be transmitted through this block * - * @param allowLightThrough Boolean flag if light should be allowed through + * @param opacity The block's opacity * @return This instance for chaining if desired. */ - public Opacity setLightTransmission(boolean allowLightThrough) { - this.allowsLightThrough = allowLightThrough; + public Opacity setOpacity(double opacity) { + this.opacity = opacity; return this; } } - // TODO -// /** -// * Indicates whether the block is replaceable. -// */ -// @UnsidedComponent -// public static final class Replaceable extends Component implements BlockProperty { -// /** -// * Singleton for Replaceable. -// */ -// private static Replaceable theInstance = null; -// -// /** -// * Gets the singleton for Replaceable. -// * -// * @return The singleton for Replaceable. -// */ -// public static Replaceable instance() { -// if (theInstance == null) { -// theInstance = new Replaceable(); -// } -// -// return theInstance; -// } -// -// private Replaceable() { -// } -// -// @Override -// public boolean equals(Object o) { -// return this == o || o instanceof Replaceable; -// } -// -// @Override -// public int hashCode() { -// return Replaceable.class.hashCode(); -// } -// } + /** + * Indicates whether the block is replaceable. + */ + @UnsidedComponent + public static final class Replaceable extends Component implements BlockProperty { + private static final Replaceable instance = new Replaceable(); + + /** + * Gets the singleton for Replaceable. + * + * @return The singleton for Replaceable. + */ + public static Replaceable instance() { + return instance; + } + + private Replaceable() { + } + + @Override + public boolean equals(Object o) { + return this == o || o instanceof Replaceable; + } + + @Override + public int hashCode() { + return Replaceable.class.hashCode(); + } + } } diff --git a/src/main/java/nova/core/block/component/LightEmitter.java b/src/main/java/nova/core/block/component/LightEmitter.java index 32f2d43bf..e926eeb4b 100644 --- a/src/main/java/nova/core/block/component/LightEmitter.java +++ b/src/main/java/nova/core/block/component/LightEmitter.java @@ -21,7 +21,7 @@ import nova.core.component.Component; import nova.core.component.SidedComponent; -import java.util.function.Supplier; +import java.util.function.DoubleSupplier; @SidedComponent public class LightEmitter extends Component { @@ -30,9 +30,9 @@ public class LightEmitter extends Component { * Called to get the amount of light emitted from a block. * Returns the level of light that is emitted by the block. */ - public Supplier emittedLevel = () -> 0f; + public DoubleSupplier emittedLevel = () -> 0; - public LightEmitter setEmittedLevel(Supplier emittedLevel) { + public LightEmitter setEmittedLevel(DoubleSupplier emittedLevel) { this.emittedLevel = emittedLevel; return this; } diff --git a/src/main/java/nova/core/item/ItemBlock.java b/src/main/java/nova/core/item/ItemBlock.java index f30af52f5..c6cdd6b3a 100644 --- a/src/main/java/nova/core/item/ItemBlock.java +++ b/src/main/java/nova/core/item/ItemBlock.java @@ -67,9 +67,9 @@ protected boolean onPostPlace(Entity entity, World world, Vector3D placePos, Dir if (opBlock.isPresent() && opBlock.get().sameType(blockFactory)) { //TODO: What if the block is NOT placed by a player? opBlock.get().events.publish(new Block.PlaceEvent(entity, side, hit, this)); - if (opBlock.get().components.has(BlockProperty.BlockSound.class)) { - world.playSoundAtPosition(placePos, opBlock.get().components.get(BlockProperty.BlockSound.class).getSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE)); - } + opBlock.get().components.getOp(BlockProperty.BlockSound.class) + .flatMap(sound -> sound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE)) + .ifPresent(sound -> world.playSoundAtPosition(placePos, sound)); } addCount(-1); diff --git a/src/main/java/nova/core/sound/Sound.java b/src/main/java/nova/core/sound/Sound.java index 127bc23d3..f029ddd7d 100644 --- a/src/main/java/nova/core/sound/Sound.java +++ b/src/main/java/nova/core/sound/Sound.java @@ -69,4 +69,19 @@ public Sound withVolume(float volume) { return new Sound(domain, name, pitch, speed, volume); } + public Sound withPS(float pitch, float speed) { + return new Sound(domain, name, pitch, speed, volume); + } + + public Sound withPV(float pitch, float volume) { + return new Sound(domain, name, pitch, speed, volume); + } + + public Sound withSV(float speed, float volume) { + return new Sound(domain, name, pitch, speed, volume); + } + + public Sound with(float pitch, float speed, float volume) { + return new Sound(domain, name, pitch, speed, volume); + } }