diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/ClientProxy.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/ClientProxy.java index bf22027a1..e282016a5 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/ClientProxy.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/ClientProxy.java @@ -43,12 +43,12 @@ import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.FWBlock; import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.FWTile; import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.FWTileRenderer; +import nova.core.wrapper.mc.forge.v17.wrapper.entity.EntityConverter; import nova.core.wrapper.mc.forge.v17.wrapper.entity.backward.BWEntityFX; import nova.core.wrapper.mc.forge.v17.wrapper.entity.forward.FWEntity; import nova.core.wrapper.mc.forge.v17.wrapper.entity.forward.FWEntityFX; import nova.core.wrapper.mc.forge.v17.wrapper.entity.forward.FWEntityRenderer; import nova.core.wrapper.mc.forge.v17.wrapper.item.FWItem; -import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import java.io.IOException; @@ -156,7 +156,7 @@ public Entity spawnParticle(net.minecraft.world.World world, EntityFactory facto if (build instanceof BWEntityFX) { EntityFX entityFX = ((BWEntityFX) build).createEntityFX(); FMLClientHandler.instance().getClient().effectRenderer.addEffect(entityFX); - return Game.natives().toNova(entityFX); + return EntityConverter.instance().toNova(entityFX); } else { FWEntityFX bwEntityFX = new FWEntityFX(world, factory); FMLClientHandler.instance().getClient().effectRenderer.addEffect(bwEntityFX); @@ -174,7 +174,7 @@ public Entity spawnParticle(net.minecraft.world.World world, Entity entity) { entityFX.posY = position.getY(); entityFX.posZ = position.getZ(); FMLClientHandler.instance().getClient().effectRenderer.addEffect(entityFX); - return Game.natives().toNova(entityFX); + return EntityConverter.instance().toNova(entityFX); } else { FWEntityFX bwEntityFX = new FWEntityFX(world, entity); FMLClientHandler.instance().getClient().effectRenderer.addEffect(bwEntityFX); diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/FMLEventHandler.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/FMLEventHandler.java index b271713b9..ae03520b9 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/FMLEventHandler.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/FMLEventHandler.java @@ -23,6 +23,7 @@ import cpw.mods.fml.common.eventhandler.SubscribeEvent; import cpw.mods.fml.common.gameevent.TickEvent; import nova.core.event.PlayerEvent; +import nova.core.wrapper.mc.forge.v17.wrapper.entity.EntityConverter; import nova.internal.core.Game; /** @@ -32,12 +33,12 @@ public class FMLEventHandler { @SubscribeEvent public void playerJoin(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent evt) { - Game.events().publish(new PlayerEvent.Join(Game.natives().toNova(evt.player))); + Game.events().publish(new PlayerEvent.Join(EntityConverter.instance().toNova(evt.player))); } @SubscribeEvent public void playerLeave(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent evt) { - Game.events().publish(new PlayerEvent.Leave(Game.natives().toNova(evt.player))); + Game.events().publish(new PlayerEvent.Leave(EntityConverter.instance().toNova(evt.player))); } @SubscribeEvent diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/ForgeEventHandler.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/ForgeEventHandler.java index c0dad0d3b..ee7533775 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/ForgeEventHandler.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/launcher/ForgeEventHandler.java @@ -28,6 +28,8 @@ import nova.core.event.PlayerEvent; import nova.core.item.Item; import nova.core.item.ItemDictionary; +import nova.core.wrapper.mc.forge.v17.wrapper.block.world.WorldConverter; +import nova.core.wrapper.mc.forge.v17.wrapper.entity.EntityConverter; import nova.core.wrapper.mc.forge.v17.wrapper.item.ItemConverter; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -38,12 +40,12 @@ public class ForgeEventHandler { @SubscribeEvent public void worldUnload(WorldEvent.Load evt) { - Game.events().publish(new nova.core.event.WorldEvent.Load(Game.natives().toNova(evt.world))); + Game.events().publish(new nova.core.event.WorldEvent.Load(WorldConverter.instance().toNova(evt.world))); } @SubscribeEvent public void worldLoad(WorldEvent.Unload evt) { - Game.events().publish(new nova.core.event.WorldEvent.Unload(Game.natives().toNova(evt.world))); + Game.events().publish(new nova.core.event.WorldEvent.Unload(WorldConverter.instance().toNova(evt.world))); } @SubscribeEvent @@ -58,20 +60,20 @@ public void onOreRegister(OreDictionary.OreRegisterEvent event) { @SubscribeEvent public void playerJoin(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent evt) { - Game.events().publish(new PlayerEvent.Join(Game.natives().toNova(evt.player))); + Game.events().publish(new PlayerEvent.Join(EntityConverter.instance().toNova(evt.player))); } @SubscribeEvent public void playerLeave(cpw.mods.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent evt) { - Game.events().publish(new PlayerEvent.Leave(Game.natives().toNova(evt.player))); + Game.events().publish(new PlayerEvent.Leave(EntityConverter.instance().toNova(evt.player))); } @SubscribeEvent public void playerInteractEvent(PlayerInteractEvent event) { nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact( - Game.natives().toNova(event.world), + WorldConverter.instance().toNova(event.world), new Vector3D(event.x, event.y, event.z), - Game.natives().toNova(event.entityPlayer), + EntityConverter.instance().toNova(event.entityPlayer), nova.core.event.PlayerEvent.Interact.Action.values()[event.action.ordinal()] ); diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/manager/MCRetentionManager.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/manager/MCRetentionManager.java index 4caca4e6e..6c42d0f67 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/manager/MCRetentionManager.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/manager/MCRetentionManager.java @@ -30,6 +30,7 @@ import nova.core.retention.Data; import nova.core.retention.Storable; import nova.core.util.registry.RetentionManager; +import nova.core.wrapper.mc.forge.v17.wrapper.data.DataConverter; import nova.internal.core.Game; import java.io.File; @@ -59,13 +60,13 @@ public void saveAll() { public void save(String filename, Storable storable) { Data saveMap = new Data(); storable.save(saveMap); - saveFile(filename, Game.natives().toNative(saveMap)); + saveFile(filename, DataConverter.instance().toNative(saveMap)); } @Override public void load(String filename, Storable storable) { NBTTagCompound nbt = loadFile(filename); - storable.load(Game.natives().toNova(nbt)); + storable.load(DataConverter.instance().toNova(nbt)); } /** @@ -76,7 +77,7 @@ public void load(String filename, Storable storable) { */ public boolean saveFile(File file, NBTTagCompound data) { try { - File tempFile = new File(file.getParent(), file.getName() + "_tmp.dat"); + File tempFile = new File(file.getParent(), file.getName().replaceFirst("\\.nbt$", ".tmp.nbt")); CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile)); @@ -94,7 +95,7 @@ public boolean saveFile(File file, NBTTagCompound data) { } public boolean saveFile(File saveDirectory, String filename, NBTTagCompound data) { - return saveFile(new File(saveDirectory, filename + ".dat"), data); + return saveFile(new File(saveDirectory, filename + ".nbt"), data); } public boolean saveFile(String filename, NBTTagCompound data) { @@ -122,7 +123,7 @@ public NBTTagCompound loadFile(File file) { * @return The NBT data */ public NBTTagCompound loadFile(File saveDirectory, String filename) { - return loadFile(new File(saveDirectory, filename + ".dat")); + return loadFile(new File(saveDirectory, filename + ".nbt")); } public NBTTagCompound loadFile(String filename) { diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/network/discriminator/NovaPacket.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/network/discriminator/NovaPacket.java index 28ca85769..e6c709938 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/network/discriminator/NovaPacket.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/network/discriminator/NovaPacket.java @@ -23,11 +23,11 @@ import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import net.minecraft.entity.player.EntityPlayer; -import nova.core.entity.Entity; import nova.core.entity.component.Player; import nova.core.network.handler.PacketHandler; import nova.core.wrapper.mc.forge.v17.network.MCPacket; import nova.core.wrapper.mc.forge.v17.network.netty.MCNetworkManager; +import nova.core.wrapper.mc.forge.v17.wrapper.entity.EntityConverter; import nova.internal.core.Game; /** @@ -65,7 +65,7 @@ public void handle(EntityPlayer player) { MCNetworkManager network = (MCNetworkManager) Game.network(); PacketHandler packetHandler = network.getPacketType(data.readInt()); int subId = data.readInt(); - MCPacket packet = new MCPacket(data.slice(), ((Entity) Game.natives().toNova(player)).components.get(Player.class)); + MCPacket packet = new MCPacket(data.slice(), EntityConverter.instance().toNova(player).components.get(Player.class)); //Set the ID of the packet packet.setID(subId); packetHandler.read(packet); diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/DirectionConverter.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/DirectionConverter.java index 79e807ac2..1a239d9c1 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/DirectionConverter.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/DirectionConverter.java @@ -69,7 +69,7 @@ public EnumFacing toNative(Direction novaObj) { case SOUTH: return EnumFacing.SOUTH; case WEST: return EnumFacing.WEST; case EAST: return EnumFacing.EAST; - default: return (EnumFacing) null; + default: return null; } } } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/BlockConverter.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/BlockConverter.java index d60806686..33f91ceeb 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/BlockConverter.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/BlockConverter.java @@ -121,8 +121,7 @@ private void registerNOVAToMinecraft() { public boolean canReplace() { return true; } - }, evt -> { - }); + }, evt -> {}); blockManager.register(airBlock); 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 d123ffce3..284017c89 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 @@ -33,7 +33,6 @@ import nova.core.block.component.LightEmitter; import nova.core.component.misc.Collider; import nova.core.component.renderer.StaticRenderer; -import nova.core.component.transform.BlockTransform; import nova.core.item.ItemFactory; import nova.core.render.model.CustomModel; import nova.core.retention.Data; @@ -47,6 +46,7 @@ import nova.core.wrapper.mc.forge.v17.wrapper.cuboid.CuboidConverter; import nova.core.wrapper.mc.forge.v17.wrapper.data.DataConverter; import nova.core.wrapper.mc.forge.v17.wrapper.entity.EntityConverter; +import nova.core.wrapper.mc.forge.v17.wrapper.item.ItemConverter; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -69,9 +69,11 @@ 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)); - if (mcBlock.isReplaceable(blockAccess(), xi(), yi(), zi())) - components.add(BlockProperty.Replaceable.instance()); + components.add(new BlockProperty.Opacity()).setOpacity(() -> mcBlock.getMaterial().isOpaque() ? 1 : 0); + BlockProperty.Replaceable replaceable = components.add(new BlockProperty.Replaceable()); + if (block != Blocks.air) { + replaceable.setReplaceable(() -> mcBlock.canPlaceBlockAt((net.minecraft.world.World) blockAccess(), xi(), yi(), zi())); + } BlockProperty.BlockSound blockSound = components.add(new BlockProperty.BlockSound()); blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", mcBlock.stepSound.func_150496_b())); @@ -113,7 +115,7 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) { @Override public ItemFactory getItemFactory() { - return Game.natives().toNova(new ItemStack(Item.getItemFromBlock(mcBlock))); + return ItemConverter.instance().toNova(new ItemStack(Item.getItemFromBlock(mcBlock))).getFactory(); } public int xi() { @@ -147,11 +149,6 @@ public Optional getTileEntity() { return Optional.ofNullable(mcTileEntity); } - @Override - public boolean canReplace() { - return mcBlock.canPlaceBlockAt((net.minecraft.world.World) blockAccess(), xi(), yi(), zi()); - } - @Override public boolean shouldDisplacePlacement() { if (mcBlock == Blocks.snow_layer && (blockAccess().getBlockMetadata(xi(), yi(), zi()) & 7) < 1) { diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlockTransform.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlockTransform.java index 6c43f36c8..50f223589 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlockTransform.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/backward/BWBlockTransform.java @@ -25,7 +25,6 @@ import nova.core.component.transform.BlockTransform; import nova.core.world.World; import nova.core.wrapper.mc.forge.v17.wrapper.block.world.WorldConverter; -import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import java.util.Optional; @@ -61,8 +60,8 @@ public IBlockAccess blockAccess() { @Override public void setWorld(World world) { - net.minecraft.world.World oldWorld = Game.natives().toNative(this.world); - net.minecraft.world.World newWorld = Game.natives().toNative(world); + net.minecraft.world.World oldWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world); + net.minecraft.world.World newWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(world); Optional tileEntity = Optional.ofNullable(oldWorld.getTileEntity((int) position.getX(), (int) position.getY(), (int) position.getZ())); Optional nbt = Optional.empty(); if (tileEntity.isPresent()) { @@ -82,7 +81,7 @@ public void setWorld(World world) { @Override public void setPosition(Vector3D position) { - net.minecraft.world.World world = Game.natives().toNative(this.world); + net.minecraft.world.World world = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world); Optional tileEntity = Optional.ofNullable(world.getTileEntity((int) this.position.getX(), (int) this.position.getY(), (int) this.position.getZ())); Optional nbt = Optional.empty(); if (tileEntity.isPresent()) { 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 1ffcc743c..3b4e8bf29 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 @@ -47,7 +47,6 @@ import nova.core.block.component.LightEmitter; import nova.core.component.Updater; import nova.core.component.misc.Collider; -import nova.core.component.renderer.DynamicRenderer; import nova.core.component.renderer.Renderer; import nova.core.component.renderer.StaticRenderer; import nova.core.retention.Storable; @@ -57,6 +56,10 @@ import nova.core.util.math.MatrixStack; import nova.core.util.shape.Cuboid; import nova.core.wrapper.mc.forge.v17.util.WrapperEvent; +import nova.core.wrapper.mc.forge.v17.wrapper.block.world.WorldConverter; +import nova.core.wrapper.mc.forge.v17.wrapper.cuboid.CuboidConverter; +import nova.core.wrapper.mc.forge.v17.wrapper.entity.EntityConverter; +import nova.core.wrapper.mc.forge.v17.wrapper.item.ItemConverter; import nova.core.wrapper.mc.forge.v17.wrapper.render.BWModel; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -149,7 +152,7 @@ public Block getBlockInstance(net.minecraft.world.IBlockAccess access, Vector3D e.printStackTrace(); } } - return getBlockInstance((nova.core.world.World) Game.natives().toNova(access), position); + return getBlockInstance(WorldConverter.instance().toNova(access), position); } @@ -193,18 +196,18 @@ public ArrayList getDrops(World world, int x, int y, int z, int metad Block.DropEvent event = new Block.DropEvent(blockInstance); blockInstance.events.publish(event); - return new ArrayList<>( - event.drops - .stream() - .map(item -> (ItemStack) Game.natives().toNative(item)) - .collect(Collectors.toCollection(ArrayList::new)) - ); + return event.drops + .stream() + .map(ItemConverter.instance()::toNative) + .collect(Collectors.toCollection(ArrayList::new)); } @Override public boolean hasTileEntity(int metadata) { // A block requires a TileEntity if it stores data or if it ticks. - return Storable.class.isAssignableFrom(blockClass) || Stateful.class.isAssignableFrom(blockClass) || Updater.class.isAssignableFrom(blockClass); + return Storable.class.isAssignableFrom(blockClass) + || Stateful.class.isAssignableFrom(blockClass) + || Updater.class.isAssignableFrom(blockClass); } @Override @@ -261,7 +264,7 @@ public void onNeighborBlockChange(World world, int x, int y, int z, net.minecraf @Override public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z, boolean willHarvest) { Block blockInstance = getBlockInstance(world, new Vector3D(x, y, z)); - Block.RemoveEvent evt = new Block.RemoveEvent(Optional.of(Game.natives().toNova(player))); + Block.RemoveEvent evt = new Block.RemoveEvent(Optional.of(EntityConverter.instance().toNova(player))); blockInstance.events.publish(evt); if (evt.result) { return super.removedByPlayer(world, player, x, y, z, willHarvest); @@ -273,7 +276,7 @@ public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, i public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player) { Block blockInstance = getBlockInstance(world, new Vector3D(x, y, z)); MovingObjectPosition mop = player.rayTrace(10, 1); - Block.LeftClickEvent evt = new Block.LeftClickEvent(Game.natives().toNova(player), Direction.fromOrdinal(mop.sideHit), new Vector3D(mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord)); + Block.LeftClickEvent evt = new Block.LeftClickEvent(EntityConverter.instance().toNova(player), Direction.fromOrdinal(mop.sideHit), new Vector3D(mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord)); blockInstance.events.publish(evt); } @@ -285,7 +288,7 @@ public void registerBlockIcons(IIconRegister ir) { @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { Block blockInstance = getBlockInstance(world, new Vector3D(x, y, z)); - Block.RightClickEvent evt = new Block.RightClickEvent(Game.natives().toNova(player), Direction.fromOrdinal(side), new Vector3D(hitX, hitY, hitZ)); + Block.RightClickEvent evt = new Block.RightClickEvent(EntityConverter.instance().toNova(player), Direction.fromOrdinal(side), new Vector3D(hitX, hitY, hitZ)); blockInstance.events.publish(evt); return evt.result; } @@ -293,7 +296,7 @@ public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer p @Override public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) { Block blockInstance = getBlockInstance(world, new Vector3D(x, y, z)); - blockInstance.components.getOp(Collider.class).ifPresent(collider -> blockInstance.events.publish(new Collider.CollideEvent(Game.natives().toNova(entity)))); + blockInstance.components.getOp(Collider.class).ifPresent(collider -> blockInstance.events.publish(new Collider.CollideEvent(EntityConverter.instance().toNova(entity)))); } @Override @@ -312,24 +315,25 @@ public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, i if (blockInstance.components.has(Collider.class)) { Cuboid cuboid = blockInstance.components.get(Collider.class).boundingBox.get(); - return Game.natives().toNative(cuboid.add(new Vector3D(x, y, z))); + return CuboidConverter.instance().toNative(cuboid.add(new Vector3D(x, y, z))); } return super.getSelectedBoundingBoxFromPool(world, x, y, z); } @Override + @SuppressWarnings({"unchecked", "rawtypes"}) public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB aabb, List list, Entity entity) { Block blockInstance = getBlockInstance(world, new Vector3D(x, y, z)); blockInstance.components.getOp(Collider.class).ifPresent( collider -> { - Set boxes = collider.occlusionBoxes.apply(Optional.ofNullable(entity != null ? Game.natives().toNova(entity) : null)); + Set boxes = collider.occlusionBoxes.apply(Optional.ofNullable(entity != null ? EntityConverter.instance().toNova(entity) : null)); list.addAll( boxes .stream() .map(c -> c.add(new Vector3D(x, y, z))) - .filter(c -> c.intersects((Cuboid) Game.natives().toNova(aabb))) - .map(cuboid -> Game.natives().toNative(cuboid)) + .filter(c -> c.intersects(CuboidConverter.instance().toNova(aabb))) + .map(CuboidConverter.instance()::toNative) .collect(Collectors.toList()) ); } @@ -490,11 +494,34 @@ public void renderItem(ItemRenderType type, ItemStack item, Object... data) { @Override public float getExplosionResistance(Entity expEntity, World world, int x, int y, int z, double explosionX, double p_explosionresistance, double explosionY) { // TODO: Maybe do something withPriority these parameters. - return (float) getBlockInstance(world, new Vector3D(x, y, z)).getResistance() * 30; + + // This number was calculated from the blast resistance of Stone, + // which requires exactly one cubic meter of TNT to get blown up. + // + // 1. During construction, the setResistance method is called + // on minecraft:stone with a value of 10. + // + // 2. The setResistance method multiplies that by 3 and assigns + // the result to the blockResistance instance variable. + // + // 3. Finally, the getExplosionResistance method divides the + // blockResistance instance variable by 5 and returns the result. + // + // From this we see that minecraft:stone’s final blast resistance is 6. + + return (float) getBlockInstance(world, new Vector3D(x, y, z)).getResistance() * 6; } @Override public float getBlockHardness(World world, int x, int y, int z) { return (float) getBlockInstance(world, new Vector3D(x, y, z)).getHardness() * 2; } + + @Override + public boolean isReplaceable(IBlockAccess access, int x, int y, int z) { + return getBlockInstance(access, new Vector3D(x, y, z)) + .components.getOp(BlockProperty.Replaceable.class) + .filter(BlockProperty.Replaceable::isReplaceable) + .isPresent(); + } } 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 index e88d46624..1c1a872e3 100644 --- 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 @@ -1,3 +1,23 @@ +/* + * Copyright (c) 2016 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + package nova.core.wrapper.mc.forge.v17.wrapper.block.forward; import net.minecraft.block.Block; 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 9dfc41ce6..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 @@ -1,3 +1,23 @@ +/* + * Copyright (c) 2016 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + package nova.core.wrapper.mc.forge.v17.wrapper.block.forward; import net.minecraft.block.material.MapColor; @@ -17,6 +37,7 @@ public class ProxyMaterial extends Material { * Construct a new proxy material. * @param color The map color. * @param opacity The Opacity to use. + * @param replaceable If this block is replaceable. */ public ProxyMaterial(MapColor color, Optional opacity, Optional replaceable) { super(color); @@ -24,13 +45,18 @@ 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().opacity == 1 : super.isOpaque(); + return opacity.isPresent() ? opacity.get().isOpaque() : super.isOpaque(); } @Override public boolean isReplaceable() { - return replaceable.isPresent() || super.isReplaceable(); + return replaceable.map(BlockProperty.Replaceable::isReplaceable).orElseGet(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 45b66bf5d..67945f0dc 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 @@ -33,15 +33,19 @@ import nova.core.util.shape.Cuboid; import nova.core.world.World; import nova.core.wrapper.mc.forge.v17.launcher.NovaMinecraft; +import nova.core.wrapper.mc.forge.v17.wrapper.block.BlockConverter; import nova.core.wrapper.mc.forge.v17.wrapper.block.backward.BWBlock; import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.FWBlock; import nova.core.wrapper.mc.forge.v17.wrapper.block.forward.MCBlockTransform; +import nova.core.wrapper.mc.forge.v17.wrapper.entity.EntityConverter; import nova.core.wrapper.mc.forge.v17.wrapper.entity.backward.BWEntity; import nova.core.wrapper.mc.forge.v17.wrapper.entity.forward.FWEntity; import nova.core.wrapper.mc.forge.v17.wrapper.entity.forward.MCEntityTransform; +import nova.core.wrapper.mc.forge.v17.wrapper.item.ItemConverter; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -93,7 +97,7 @@ public Optional getBlock(Vector3D position) { @Override public boolean setBlock(Vector3D position, BlockFactory blockFactory) { //TODO: Implement object arguments - net.minecraft.block.Block mcBlock = Game.natives().toNative(blockFactory.build()); + net.minecraft.block.Block mcBlock = BlockConverter.instance().toNative(blockFactory); return world().setBlock((int) position.getX(), (int) position.getY(), (int) position.getZ(), mcBlock != null ? mcBlock : Blocks.air); } @@ -116,6 +120,7 @@ public Entity addClientEntity(EntityFactory factory) { } @Override + @SuppressWarnings("unchecked") public Entity addClientEntity(Entity entity) { return NovaMinecraft.proxy.spawnParticle(world(), entity); } @@ -128,23 +133,24 @@ public void removeEntity(Entity entity) { } @Override + @SuppressWarnings("unchecked") public Set getEntities(Cuboid bound) { - return (Set) world().getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(bound.min.getX(), bound.min.getY(), bound.min.getZ(), bound.max.getX(), bound.max.getY(), bound.max.getZ())) + return ((List) world().getEntitiesWithinAABB(Entity.class, AxisAlignedBB.getBoundingBox(bound.min.getX(), bound.min.getY(), bound.min.getZ(), bound.max.getX(), bound.max.getY(), bound.max.getZ()))) .stream() - .map(mcEnt -> Game.natives().getNative(Entity.class, net.minecraft.entity.Entity.class).toNova((net.minecraft.entity.Entity) mcEnt)) + .map(EntityConverter.instance()::toNova) .collect(Collectors.toSet()); } @Override public Entity addEntity(Vector3D position, Item item) { - EntityItem entityItem = new EntityItem(world(), position.getX(), position.getY(), position.getZ(), Game.natives().toNative(item)); + EntityItem entityItem = new EntityItem(world(), position.getX(), position.getY(), position.getZ(), ItemConverter.instance().toNative(item)); world().spawnEntityInWorld(entityItem); return new BWEntity(entityItem); } @Override public Optional getEntity(String uniqueID) { - return Optional.ofNullable(Game.natives().toNova(world().getEntityByID(Integer.parseInt(uniqueID)))); + return Optional.ofNullable(world().getEntityByID(Integer.parseInt(uniqueID))).map(EntityConverter.instance()::toNova); } @Override diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/EntityConverter.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/EntityConverter.java index 909add8d2..999af8554 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/EntityConverter.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/EntityConverter.java @@ -35,6 +35,8 @@ import java.util.Optional; +import javax.annotation.Nonnull; + public class EntityConverter implements NativeConverter, ForgeLoadable { public static EntityConverter instance() { diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/forward/FWEntity.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/forward/FWEntity.java index d3e65a306..2bcac5420 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/forward/FWEntity.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/forward/FWEntity.java @@ -34,6 +34,7 @@ import nova.core.retention.Storable; import nova.core.util.shape.Cuboid; import nova.core.wrapper.mc.forge.v17.util.WrapperEvent; +import nova.core.wrapper.mc.forge.v17.wrapper.cuboid.CuboidConverter; import nova.core.wrapper.mc.forge.v17.wrapper.data.DataConverter; import nova.internal.core.Game; @@ -195,7 +196,7 @@ public void setPosition(double x, double y, double z) { this.posZ = z; //Reset the bounding box if (getBoundingBox() != null) { - setBounds(Game.natives().toNova(getBoundingBox())); + setBounds(CuboidConverter.instance().toNova(getBoundingBox())); } } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/forward/MCEntityTransform.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/forward/MCEntityTransform.java index 336dc050d..8e3835781 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/forward/MCEntityTransform.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/forward/MCEntityTransform.java @@ -27,6 +27,7 @@ import nova.core.util.math.RotationUtil; import nova.core.util.math.Vector3DUtil; import nova.core.world.World; +import nova.core.wrapper.mc.forge.v17.wrapper.block.world.WorldConverter; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Rotation; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -48,7 +49,7 @@ public MCEntityTransform(net.minecraft.entity.Entity wrapper) { @Override public World world() { - return Game.natives().toNova(wrapper.worldObj); + return WorldConverter.instance().toNova(wrapper.worldObj); } @Override diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/inventory/BWInventory.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/inventory/BWInventory.java index 4eb0894b1..50fd3db23 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/inventory/BWInventory.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/inventory/BWInventory.java @@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack; import nova.core.component.inventory.Inventory; import nova.core.item.Item; +import nova.core.wrapper.mc.forge.v17.wrapper.item.ItemConverter; import nova.internal.core.Game; import java.util.Optional; @@ -37,18 +38,12 @@ public BWInventory(IInventory mcInventory) { @Override public Optional get(int i) { - ItemStack stackInSlot = wrapped.getStackInSlot(i); - - if (stackInSlot == null) { - return Optional.empty(); - } - - return Optional.of(Game.natives().toNova(stackInSlot)); + return Optional.ofNullable(wrapped.getStackInSlot(i)).map(ItemConverter.instance()::toNova); } @Override public boolean set(int i, Item item) { - wrapped.setInventorySlotContents(i, Game.natives().toNative(item)); + wrapped.setInventorySlotContents(i, ItemConverter.instance().toNative(item)); return true; } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItemFactory.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItemFactory.java index c994ee58f..57d1c0bcd 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItemFactory.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItemFactory.java @@ -26,6 +26,7 @@ import nova.core.item.ItemFactory; import nova.core.retention.Data; import nova.core.wrapper.mc.forge.v17.util.WrapperEvent; +import nova.core.wrapper.mc.forge.v17.wrapper.data.DataConverter; import nova.internal.core.Game; /** @@ -60,7 +61,7 @@ public String getUnlocalizedName() { @Override public Item build(Data data) { int meta = (Integer) data.getOrDefault("damage", this.meta); - NBTTagCompound nbtData = Game.natives().toNative(data); + NBTTagCompound nbtData = DataConverter.instance().toNative(data); BWItem bwItem = new BWItem(item, meta, nbtData); bwItem.components.add(new FactoryProvider(this)); WrapperEvent.BWItemCreate event = new WrapperEvent.BWItemCreate(bwItem, item); @@ -76,7 +77,7 @@ public Data save(Item item) { BWItem mcItem = (BWItem) item; - Data result = mcItem.getTag() != null ? Game.natives().toNova(mcItem.getTag()) : new Data(); + Data result = mcItem.getTag() != null ? DataConverter.instance().toNova(mcItem.getTag()) : new Data(); if (result == null) { result = new Data(); } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemWrapperMethods.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemWrapperMethods.java index 9b9d80f55..7d043b9ce 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemWrapperMethods.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemWrapperMethods.java @@ -53,14 +53,15 @@ public interface ItemWrapperMethods extends IItemRenderer { ItemFactory getItemFactory(); + @SuppressWarnings({"unchecked", "rawtypes"}) default void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean p_77624_4_) { - Item item = Game.natives().toNova(itemStack); + Item item = ItemConverter.instance().toNova(itemStack); item.setCount(itemStack.stackSize).events.publish(new Item.TooltipEvent(Optional.of(new BWEntity(player)), list)); getItemFactory().save(item); } default boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - Item item = Game.natives().toNova(itemStack); + Item item = ItemConverter.instance().toNova(itemStack); Item.UseEvent event = new Item.UseEvent(new BWEntity(player), new Vector3D(x, y, z), Direction.fromOrdinal(side), new Vector3D(hitX, hitY, hitZ)); item.events.publish(event); ItemConverter.instance().updateMCItemStack(itemStack, item); @@ -68,7 +69,7 @@ default boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, } default ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { - Item item = Game.natives().toNova(itemStack); + Item item = ItemConverter.instance().toNova(itemStack); item.events.publish(new Item.RightClickEvent(new BWEntity(player))); return ItemConverter.instance().updateMCItemStack(itemStack, item); } @@ -93,7 +94,7 @@ default boolean shouldUseRenderHelper(IItemRenderer.ItemRenderType type, ItemSta @Override default void renderItem(IItemRenderer.ItemRenderType type, ItemStack itemStack, Object... data) { - Item item = Game.natives().toNova(itemStack); + Item item = ItemConverter.instance().toNova(itemStack); if (item.components.has(Renderer.class)) { GL11.glPushAttrib(GL_TEXTURE_BIT); GL11.glEnable(GL12.GL_RESCALE_NORMAL); @@ -111,7 +112,8 @@ default void renderItem(IItemRenderer.ItemRenderType type, ItemStack itemStack, } } + @SuppressWarnings("deprecation") default int getColorFromItemStack(ItemStack itemStack, int p_82790_2_) { - return ((Item) Game.natives().toNova(itemStack)).colorMultiplier().argb(); + return ItemConverter.instance().toNova(itemStack).colorMultiplier().argb(); } } diff --git a/minecraft/1.7/src/test/java/nova/core/wrapper/mc/forge/v17/wrapper/DirectionConverterTest.java b/minecraft/1.7/src/test/java/nova/core/wrapper/mc/forge/v17/wrapper/DirectionConverterTest.java index 67ab96e0b..0a08fa08f 100644 --- a/minecraft/1.7/src/test/java/nova/core/wrapper/mc/forge/v17/wrapper/DirectionConverterTest.java +++ b/minecraft/1.7/src/test/java/nova/core/wrapper/mc/forge/v17/wrapper/DirectionConverterTest.java @@ -27,7 +27,6 @@ import org.junit.Test; import static nova.testutils.NovaAssertions.assertThat; -import static org.assertj.core.api.Assertions.assertThat; /** * Used to test {@link DirectionConverter}. @@ -43,6 +42,12 @@ public void setUp() { converter = new DirectionConverter(); } + @Test + public void testClasses() { + assertThat(converter.getNovaSide()).isEqualTo(Direction.class); + assertThat(converter.getNativeSide()).isEqualTo(EnumFacing.class); + } + @Test public void testToNova() { assertThat(converter.toNova(EnumFacing.DOWN)).isEqualTo(Direction.DOWN); diff --git a/minecraft/1.7/src/test/java/nova/core/wrapper/mc/forge/v17/wrapper/assets/AssetConverterTest.java b/minecraft/1.7/src/test/java/nova/core/wrapper/mc/forge/v17/wrapper/assets/AssetConverterTest.java index c877ba423..c1c1c5089 100644 --- a/minecraft/1.7/src/test/java/nova/core/wrapper/mc/forge/v17/wrapper/assets/AssetConverterTest.java +++ b/minecraft/1.7/src/test/java/nova/core/wrapper/mc/forge/v17/wrapper/assets/AssetConverterTest.java @@ -21,11 +21,15 @@ package nova.core.wrapper.mc.forge.v17.wrapper.assets; import net.minecraft.util.ResourceLocation; +import nova.core.render.texture.BlockTexture; +import nova.core.render.texture.EntityTexture; +import nova.core.render.texture.ItemTexture; +import nova.core.render.texture.Texture; import nova.core.util.Asset; import org.junit.Before; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThat; +import static nova.testutils.NovaAssertions.assertThat; /** * Used to test {@link AssetConverter}. @@ -41,12 +45,21 @@ public void setUp() { converter = new AssetConverter(); } + @Test + public void testClasses() { + assertThat(converter.getNovaSide()).isEqualTo(Asset.class); + assertThat(converter.getNativeSide()).isEqualTo(ResourceLocation.class); + } + @Test public void testToNova() { assertThat(converter.toNova(new ResourceLocation("nova", "stuff"))).isEqualTo(new Asset("nova", "stuff")); assertThat(converter.toNova(new ResourceLocation("nova:otherStuff"))).isEqualTo(new Asset("nova", "otherStuff")); assertThat(converter.toNova(new ResourceLocation("nova:otherStuff"))).isEqualTo(new Asset("nova", "otherstuff")); // NOVA's Assets are entirely case-insensitive + assertThat(converter.toNovaTexture(new ResourceLocation("nova", "stuff"))).isEqualTo(new Texture("nova", "stuff")); + assertThat(converter.toNovaTexture(new ResourceLocation("nova:otherStuff"))).isEqualTo(new Texture("nova", "otherStuff")); + assertThat(converter.toNovaTexture(new ResourceLocation("nova:otherStuff"))).isEqualTo(new Texture("nova", "otherstuff")); } @Test @@ -55,5 +68,14 @@ public void testToNative() { assertThat(converter.toNative(new Asset("nova", "otherStuff"))).isNotEqualTo(new ResourceLocation("nova:otherstuff")); assertThat(converter.toNative(new Asset("nova", "otherStuff"))).isEqualTo(new ResourceLocation("nova:otherStuff")); // 1.8 ResourceLocation is partially case sensitive. 1.11 ResourceLocation is all lowercase. + assertThat(converter.toNativeTexture(new Asset("nova", "stuff"))).isEqualTo(new ResourceLocation("nova", "stuff")); + assertThat(converter.toNativeTexture(new Texture("nova", "otherStuff.png"))).isEqualTo(new ResourceLocation("nova:otherStuff")); + assertThat(converter.toNativeTexture(new Texture("nova", "otherStuff.png"), true)).isEqualTo(new ResourceLocation("nova:otherStuff.png")); + assertThat(converter.toNativeTexture(new BlockTexture("nova", "otherStuff.png"))).isEqualTo(new ResourceLocation("nova:otherStuff")); + assertThat(converter.toNativeTexture(new BlockTexture("nova", "otherStuff.png"), true)).isEqualTo(new ResourceLocation("nova:otherStuff.png")); + assertThat(converter.toNativeTexture(new ItemTexture("nova", "otherStuff.png"))).isEqualTo(new ResourceLocation("nova:otherStuff")); + assertThat(converter.toNativeTexture(new ItemTexture("nova", "otherStuff.png"), true)).isEqualTo(new ResourceLocation("nova:otherStuff.png")); + assertThat(converter.toNativeTexture(new EntityTexture("nova", "otherStuff.png"))).isEqualTo(new ResourceLocation("nova:../entities/otherStuff")); + assertThat(converter.toNativeTexture(new EntityTexture("nova", "otherStuff.png"), true)).isEqualTo(new ResourceLocation("nova:../entities/otherStuff.png")); } } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/ClientProxy.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/ClientProxy.java index eace4d8a5..e647cdef3 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/ClientProxy.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/ClientProxy.java @@ -47,12 +47,12 @@ import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWBlock; import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWTile; import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWTileRenderer; +import nova.core.wrapper.mc.forge.v18.wrapper.entity.EntityConverter; import nova.core.wrapper.mc.forge.v18.wrapper.entity.backward.BWEntityFX; import nova.core.wrapper.mc.forge.v18.wrapper.entity.forward.FWEntity; import nova.core.wrapper.mc.forge.v18.wrapper.entity.forward.FWEntityFX; import nova.core.wrapper.mc.forge.v18.wrapper.entity.forward.FWEntityRenderer; import nova.core.wrapper.mc.forge.v18.wrapper.item.FWItem; -import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import java.io.IOException; @@ -180,7 +180,7 @@ public Entity spawnParticle(net.minecraft.world.World world, EntityFactory facto if (build instanceof BWEntityFX) { EntityFX entityFX = ((BWEntityFX) build).createEntityFX(world); FMLClientHandler.instance().getClient().effectRenderer.addEffect(entityFX); - return Game.natives().toNova(entityFX); + return EntityConverter.instance().toNova(entityFX); } else { FWEntityFX bwEntityFX = new FWEntityFX(world, factory); FMLClientHandler.instance().getClient().effectRenderer.addEffect(bwEntityFX); @@ -198,7 +198,7 @@ public Entity spawnParticle(net.minecraft.world.World world, Entity entity) { entityFX.posY = position.getY(); entityFX.posZ = position.getZ(); FMLClientHandler.instance().getClient().effectRenderer.addEffect(entityFX); - return Game.natives().toNova(entityFX); + return EntityConverter.instance().toNova(entityFX); } else { FWEntityFX bwEntityFX = new FWEntityFX(world, entity); FMLClientHandler.instance().getClient().effectRenderer.addEffect(bwEntityFX); diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/FMLEventHandler.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/FMLEventHandler.java index 07314a310..f742b0362 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/FMLEventHandler.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/FMLEventHandler.java @@ -23,6 +23,7 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent; import nova.core.event.PlayerEvent; +import nova.core.wrapper.mc.forge.v18.wrapper.entity.EntityConverter; import nova.internal.core.Game; /** @@ -32,12 +33,12 @@ public class FMLEventHandler { @SubscribeEvent public void playerJoin(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent evt) { - Game.events().publish(new PlayerEvent.Join(Game.natives().toNova(evt.player))); + Game.events().publish(new PlayerEvent.Join(EntityConverter.instance().toNova(evt.player))); } @SubscribeEvent public void playerLeave(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedOutEvent evt) { - Game.events().publish(new PlayerEvent.Leave(Game.natives().toNova(evt.player))); + Game.events().publish(new PlayerEvent.Leave(EntityConverter.instance().toNova(evt.player))); } @SubscribeEvent diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/ForgeEventHandler.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/ForgeEventHandler.java index 172d8a6c7..fe12d68d4 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/ForgeEventHandler.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/launcher/ForgeEventHandler.java @@ -27,6 +27,9 @@ import net.minecraftforge.oredict.OreDictionary; import nova.core.item.Item; import nova.core.item.ItemDictionary; +import nova.core.wrapper.mc.forge.v18.wrapper.VectorConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.block.world.WorldConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.entity.EntityConverter; import nova.core.wrapper.mc.forge.v18.wrapper.item.ItemConverter; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -38,12 +41,12 @@ public class ForgeEventHandler { @SubscribeEvent public void worldUnload(WorldEvent.Load evt) { - Game.events().publish(new nova.core.event.WorldEvent.Load(Game.natives().toNova(evt.world))); + Game.events().publish(new nova.core.event.WorldEvent.Load(WorldConverter.instance().toNova(evt.world))); } @SubscribeEvent public void worldLoad(WorldEvent.Unload evt) { - Game.events().publish(new nova.core.event.WorldEvent.Unload(Game.natives().toNova(evt.world))); + Game.events().publish(new nova.core.event.WorldEvent.Unload(WorldConverter.instance().toNova(evt.world))); } @SubscribeEvent @@ -60,9 +63,9 @@ public void onOreRegister(OreDictionary.OreRegisterEvent event) { public void playerInteractEvent(PlayerInteractEvent event) { if (event.world != null && event.pos != null) { nova.core.event.PlayerEvent.Interact evt = new nova.core.event.PlayerEvent.Interact( - Game.natives().toNova(event.world), - new Vector3D(event.pos.getX(), event.pos.getY(), event.pos.getZ()), - Game.natives().toNova(event.entityPlayer), + WorldConverter.instance().toNova(event.world), + VectorConverter.instance().toNova(event.pos), + EntityConverter.instance().toNova(event.entityPlayer), nova.core.event.PlayerEvent.Interact.Action.values()[event.action.ordinal()] ); diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/manager/MCRetentionManager.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/manager/MCRetentionManager.java index 1c4778066..8be291465 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/manager/MCRetentionManager.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/manager/MCRetentionManager.java @@ -30,6 +30,7 @@ import nova.core.retention.Data; import nova.core.retention.Storable; import nova.core.util.registry.RetentionManager; +import nova.core.wrapper.mc.forge.v18.wrapper.data.DataConverter; import nova.internal.core.Game; import java.io.File; @@ -59,13 +60,13 @@ public void saveAll() { public void save(String filename, Storable storable) { Data saveMap = new Data(); storable.save(saveMap); - saveFile(filename, Game.natives().toNative(saveMap)); + saveFile(filename, DataConverter.instance().toNative(saveMap)); } @Override public void load(String filename, Storable storable) { NBTTagCompound nbt = loadFile(filename); - storable.load(Game.natives().toNova(nbt)); + storable.load(DataConverter.instance().toNova(nbt)); } /** @@ -76,7 +77,7 @@ public void load(String filename, Storable storable) { */ public boolean saveFile(File file, NBTTagCompound data) { try { - File tempFile = new File(file.getParent(), file.getName() + "_tmp.dat"); + File tempFile = new File(file.getParent(), file.getName().replaceFirst("\\.nbt$", ".tmp.nbt")); CompressedStreamTools.writeCompressed(data, new FileOutputStream(tempFile)); @@ -94,7 +95,7 @@ public boolean saveFile(File file, NBTTagCompound data) { } public boolean saveFile(File saveDirectory, String filename, NBTTagCompound data) { - return saveFile(new File(saveDirectory, filename + ".dat"), data); + return saveFile(new File(saveDirectory, filename + ".nbt"), data); } public boolean saveFile(String filename, NBTTagCompound data) { @@ -122,7 +123,7 @@ public NBTTagCompound loadFile(File file) { * @return The NBT data */ public NBTTagCompound loadFile(File saveDirectory, String filename) { - return loadFile(new File(saveDirectory, filename + ".dat")); + return loadFile(new File(saveDirectory, filename + ".nbt")); } public NBTTagCompound loadFile(String filename) { diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/network/discriminator/NovaPacket.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/network/discriminator/NovaPacket.java index e75f28cbe..6e6cceb02 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/network/discriminator/NovaPacket.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/network/discriminator/NovaPacket.java @@ -28,6 +28,7 @@ import nova.core.network.handler.PacketHandler; import nova.core.wrapper.mc.forge.v18.network.MCPacket; import nova.core.wrapper.mc.forge.v18.network.netty.MCNetworkManager; +import nova.core.wrapper.mc.forge.v18.wrapper.entity.EntityConverter; import nova.internal.core.Game; /** @@ -65,7 +66,7 @@ public void handle(EntityPlayer player) { MCNetworkManager network = (MCNetworkManager) Game.network(); PacketHandler packetHandler = network.getPacketType(data.readInt()); int subId = data.readInt(); - MCPacket packet = new MCPacket(data.slice(), ((Entity) Game.natives().toNova(player)).components.get(Player.class)); + MCPacket packet = new MCPacket(data.slice(), EntityConverter.instance().toNova(player).components.get(Player.class)); //Set the ID of the packet packet.setID(subId); packetHandler.read(packet); diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/VectorConverter.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/VectorConverter.java index a07048576..802de4f90 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/VectorConverter.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/VectorConverter.java @@ -21,6 +21,8 @@ package nova.core.wrapper.mc.forge.v18.wrapper; import net.minecraft.util.BlockPos; +import net.minecraft.util.Vec3; +import net.minecraft.util.Vec3i; import nova.core.nativewrapper.NativeConverter; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -43,6 +45,14 @@ public Class getNativeSide() { @Override public Vector3D toNova(BlockPos pos) { + return toNova((Vec3i) pos); + } + + public Vector3D toNova(Vec3 pos) { + return new Vector3D(pos.xCoord, pos.yCoord, pos.zCoord); + } + + public Vector3D toNova(Vec3i pos) { return new Vector3D(pos.getX(), pos.getY(), pos.getZ()); } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/BlockConverter.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/BlockConverter.java index 0bb95ca85..f40bef205 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/BlockConverter.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/BlockConverter.java @@ -121,8 +121,7 @@ private void registerNOVAToMinecraft() { public boolean canReplace() { return true; } - }, evt -> { - }); + }, evt -> {}); blockManager.register(airBlock); 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 63cca590d..a8c34fc54 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 @@ -50,6 +50,7 @@ import nova.core.wrapper.mc.forge.v18.wrapper.cuboid.CuboidConverter; import nova.core.wrapper.mc.forge.v18.wrapper.data.DataConverter; import nova.core.wrapper.mc.forge.v18.wrapper.entity.EntityConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.item.ItemConverter; import nova.core.wrapper.mc.forge.v18.wrapper.render.backward.BWBakedModel; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -73,9 +74,11 @@ 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)); - if (mcBlock.isReplaceable((net.minecraft.world.World) blockAccess(), new BlockPos(x(), y(), z()))) - components.add(BlockProperty.Replaceable.instance()); + components.add(new BlockProperty.Opacity()).setOpacity(() -> mcBlock.getMaterial().isOpaque() ? 1 : 0); + BlockProperty.Replaceable replaceable = components.add(new BlockProperty.Replaceable()); + if (block != Blocks.air) { + replaceable.setReplaceable(() -> mcBlock.canPlaceBlockAt((net.minecraft.world.World) blockAccess(), blockPos())); + } BlockProperty.BlockSound blockSound = components.add(new BlockProperty.BlockSound()); blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", mcBlock.stepSound.getPlaceSound())); @@ -137,7 +140,7 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) { @Override public ItemFactory getItemFactory() { - return Game.natives().toNova(new ItemStack(Item.getItemFromBlock(mcBlock))); + return ItemConverter.instance().toNova(new ItemStack(Item.getItemFromBlock(mcBlock))).getFactory(); } public net.minecraft.block.Block block() { @@ -163,18 +166,13 @@ public Optional getTileEntity() { return Optional.ofNullable(mcTileEntity); } - @Override - public boolean canReplace() { - return mcBlock.canPlaceBlockAt((net.minecraft.world.World) blockAccess(), new BlockPos(x(), y(), z())); - } - @Override public boolean shouldDisplacePlacement() { if (mcBlock == Blocks.snow_layer && ((int) blockState().getValue(BlockSnow.LAYERS) < 1)) { return false; } - if (mcBlock == Blocks.vine || mcBlock == Blocks.tallgrass || mcBlock == Blocks.deadbush || mcBlock.isReplaceable(Game.natives().toNative(world()), new BlockPos(x(), y(), z()))) { + if (mcBlock == Blocks.vine || mcBlock == Blocks.tallgrass || mcBlock == Blocks.deadbush || mcBlock.isReplaceable((net.minecraft.world.World) blockAccess(), blockPos())) { return false; } return super.shouldDisplacePlacement(); diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlockTransform.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlockTransform.java index eec63e592..7ccfa2781 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlockTransform.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/backward/BWBlockTransform.java @@ -23,12 +23,10 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.world.IBlockAccess; -import net.minecraft.world.chunk.Chunk; import nova.core.component.transform.BlockTransform; import nova.core.world.World; import nova.core.wrapper.mc.forge.v18.wrapper.VectorConverter; import nova.core.wrapper.mc.forge.v18.wrapper.block.world.WorldConverter; -import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import java.util.Optional; @@ -69,8 +67,8 @@ public IBlockAccess blockAccess() { @Override public void setWorld(World world) { BlockPos pos = blockPos(); - net.minecraft.world.World oldWorld = Game.natives().toNative(this.world); - net.minecraft.world.World newWorld = Game.natives().toNative(world); + net.minecraft.world.World oldWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world); + net.minecraft.world.World newWorld = (net.minecraft.world.World) WorldConverter.instance().toNative(world); Optional tileEntity = Optional.ofNullable(oldWorld.getTileEntity(pos)); Optional nbt = Optional.empty(); if (tileEntity.isPresent()) { @@ -92,7 +90,7 @@ public void setWorld(World world) { public void setPosition(Vector3D position) { BlockPos oldPos = blockPos(); BlockPos newPos = VectorConverter.instance().toNative(position); - net.minecraft.world.World world = Game.natives().toNative(this.world); + net.minecraft.world.World world = (net.minecraft.world.World) WorldConverter.instance().toNative(this.world); Optional tileEntity = Optional.ofNullable(blockAccess().getTileEntity(oldPos)); Optional nbt = Optional.empty(); if (tileEntity.isPresent()) { 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 4f49c0a89..1417d0e38 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 @@ -48,7 +48,12 @@ import nova.core.util.math.MathUtil; import nova.core.util.shape.Cuboid; import nova.core.wrapper.mc.forge.v18.util.WrapperEvent; +import nova.core.wrapper.mc.forge.v18.wrapper.DirectionConverter; import nova.core.wrapper.mc.forge.v18.wrapper.VectorConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.block.world.WorldConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.cuboid.CuboidConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.entity.EntityConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.item.ItemConverter; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -132,7 +137,7 @@ public Block getBlockInstance(IBlockAccess access, Vector3D position) { e.printStackTrace(); } } - return getBlockInstance((nova.core.world.World) Game.natives().toNova(access), position); + return getBlockInstance(WorldConverter.instance().toNova(access), position); } @@ -157,7 +162,7 @@ public void onBlockHarvested(World world, BlockPos pos, IBlockState state, Entit // hack is needed because the player sets the block to air *before* // getting the drops. woo good logic from mojang. if (!player.capabilities.isCreativeMode) { - harvestedBlocks.put(new BlockPosition(world, pos.getX(), pos.getY(), pos.getZ()), getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ()))); + harvestedBlocks.put(new BlockPosition(world, pos.getX(), pos.getY(), pos.getZ()), getBlockInstance(world, VectorConverter.instance().toNova(pos))); } } @@ -171,24 +176,24 @@ public List getDrops(IBlockAccess world, BlockPos pos, IBlockState st if (harvestedBlocks.containsKey(position)) { blockInstance = harvestedBlocks.remove(position); } else { - blockInstance = getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos)); } Block.DropEvent event = new Block.DropEvent(blockInstance); blockInstance.events.publish(event); - return new ArrayList<>( - event.drops - .stream() - .map(item -> (ItemStack) Game.natives().toNative(item)) - .collect(Collectors.toCollection(ArrayList::new)) - ); + return event.drops + .stream() + .map(ItemConverter.instance()::toNative) + .collect(Collectors.toCollection(ArrayList::new)); } @Override public boolean hasTileEntity(IBlockState state) { // A block requires a TileEntity if it stores data or if it ticks. - return Storable.class.isAssignableFrom(blockClass) || Stateful.class.isAssignableFrom(blockClass) || Updater.class.isAssignableFrom(blockClass); + return Storable.class.isAssignableFrom(blockClass) + || Stateful.class.isAssignableFrom(blockClass) + || Updater.class.isAssignableFrom(blockClass); } @Override @@ -214,7 +219,7 @@ public IBlockState getExtendedState(IBlockState state, IBlockAccess world, Block @Override public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, net.minecraft.block.Block neighborBlock) { - Block blockInstance = getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos)); // Minecraft does not provide the neighbor :( Block.NeighborChangeEvent evt = new Block.NeighborChangeEvent(Optional.empty()); blockInstance.events.publish(evt); @@ -222,8 +227,8 @@ public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, @Override public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, boolean willHarvest) { - Block blockInstance = getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); - Block.RemoveEvent evt = new Block.RemoveEvent(Optional.of(Game.natives().toNova(player))); + Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos)); + Block.RemoveEvent evt = new Block.RemoveEvent(Optional.of(EntityConverter.instance().toNova(player))); blockInstance.events.publish(evt); if (evt.result) { return super.removedByPlayer(world, pos, player, willHarvest); @@ -233,29 +238,29 @@ public boolean removedByPlayer(World world, BlockPos pos, EntityPlayer player, b @Override public void onBlockClicked(World world, BlockPos pos, EntityPlayer player) { - Block blockInstance = getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos)); MovingObjectPosition mop = player.rayTrace(10, 1); - Block.LeftClickEvent evt = new Block.LeftClickEvent(Game.natives().toNova(player), Direction.fromOrdinal(mop.sideHit.ordinal()), new Vector3D(mop.hitVec.xCoord, mop.hitVec.yCoord, mop.hitVec.zCoord)); + Block.LeftClickEvent evt = new Block.LeftClickEvent(EntityConverter.instance().toNova(player), DirectionConverter.instance().toNova(mop.sideHit), VectorConverter.instance().toNova(mop.hitVec)); blockInstance.events.publish(evt); } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ) { - Block blockInstance = getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); - Block.RightClickEvent evt = new Block.RightClickEvent(Game.natives().toNova(player), Direction.fromOrdinal(side.ordinal()), new Vector3D(hitX, hitY, hitZ)); + Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos)); + Block.RightClickEvent evt = new Block.RightClickEvent(EntityConverter.instance().toNova(player), DirectionConverter.instance().toNova(side), new Vector3D(hitX, hitY, hitZ)); blockInstance.events.publish(evt); return evt.result; } @Override public void onEntityCollidedWithBlock(World world, BlockPos pos, Entity entity) { - Block blockInstance = getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); - blockInstance.components.getOp(Collider.class).ifPresent(collider -> blockInstance.events.publish(new Collider.CollideEvent(Game.natives().toNova(entity)))); + Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos)); + blockInstance.components.getOp(Collider.class).ifPresent(collider -> blockInstance.events.publish(new Collider.CollideEvent(EntityConverter.instance().toNova(entity)))); } @Override public void setBlockBoundsBasedOnState(IBlockAccess access, BlockPos pos) { - Block blockInstance = getBlockInstance(access, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + Block blockInstance = getBlockInstance(access, VectorConverter.instance().toNova(pos)); if (blockInstance.components.has(Collider.class)) { Cuboid cuboid = blockInstance.components.get(Collider.class).boundingBox.get(); setBlockBounds((float) cuboid.min.getX(), (float) cuboid.min.getY(), (float) cuboid.min.getZ(), (float) cuboid.max.getX(), (float) cuboid.max.getY(), (float) cuboid.max.getZ()); @@ -264,28 +269,29 @@ public void setBlockBoundsBasedOnState(IBlockAccess access, BlockPos pos) { @Override public AxisAlignedBB getSelectedBoundingBox(World world, BlockPos pos) { - Block blockInstance = getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos)); if (blockInstance.components.has(Collider.class)) { Cuboid cuboid = blockInstance.components.get(Collider.class).boundingBox.get(); - return Game.natives().toNative(cuboid.add(new Vector3D(pos.getX(), pos.getY(), pos.getZ()))); + return CuboidConverter.instance().toNative(cuboid.add(VectorConverter.instance().toNova(pos))); } return super.getSelectedBoundingBox(world, pos); } @Override + @SuppressWarnings({"unchecked", "rawtypes"}) public void addCollisionBoxesToList(World world, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity entity) { - Block blockInstance = getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + Block blockInstance = getBlockInstance(world, VectorConverter.instance().toNova(pos)); blockInstance.components.getOp(Collider.class).ifPresent( collider -> { - Set boxes = collider.occlusionBoxes.apply(Optional.ofNullable(entity != null ? Game.natives().toNova(entity) : null)); + Set boxes = collider.occlusionBoxes.apply(Optional.ofNullable(entity != null ? EntityConverter.instance().toNova(entity) : null)); list.addAll( boxes .stream() - .map(c -> c.add(new Vector3D(pos.getX(), pos.getY(), pos.getZ()))) - .filter(c -> c.intersects((Cuboid) Game.natives().toNova(mask))) - .map(cuboid -> Game.natives().toNative(cuboid)) + .map(c -> c.add(VectorConverter.instance().toNova(pos))) + .filter(c -> c.intersects(CuboidConverter.instance().toNova(mask))) + .map(CuboidConverter.instance()::toNative) .collect(Collectors.toList()) ); } @@ -326,7 +332,7 @@ public boolean isFullCube() { @Override public int getLightValue(IBlockAccess access, BlockPos pos) { - Block blockInstance = getBlockInstance(access, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + Block blockInstance = getBlockInstance(access, VectorConverter.instance().toNova(pos)); Optional opEmitter = blockInstance.components.getOp(LightEmitter.class); if (opEmitter.isPresent()) { @@ -343,7 +349,7 @@ public EnumWorldBlockLayer getBlockLayer() { @Override public boolean canConnectRedstone(IBlockAccess access, BlockPos pos, EnumFacing side) { - Block blockInstance = getBlockInstance(access, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + Block blockInstance = getBlockInstance(access, VectorConverter.instance().toNova(pos)); WrapperEvent.RedstoneConnect event = new WrapperEvent.RedstoneConnect(blockInstance.world(), blockInstance.position(), Direction.fromOrdinal(side.ordinal())); Game.events().publish(event); return event.canConnect; @@ -351,7 +357,7 @@ public boolean canConnectRedstone(IBlockAccess access, BlockPos pos, EnumFacing @Override public int isProvidingWeakPower(IBlockAccess access, BlockPos pos, IBlockState state, EnumFacing side) { - Block blockInstance = getBlockInstance(access, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + Block blockInstance = getBlockInstance(access, VectorConverter.instance().toNova(pos)); WrapperEvent.WeakRedstone event = new WrapperEvent.WeakRedstone(blockInstance.world(), blockInstance.position(), Direction.fromOrdinal(side.ordinal())); Game.events().publish(event); return event.power; @@ -359,7 +365,7 @@ public int isProvidingWeakPower(IBlockAccess access, BlockPos pos, IBlockState s @Override public int isProvidingStrongPower(IBlockAccess access, BlockPos pos, IBlockState state, EnumFacing side) { - Block blockInstance = getBlockInstance(access, new Vector3D(pos.getX(), pos.getY(), pos.getZ())); + Block blockInstance = getBlockInstance(access, VectorConverter.instance().toNova(pos)); WrapperEvent.StrongRedstone event = new WrapperEvent.StrongRedstone(blockInstance.world(), blockInstance.position(), Direction.fromOrdinal(side.ordinal())); Game.events().publish(event); return event.power; @@ -378,11 +384,34 @@ public String getLocalizedName() { @Override public float getExplosionResistance(World world, BlockPos pos, Entity exploder, Explosion explosion) { // TODO: Maybe do something withPriority these parameters. - return (float) getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())).getResistance() * 30; + + // This number was calculated from the blast resistance of Stone, + // which requires exactly one cubic meter of TNT to get blown up. + // + // 1. During construction, the setResistance method is called + // on minecraft:stone with a value of 10. + // + // 2. The setResistance method multiplies that by 3 and assigns + // the result to the blockResistance instance variable. + // + // 3. Finally, the getExplosionResistance method divides the + // blockResistance instance variable by 5 and returns the result. + // + // From this we see that minecraft:stone’s final blast resistance is 6. + + return (float) getBlockInstance(world, VectorConverter.instance().toNova(pos)).getResistance() * 6; } @Override public float getBlockHardness(World world, BlockPos pos) { - return (float) getBlockInstance(world, new Vector3D(pos.getX(), pos.getY(), pos.getZ())).getHardness() * 2; + return (float) getBlockInstance(world, VectorConverter.instance().toNova(pos)).getHardness() * 2; + } + + @Override + public boolean isReplaceable(World world, BlockPos pos) { + return getBlockInstance(world, VectorConverter.instance().toNova(pos)) + .components.getOp(BlockProperty.Replaceable.class) + .filter(BlockProperty.Replaceable::isReplaceable) + .isPresent(); } } 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 812d5cd4e..072c8e599 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,3 +1,23 @@ +/* + * Copyright (c) 2016 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + package nova.core.wrapper.mc.forge.v18.wrapper.block.forward; import net.minecraft.block.Block; 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 df9f5a92f..f47888372 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 @@ -1,3 +1,23 @@ +/* + * Copyright (c) 2016 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + package nova.core.wrapper.mc.forge.v18.wrapper.block.forward; import net.minecraft.block.material.MapColor; @@ -17,6 +37,7 @@ public class ProxyMaterial extends Material { * Construct a new proxy material. * @param color The map color. * @param opacity The Opacity to use. + * @param replaceable If this block is replaceable. */ public ProxyMaterial(MapColor color, Optional opacity, Optional replaceable) { super(color); @@ -26,16 +47,16 @@ public ProxyMaterial(MapColor color, Optional opacity, Op @Override public boolean blocksLight() { - return opacity.isPresent() ? opacity.get().opacity == 1 : super.blocksLight(); + return opacity.isPresent() ? opacity.get().isOpaque() : super.blocksLight(); } @Override public boolean isOpaque() { - return opacity.isPresent() ? opacity.get().opacity == 1 : super.isOpaque(); + return opacity.isPresent() ? opacity.get().isOpaque() : super.isOpaque(); } @Override public boolean isReplaceable() { - return replaceable.isPresent() || super.isReplaceable(); + return replaceable.map(BlockProperty.Replaceable::isReplaceable).orElseGet(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 55f45756b..766fbac7e 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 @@ -35,14 +35,19 @@ import nova.core.util.shape.Cuboid; import nova.core.world.World; import nova.core.wrapper.mc.forge.v18.launcher.NovaMinecraft; +import nova.core.wrapper.mc.forge.v18.wrapper.VectorConverter; +import nova.core.wrapper.mc.forge.v18.wrapper.block.BlockConverter; import nova.core.wrapper.mc.forge.v18.wrapper.block.backward.BWBlock; import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.FWBlock; import nova.core.wrapper.mc.forge.v18.wrapper.block.forward.MCBlockTransform; +import nova.core.wrapper.mc.forge.v18.wrapper.entity.EntityConverter; import nova.core.wrapper.mc.forge.v18.wrapper.entity.forward.FWEntity; import nova.core.wrapper.mc.forge.v18.wrapper.entity.forward.MCEntityTransform; +import nova.core.wrapper.mc.forge.v18.wrapper.item.ItemConverter; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; +import java.util.List; import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; @@ -96,9 +101,8 @@ public Optional getBlock(Vector3D position) { @Override public boolean setBlock(Vector3D position, BlockFactory blockFactory) { - //TODO: Do not call blockFactory.build() - net.minecraft.block.Block mcBlock = Game.natives().toNative(blockFactory.build()); - BlockPos pos = new BlockPos((int) position.getX(), (int) position.getY(), (int) position.getZ()); + net.minecraft.block.Block mcBlock = BlockConverter.instance().toNative(blockFactory); + BlockPos pos = VectorConverter.instance().toNative(position); net.minecraft.block.Block actualBlock = mcBlock != null ? mcBlock : Blocks.air; IBlockState defaultState = actualBlock.getDefaultState(); IBlockState extendedState = actualBlock.getExtendedState(defaultState, world(), pos); @@ -124,6 +128,7 @@ public Entity addClientEntity(EntityFactory factory) { } @Override + @SuppressWarnings("unchecked") public Entity addClientEntity(Entity entity) { return NovaMinecraft.proxy.spawnParticle(world(), entity); } @@ -136,24 +141,24 @@ public void removeEntity(Entity entity) { } @Override + @SuppressWarnings("unchecked") public Set getEntities(Cuboid bound) { - return (Set) world() - .getEntitiesWithinAABB(net.minecraft.entity.Entity.class, AxisAlignedBB.fromBounds(bound.min.getX(), bound.min.getY(), bound.min.getZ(), bound.max.getX(), bound.max.getY(), bound.max.getZ())) + return ((List) world().getEntitiesWithinAABB(net.minecraft.entity.Entity.class, AxisAlignedBB.fromBounds(bound.min.getX(), bound.min.getY(), bound.min.getZ(), bound.max.getX(), bound.max.getY(), bound.max.getZ()))) .stream() - .map(mcEnt -> Game.natives().getNative(Entity.class, net.minecraft.entity.Entity.class).toNova((net.minecraft.entity.Entity) mcEnt)) + .map(EntityConverter.instance()::toNova) .collect(Collectors.toSet()); } @Override public Entity addEntity(Vector3D position, Item item) { - EntityItem entityItem = new EntityItem(world(), position.getX(), position.getY(), position.getZ(), Game.natives().toNative(item)); + EntityItem entityItem = new EntityItem(world(), position.getX(), position.getY(), position.getZ(), ItemConverter.instance().toNative(item)); world().spawnEntityInWorld(entityItem); - return Game.natives().toNova(entityItem); + return EntityConverter.instance().toNova(entityItem); } @Override public Optional getEntity(String uniqueID) { - return Optional.ofNullable(Game.natives().toNova(world().getEntityByID(Integer.parseInt(uniqueID)))); + return Optional.ofNullable(world().getEntityByID(Integer.parseInt(uniqueID))).map(EntityConverter.instance()::toNova); } @Override diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/forward/FWEntity.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/forward/FWEntity.java index 3d813571e..0a72773ad 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/forward/FWEntity.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/forward/FWEntity.java @@ -34,6 +34,7 @@ import nova.core.retention.Storable; import nova.core.util.shape.Cuboid; import nova.core.wrapper.mc.forge.v18.util.WrapperEvent; +import nova.core.wrapper.mc.forge.v18.wrapper.cuboid.CuboidConverter; import nova.core.wrapper.mc.forge.v18.wrapper.data.DataConverter; import nova.internal.core.Game; @@ -196,7 +197,7 @@ public void setPosition(double x, double y, double z) { this.posZ = z; //Reset the bounding box if (getBoundingBox() != null) { - setBounds(Game.natives().toNova(getBoundingBox())); + setBounds(CuboidConverter.instance().toNova(getBoundingBox())); } } @@ -207,7 +208,7 @@ public void setPosition(double x, double y, double z) { public void setBounds(Cuboid bounds) { //TODO: Fix moveEntity auto-centering if (transform != null) { - setEntityBoundingBox(Game.natives().toNative(bounds.add(transform.position()))); + setEntityBoundingBox(CuboidConverter.instance().toNative(bounds.add(transform.position()))); } } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/forward/MCEntityTransform.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/forward/MCEntityTransform.java index 99919b400..0fc8e5469 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/forward/MCEntityTransform.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/forward/MCEntityTransform.java @@ -27,7 +27,7 @@ import nova.core.util.math.RotationUtil; import nova.core.util.math.Vector3DUtil; import nova.core.world.World; -import nova.internal.core.Game; +import nova.core.wrapper.mc.forge.v18.wrapper.block.world.WorldConverter; import org.apache.commons.math3.geometry.euclidean.threed.Rotation; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -48,7 +48,7 @@ public MCEntityTransform(net.minecraft.entity.Entity wrapper) { @Override public World world() { - return Game.natives().toNova(wrapper.worldObj); + return WorldConverter.instance().toNova(wrapper.worldObj); } @Override diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/inventory/BWInventory.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/inventory/BWInventory.java index 6f077b70f..53a57f887 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/inventory/BWInventory.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/inventory/BWInventory.java @@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack; import nova.core.component.inventory.Inventory; import nova.core.item.Item; +import nova.core.wrapper.mc.forge.v18.wrapper.item.ItemConverter; import nova.internal.core.Game; import java.util.Optional; @@ -37,18 +38,12 @@ public BWInventory(IInventory mcInventory) { @Override public Optional get(int i) { - ItemStack stackInSlot = wrapped.getStackInSlot(i); - - if (stackInSlot == null) { - return Optional.empty(); - } - - return Optional.of(Game.natives().toNova(stackInSlot)); + return Optional.ofNullable(wrapped.getStackInSlot(i)).map(ItemConverter.instance()::toNova); } @Override public boolean set(int i, Item item) { - wrapped.setInventorySlotContents(i, Game.natives().toNative(item)); + wrapped.setInventorySlotContents(i, ItemConverter.instance().toNative(item)); return true; } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/BWItemFactory.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/BWItemFactory.java index 43f8c822c..9c8b5c0af 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/BWItemFactory.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/BWItemFactory.java @@ -26,6 +26,7 @@ import nova.core.item.ItemFactory; import nova.core.retention.Data; import nova.core.wrapper.mc.forge.v18.util.WrapperEvent; +import nova.core.wrapper.mc.forge.v18.wrapper.data.DataConverter; import nova.internal.core.Game; /** @@ -60,7 +61,7 @@ public String getUnlocalizedName() { @Override public Item build(Data data) { int meta = (Integer) data.getOrDefault("damage", this.meta); - NBTTagCompound nbtData = Game.natives().toNative(data); + NBTTagCompound nbtData = DataConverter.instance().toNative(data); BWItem bwItem = new BWItem(item, meta, nbtData); bwItem.components.add(new FactoryProvider(this)); WrapperEvent.BWItemCreate event = new WrapperEvent.BWItemCreate(bwItem, item); @@ -76,7 +77,7 @@ public Data save(Item item) { BWItem mcItem = (BWItem) item; - Data result = mcItem.getTag() != null ? Game.natives().toNova(mcItem.getTag()) : new Data(); + Data result = mcItem.getTag() != null ? DataConverter.instance().toNova(mcItem.getTag()) : new Data(); if (result == null) { result = new Data(); } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/ItemWrapperMethods.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/ItemWrapperMethods.java index 9ae26ea0b..62434be0b 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/ItemWrapperMethods.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/ItemWrapperMethods.java @@ -41,14 +41,15 @@ public interface ItemWrapperMethods { ItemFactory getItemFactory(); + @SuppressWarnings({"unchecked", "rawtypes"}) default void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean p_77624_4_) { - Item item = Game.natives().toNova(itemStack); + Item item = ItemConverter.instance().toNova(itemStack); item.setCount(itemStack.stackSize).events.publish(new Item.TooltipEvent(Optional.of(new BWEntity(player)), list)); getItemFactory().save(item); } default boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int side, float hitX, float hitY, float hitZ) { - Item item = Game.natives().toNova(itemStack); + Item item = ItemConverter.instance().toNova(itemStack); Item.UseEvent event = new Item.UseEvent(new BWEntity(player), new Vector3D(x, y, z), Direction.fromOrdinal(side), new Vector3D(hitX, hitY, hitZ)); item.events.publish(event); ItemConverter.instance().updateMCItemStack(itemStack, item); @@ -56,12 +57,13 @@ default boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, } default ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { - Item item = Game.natives().toNova(itemStack); + Item item = ItemConverter.instance().toNova(itemStack); item.events.publish(new Item.RightClickEvent(new BWEntity(player))); return ItemConverter.instance().updateMCItemStack(itemStack, item); } + @SuppressWarnings("deprecation") default int getColorFromItemStack(ItemStack itemStack, int p_82790_2_) { - return ((Item) Game.natives().toNova(itemStack)).colorMultiplier().argb(); + return ItemConverter.instance().toNova(itemStack).colorMultiplier().argb(); } } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/backward/BWBakedModel.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/backward/BWBakedModel.java index 53896e693..38e89a224 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/backward/BWBakedModel.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/render/backward/BWBakedModel.java @@ -37,8 +37,8 @@ import nova.core.util.math.MatrixStack; import nova.core.util.math.TransformUtil; import nova.core.util.math.Vector3DUtil; +import nova.core.wrapper.mc.forge.v18.wrapper.DirectionConverter; import nova.core.wrapper.mc.forge.v18.wrapper.assets.AssetConverter; -import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; import org.apache.commons.math3.linear.LUDecomposition; @@ -48,7 +48,6 @@ import java.util.Arrays; import java.util.Collection; import java.util.HashSet; -import java.util.LinkedList; import java.util.List; import java.util.Optional; import java.util.Set; @@ -124,7 +123,7 @@ public Set flatten(MatrixStack matrixStack) { public List getFaceQuads(Direction direction) { if (direction == Direction.UNKNOWN) return getGeneralQuads(); - return getFaceQuads((EnumFacing) Game.natives().toNative(direction)); + return getFaceQuads(DirectionConverter.instance().toNative(direction)); } @SuppressWarnings("unchecked") diff --git a/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/DirectionConverterTest.java b/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/DirectionConverterTest.java index a9aa8ce7f..cc9c550ba 100644 --- a/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/DirectionConverterTest.java +++ b/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/DirectionConverterTest.java @@ -26,7 +26,6 @@ import org.junit.Test; import static nova.testutils.NovaAssertions.assertThat; -import static org.assertj.core.api.Assertions.assertThat; /** * Used to test {@link DirectionConverter}. @@ -42,6 +41,12 @@ public void setUp() { converter = new DirectionConverter(); } + @Test + public void testClasses() { + assertThat(converter.getNovaSide()).isEqualTo(Direction.class); + assertThat(converter.getNativeSide()).isEqualTo(EnumFacing.class); + } + @Test public void testToNova() { assertThat(converter.toNova(EnumFacing.DOWN)).isEqualTo(Direction.DOWN); diff --git a/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/VectorConverterTest.java b/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/VectorConverterTest.java index 6b24c62dd..88c68d734 100644 --- a/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/VectorConverterTest.java +++ b/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/VectorConverterTest.java @@ -21,6 +21,7 @@ package nova.core.wrapper.mc.forge.v18.wrapper; import net.minecraft.util.BlockPos; +import net.minecraft.util.Vec3; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.junit.Before; import org.junit.Test; @@ -41,12 +42,23 @@ public void setUp() { converter = new VectorConverter(); } + @Test + public void testClasses() { + assertThat(converter.getNovaSide()).isEqualTo(Vector3D.class); + assertThat(converter.getNativeSide()).isEqualTo(BlockPos.class); + } + @Test public void testToNova() { for (int x = -1; x <= 1; x++) for (int y = -1; y <= 1; y++) for (int z = -1; z <= 1; z++) assertThat(converter.toNova(new BlockPos(x, y, z))).isEqualTo(new Vector3D(x, y, z)); + + for (int x = -1; x <= 1; x++) + for (int y = -1; y <= 1; y++) + for (int z = -1; z <= 1; z++) + assertThat(converter.toNova(new Vec3(x, y, z))).isEqualTo(new Vector3D(x, y, z)); } @Test diff --git a/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/assets/AssetConverterTest.java b/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/assets/AssetConverterTest.java index 81bdf677e..24a7a04cb 100644 --- a/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/assets/AssetConverterTest.java +++ b/minecraft/1.8/src/test/java/nova/core/wrapper/mc/forge/v18/wrapper/assets/AssetConverterTest.java @@ -21,10 +21,12 @@ package nova.core.wrapper.mc.forge.v18.wrapper.assets; import net.minecraft.util.ResourceLocation; +import nova.core.render.texture.Texture; import nova.core.util.Asset; import org.junit.Before; import org.junit.Test; +import static nova.testutils.NovaAssertions.assertThat; import static org.assertj.core.api.Assertions.assertThat; /** @@ -41,12 +43,21 @@ public void setUp() { converter = new AssetConverter(); } + @Test + public void testClasses() { + assertThat(converter.getNovaSide()).isEqualTo(Asset.class); + assertThat(converter.getNativeSide()).isEqualTo(ResourceLocation.class); + } + @Test public void testToNova() { assertThat(converter.toNova(new ResourceLocation("nova", "stuff"))).isEqualTo(new Asset("nova", "stuff")); assertThat(converter.toNova(new ResourceLocation("nova:otherStuff"))).isEqualTo(new Asset("nova", "otherStuff")); assertThat(converter.toNova(new ResourceLocation("nova:otherStuff"))).isEqualTo(new Asset("nova", "otherstuff")); // NOVA's Assets are entirely case-insensitive + assertThat(converter.toNovaTexture(new ResourceLocation("nova", "stuff"))).isEqualTo(new Texture("nova", "stuff")); + assertThat(converter.toNovaTexture(new ResourceLocation("nova:otherStuff"))).isEqualTo(new Texture("nova", "otherStuff")); + assertThat(converter.toNovaTexture(new ResourceLocation("nova:otherStuff"))).isEqualTo(new Texture("nova", "otherstuff")); } @Test @@ -55,5 +66,8 @@ public void testToNative() { assertThat(converter.toNative(new Asset("nova", "otherStuff"))).isNotEqualTo(new ResourceLocation("nova:otherstuff")); assertThat(converter.toNative(new Asset("nova", "otherStuff"))).isEqualTo(new ResourceLocation("nova:otherStuff")); // 1.8 ResourceLocation is partially case sensitive. 1.11 ResourceLocation is all lowercase. + assertThat(converter.toNativeTexture(new Asset("nova", "stuff"))).isEqualTo(new ResourceLocation("nova", "stuff")); + assertThat(converter.toNativeTexture(new Texture("nova", "otherStuff.png"))).isEqualTo(new ResourceLocation("nova:otherStuff")); + assertThat(converter.toNativeTexture(new Texture("nova", "otherStuff.png"), true)).isEqualTo(new ResourceLocation("nova:otherStuff.png")); } } diff --git a/src/main/java/nova/core/block/Block.java b/src/main/java/nova/core/block/Block.java index 682089c6b..59e8b1e80 100644 --- a/src/main/java/nova/core/block/Block.java +++ b/src/main/java/nova/core/block/Block.java @@ -160,7 +160,7 @@ public double getResistance() { * @return True if this block can be replaced. */ public boolean canReplace() { - return false; + return components.getOp(BlockProperty.Replaceable.class).filter(BlockProperty.Replaceable::isReplaceable).isPresent(); } /** diff --git a/src/main/java/nova/core/block/component/BlockProperty.java b/src/main/java/nova/core/block/component/BlockProperty.java index 4999d1088..766368bd1 100644 --- a/src/main/java/nova/core/block/component/BlockProperty.java +++ b/src/main/java/nova/core/block/component/BlockProperty.java @@ -1,13 +1,36 @@ +/* + * Copyright (c) 2016 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + package nova.core.block.component; import nova.core.component.Component; import nova.core.component.SidedComponent; import nova.core.component.UnsidedComponent; import nova.core.sound.Sound; +import nova.core.util.math.MathUtil; import java.util.HashMap; import java.util.Map; import java.util.Optional; +import java.util.function.BooleanSupplier; +import java.util.function.DoubleSupplier; /** * Block properties. @@ -19,12 +42,12 @@ public interface BlockProperty { * The breaking difficulty of a block, or how long it takes to break a block. * Tools and armour may make the block break faster or slower than this. *

- * The standard, regular block hardness is 1. {@code Double.POSITIVE_INFINITY} is unbreakable. + * The standard, regular block hardness is 1. {@link Double#POSITIVE_INFINITY} is unbreakable. *

*/ @UnsidedComponent public static class Hardness extends Component implements BlockProperty { - private double hardness = 1.0; + private DoubleSupplier hardness = () -> 1; /** * Sets the breaking difficulty. @@ -32,49 +55,72 @@ 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(); } } /** - * The blast resistance of a block. + * The blast resistance of a block, indicates how many cubic meters of TNT are needed to explode it. *

* The standard, regular block resistance is 1. {@link Double#POSITIVE_INFINITY} is unexplodable. *

*/ @UnsidedComponent public static class Resistance extends Component implements BlockProperty { - private double resistance = 1.0; + private DoubleSupplier resistance = () -> 1; /** - * Sets the blast resistance + * Sets the blast resistance, indicates how many cubic meters + * of TNT are needed to explode it. * * @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; } /** - * Gets the blast resistance. + * Sets the blast resistance, indicates how many cubic meters + * of TNT are needed to explode it. + * + * @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, indicates how many cubic meters + * of TNT are needed to explode it. * * @return The blast resistance. */ public double getResistance() { - return resistance; + return resistance.getAsDouble(); } } @@ -152,11 +198,15 @@ public enum BlockSoundTrigger { * @author winsock */ @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. */ - public double opacity = 1; + private DoubleSupplier opacity = OPAQUE; /** * Sets that the block should allow light through @@ -164,7 +214,17 @@ public static class Opacity extends Component implements BlockProperty { * @return This instance for chaining if desired. */ public Opacity setTransparent() { - opacity = 0; + opacity = TRANSPARENT; + return this; + } + + /** + * Sets that the block should disallow light through + * + * @return This instance for chaining if desired. + */ + public Opacity setOpaque() { + opacity = OPAQUE; return this; } @@ -174,39 +234,78 @@ public Opacity setTransparent() { * @param opacity The block's opacity * @return This instance for chaining if desired. */ - public Opacity setOpacity(double opacity) { + 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 MathUtil.clamp(opacity.getAsDouble(), 0, 1); + } + + /** + * Checks if the block should allow light through + * + * @return If the block should allow light through + */ + public boolean isTransparent() { + return getOpacity() < 1; + } + + /** + * Checks if the block should disallow light through + * + * @return If the block should disallow light through + */ + public boolean isOpaque() { + return getOpacity() == 1; + } } /** * Indicates whether the block is replaceable. + * + * @author ExE Boss */ @UnsidedComponent - public static final class Replaceable extends Component implements BlockProperty { - private static final Replaceable instance = new Replaceable(); + public static class Replaceable extends Component implements BlockProperty { + private BooleanSupplier replaceable = () -> true; + + public Replaceable() {} /** - * Gets the singleton for Replaceable. + * Set the boolean supplier that is used to check if this block is replaceable. * - * @return The singleton for Replaceable. + * @param replaceable The replacement boolean supplier. + * @return This instance for chaining if desired. */ - public static Replaceable instance() { - return instance; - } - - private Replaceable() { - } - - @Override - public boolean equals(Object o) { - return this == o || o instanceof Replaceable; + public Replaceable setReplaceable(BooleanSupplier replaceable) { + this.replaceable = replaceable; + return this; } - @Override - public int hashCode() { - return Replaceable.class.hashCode(); + /** + * Check if this block can be replaced. + * + * @return if this block can be replaced. + */ + public boolean isReplaceable() { + return this.replaceable.getAsBoolean(); } } } diff --git a/src/main/java/nova/core/nativewrapper/NativeConverter.java b/src/main/java/nova/core/nativewrapper/NativeConverter.java index 9d7452f2f..83e75eaaa 100644 --- a/src/main/java/nova/core/nativewrapper/NativeConverter.java +++ b/src/main/java/nova/core/nativewrapper/NativeConverter.java @@ -26,13 +26,38 @@ * Implementing a Loadable on a NativeConverter will allow it to handle loading events. * * @author TheSandromatic, Calclavia + * @param The NOVA implementation class. + * @param The game implementation class. */ public interface NativeConverter { + + /** + * Get the class of the NOVA implementation. + * + * @return The class of the NOVA implementation. + */ Class getNovaSide(); + /** + * Get the class of the game implementation. + * + * @return The class of the game implementation. + */ Class getNativeSide(); + /** + * Convert a game implementation object to the NOVA equivalent. + * + * @param nativeObj A game implementation object. + * @return The NOVA equivalent object. + */ NOVA toNova(NATIVE nativeObj); + /** + * Convert a NOVA implementation object to the game equivalent. + * + * @param novaObj A NOVA implementation object. + * @return The game equivalent object. + */ NATIVE toNative(NOVA novaObj); } diff --git a/src/main/java/nova/core/nativewrapper/NativeManager.java b/src/main/java/nova/core/nativewrapper/NativeManager.java index c241a4129..df844740f 100644 --- a/src/main/java/nova/core/nativewrapper/NativeManager.java +++ b/src/main/java/nova/core/nativewrapper/NativeManager.java @@ -16,7 +16,9 @@ * * You should have received a copy of the GNU General Public License * along with NOVA. If not, see . - */package nova.core.nativewrapper; + */ + +package nova.core.nativewrapper; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; @@ -49,8 +51,10 @@ public class NativeManager { /** * Registers a component to a native interface. - * @param component A component. Must extend INTERFACE. - * @param nativeInterface the class of the INTERFACE. + * + * @param The interface of the component. + * @param component A component. Must extend {@code INTERFACE}. + * @param nativeInterface the class of the {@code INTERFACE}. */ public void registerComponentToInterface(Class component, Class nativeInterface) { novaComponentToNativeInterface.put(component, nativeInterface); @@ -107,6 +111,9 @@ private > CONVERTE /** * Converts a native object to a nova object. This method has autocast, is DANGEROUS and may crash. + * + * @param nativeObject A game implementation object. + * @return The NOVA equivalent object. */ public T toNova(Object nativeObject) { Objects.requireNonNull(nativeObject); @@ -120,6 +127,9 @@ public T toNova(Object nativeObject) { /** * Converts a nova object to a native object. This method has autocast, is DANGEROUS and may crash. + * + * @param novaObject A NOVA implementation object. + * @return The game equivalent object. */ public T toNative(Object novaObject) { Objects.requireNonNull(novaObject); @@ -136,6 +146,8 @@ public T toNative(Object novaObject) { } public static class NativeException extends NovaException { + private static final long serialVersionUID = 1L; + public NativeException() { super(); } diff --git a/src/test/java/nova/core/block/component/BlockPropertyTest.java b/src/test/java/nova/core/block/component/BlockPropertyTest.java new file mode 100644 index 000000000..ced3e6c1b --- /dev/null +++ b/src/test/java/nova/core/block/component/BlockPropertyTest.java @@ -0,0 +1,103 @@ +/* + * Copyright (c) 2017 NOVA, All rights reserved. + * This library is free software, licensed under GNU Lesser General Public License version 3 + * + * This file is part of NOVA. + * + * NOVA is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * NOVA is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with NOVA. If not, see . + */ + +package nova.core.block.component; + +import nova.core.sound.Sound; +import org.junit.Test; + +import static nova.testutils.NovaAssertions.assertThat; + +/** + * @author ExE Boss + */ +public class BlockPropertyTest { + + @Test + public void testHardness() { + 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(); + assertThat(resistance.getResistance()).isEqualTo(1.0); + + resistance.setResistance(10.0); + assertThat(resistance.getResistance()).isEqualTo(10.0); + } + + @Test + public void testBlockSound() { + BlockProperty.BlockSound sound = new BlockProperty.BlockSound(); + sound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("test", "break")); + sound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("test", "place")); + sound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("test", "walk")); + sound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.CUSTOM_TRIGGER, new Sound("test", "custom")); + sound.setCustomBlockSound("test:custom", new Sound("test", "custom")); + + assertThat(sound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK)).contains(new Sound("test", "break")); + assertThat(sound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE)).contains(new Sound("test", "place")); + assertThat(sound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK)).contains(new Sound("test", "walk")); + assertThat(sound.getSound(BlockProperty.BlockSound.BlockSoundTrigger.CUSTOM_TRIGGER)).isEmpty(); + assertThat(sound.getCustomSound("test:custom")).contains(new Sound("test", "custom")); + } + + @Test + public void testOpacity() { + BlockProperty.Opacity opacity = new BlockProperty.Opacity().setOpaque(); + assertThat(opacity.getOpacity()).isEqualTo(1.0); + assertThat(opacity.isOpaque()).isTrue(); + assertThat(opacity.isTransparent()).isFalse(); + + opacity.setTransparent(); + assertThat(opacity.getOpacity()).isEqualTo(0.0); + assertThat(opacity.isOpaque()).isFalse(); + assertThat(opacity.isTransparent()).isTrue(); + + opacity.setOpacity(0.5); + 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 + public void testReplaceable() { + BlockProperty.Replaceable replaceable = new BlockProperty.Replaceable(); + assertThat(replaceable.isReplaceable()).isTrue(); + + replaceable.setReplaceable(() -> false); + assertThat(replaceable.isReplaceable()).isFalse(); + } +}