From 0f0a06ebe10606ef792724cf8e6811d28f57d6d6 Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Wed, 11 Jan 2017 03:00:52 +0100 Subject: [PATCH] Remove dependency on #227 (Part 1: Revert "String -> Identifier. WIP.") This reverts commit 5e56559d932bca50a691d69bf6e7b545825dfaac. # Conflicts: # minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/block/BlockConverter.java # minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemConverter.java # minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/BlockConverter.java # minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/ItemConverter.java # src/main/java/nova/core/util/registry/Factory.java --- .../v17/recipes/MinecraftItemIngredient.java | 2 +- .../mc/forge/v17/recipes/RecipeConverter.java | 2 +- .../v17/wrapper/block/BlockConverter.java | 5 +- .../v17/wrapper/block/forward/FWBlock.java | 4 +- .../v17/wrapper/block/world/BWWorld.java | 8 +-- .../v17/wrapper/entity/backward/BWEntity.java | 6 +- .../v17/wrapper/entity/forward/FWEntity.java | 4 +- .../mc/forge/v17/wrapper/item/BWItem.java | 2 +- .../mc/forge/v17/wrapper/item/FWItem.java | 2 +- .../forge/v17/wrapper/item/ItemConverter.java | 12 ++-- .../v18/recipes/MinecraftItemIngredient.java | 2 +- .../mc/forge/v18/recipes/RecipeConverter.java | 2 +- .../v18/wrapper/block/BlockConverter.java | 4 +- .../v18/wrapper/block/forward/FWBlock.java | 4 +- .../wrapper/block/forward/FWBlockSound.java | 6 +- .../v18/wrapper/block/world/BWWorld.java | 8 +-- .../v18/wrapper/entity/backward/BWEntity.java | 6 +- .../v18/wrapper/entity/forward/FWEntity.java | 4 +- .../mc/forge/v18/wrapper/item/BWItem.java | 2 +- .../mc/forge/v18/wrapper/item/FWItem.java | 2 +- .../forge/v18/wrapper/item/ItemConverter.java | 13 +++-- src/main/java/nova/core/block/Block.java | 5 +- .../java/nova/core/component/Category.java | 8 +-- .../java/nova/core/component/Component.java | 8 +-- .../java/nova/core/component/fluid/Fluid.java | 10 ++-- .../nova/core/component/misc/Damageable.java | 8 +-- src/main/java/nova/core/entity/Entity.java | 10 ++-- src/main/java/nova/core/item/Item.java | 5 +- src/main/java/nova/core/item/ItemFactory.java | 2 +- src/main/java/nova/core/item/ItemManager.java | 4 +- src/main/java/nova/core/network/Packet.java | 55 ++----------------- .../crafting/CraftingRecipeManager.java | 4 +- .../recipes/crafting/OreItemIngredient.java | 3 +- src/main/java/nova/core/render/Asset.java | 8 +-- .../java/nova/core/render/RenderManager.java | 8 +-- .../nova/core/render/texture/Texture.java | 8 +-- src/main/java/nova/core/retention/Data.java | 36 ++---------- .../java/nova/core/retention/Storable.java | 6 +- src/main/java/nova/core/sound/Sound.java | 2 +- .../nova/core/util/{id => }/Identifiable.java | 4 +- .../util/{id => }/UniqueIdentifiable.java | 6 +- .../nova/core/util/id/AbstractIdentifier.java | 46 ---------------- .../nova/core/util/id/ClassIdentifier.java | 32 ----------- .../java/nova/core/util/id/Identifier.java | 19 ------- .../nova/core/util/id/StringIdentifier.java | 18 ------ .../nova/core/util/id/UUIDIdentifier.java | 29 ---------- .../java/nova/core/util/registry/Factory.java | 8 +-- .../core/util/registry/FactoryManager.java | 2 +- .../nova/core/util/registry/Registry.java | 6 +- src/main/java/nova/core/world/World.java | 2 +- .../java/nova/core/util/MockIdentifiable.java | 10 +--- .../java/nova/core/util/RegistryTest.java | 6 +- src/test/java/nova/testutils/FakeWorld.java | 6 +- 53 files changed, 115 insertions(+), 369 deletions(-) rename src/main/java/nova/core/util/{id => }/Identifiable.java (96%) rename src/main/java/nova/core/util/{id => }/UniqueIdentifiable.java (87%) delete mode 100644 src/main/java/nova/core/util/id/AbstractIdentifier.java delete mode 100644 src/main/java/nova/core/util/id/ClassIdentifier.java delete mode 100644 src/main/java/nova/core/util/id/Identifier.java delete mode 100644 src/main/java/nova/core/util/id/StringIdentifier.java delete mode 100644 src/main/java/nova/core/util/id/UUIDIdentifier.java diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/recipes/MinecraftItemIngredient.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/recipes/MinecraftItemIngredient.java index ddf1fbe86..97582befa 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/recipes/MinecraftItemIngredient.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/recipes/MinecraftItemIngredient.java @@ -29,6 +29,6 @@ */ public class MinecraftItemIngredient extends SpecificItemIngredient { public MinecraftItemIngredient(net.minecraft.item.ItemStack itemStack) { - super(((Item) Game.natives().toNova(itemStack)).getID().asString()); // TODO? + super(((Item) Game.natives().toNova(itemStack)).getID()); } } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/recipes/RecipeConverter.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/recipes/RecipeConverter.java index f02af76db..298f3d266 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/recipes/RecipeConverter.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/recipes/RecipeConverter.java @@ -84,7 +84,7 @@ private static ItemIngredient getIngredient(Object ingredient) { if (ingredient == null) { return null; } else if (ingredient instanceof ItemStack) { - return new SpecificItemIngredient(((Item) Game.natives().toNova(ingredient)).getID().asString()); // TODO? + return new SpecificItemIngredient(((Item) Game.natives().toNova(ingredient)).getID()); } else if (ingredient instanceof String) { return new OreItemIngredient((String) ingredient); } else if (ingredient instanceof List) { 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 edfc4b678..168742431 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 @@ -141,9 +141,8 @@ private void registerNovaBlock(BlockFactory blockFactory) { FWBlock blockWrapper = new FWBlock(blockFactory); blockFactoryMap.put(blockFactory, blockWrapper); NovaMinecraft.proxy.registerBlock(blockWrapper); - String blockId = blockFactory.getID().asString(); // TODO? -// GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, blockId.contains(":") ? blockId : modId + ":" + blockId); - registerNovaBlock(blockWrapper, blockId); +// GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, blockFactory.getID()); + registerNovaBlock(blockWrapper, blockFactory.getID()); if (blockWrapper.dummy.components.has(Category.class) && FMLCommonHandler.instance().getSide().isClient()) { //Add into creative tab 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 b4710f806..123d2e4f9 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 @@ -91,7 +91,7 @@ public FWBlock(BlockFactory factory) { this.factory = factory; this.dummy = factory.build(); this.blockClass = dummy.getClass(); - this.setBlockName(dummy.getID().asString()); // TODO? + this.setBlockName(dummy.getID()); // Recalculate super constructor things after loading the block properly this.opaque = isOpaqueCube(); @@ -169,7 +169,7 @@ public boolean hasTileEntity(int metadata) { @Override public TileEntity createTileEntity(World world, int metadata) { - return FWTileLoader.loadTile(dummy.getID().asString()); // TODO? + return FWTileLoader.loadTile(dummy.getID()); } @Override 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 858f4bc37..28f892222 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 @@ -29,8 +29,6 @@ import nova.core.entity.EntityFactory; import nova.core.item.Item; import nova.core.sound.Sound; -import nova.core.util.id.Identifier; -import nova.core.util.id.StringIdentifier; import nova.core.util.shape.Cuboid; import nova.core.world.World; import nova.core.wrapper.mc.forge.v17.launcher.NovaMinecraft; @@ -146,12 +144,12 @@ public Optional getEntity(String uniqueID) { } @Override - public Identifier getID() { - return new StringIdentifier(world().provider.getDimensionName()); + public String getID() { + return world().provider.getDimensionName(); } @Override public void playSoundAtPosition(Vector3D position, Sound sound) { - world().playSound(position.getX(), position.getY(), position.getZ(), sound.getID().asString(), sound.pitch, sound.volume, false); + world().playSound(position.getX(), position.getY(), position.getZ(), sound.getID(), sound.pitch, sound.volume, false); } } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/backward/BWEntity.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/backward/BWEntity.java index 83dda3ee3..bc58ff023 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/backward/BWEntity.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/entity/backward/BWEntity.java @@ -28,8 +28,6 @@ import nova.core.entity.Entity; import nova.core.entity.component.Living; import nova.core.entity.component.Player; -import nova.core.util.id.Identifier; -import nova.core.util.id.UUIDIdentifier; import nova.core.wrapper.mc.forge.v17.wrapper.entity.forward.MCEntityTransform; import nova.core.wrapper.mc.forge.v17.wrapper.inventory.BWInventory; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -90,8 +88,8 @@ public String getUsername() { } @Override - public Identifier getID() { - return new UUIDIdentifier(entity.getGameProfile().getId()); + public String getID() { + return entity.getGameProfile().getId().toString(); } @Override 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 9e4a91a4b..02a7bb50e 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 @@ -75,13 +75,13 @@ protected void writeEntityToNBT(NBTTagCompound nbt) { ((Storable) wrapped).save(data); DataWrapper.instance().toNative(nbt, data); } - nbt.setString("novaID", wrapped.getID().asString()); // TODO? + nbt.setString("novaID", wrapped.getID()); } @Override public void writeSpawnData(ByteBuf buffer) { //Write the ID of the entity to client - String id = wrapped.getID().asString(); // TODO? + String id = wrapped.getID(); char[] chars = id.toCharArray(); buffer.writeInt(chars.length); diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItem.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItem.java index 08fd8ebae..9bb8b6925 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItem.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/BWItem.java @@ -97,6 +97,6 @@ public net.minecraft.item.ItemStack makeItemStack(int stackSize) { @Override public String toString() { - return getID().asString(); // TODO? + return getID(); } } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/FWItem.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/FWItem.java index ebc78662b..7c4e8c8ec 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/FWItem.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/FWItem.java @@ -38,7 +38,7 @@ public class FWItem extends net.minecraft.item.Item implements ItemWrapperMethod public FWItem(ItemFactory item) { this.itemFactory = item; - setUnlocalizedName(item.getID().asString()); // TODO? + setUnlocalizedName(item.getID()); setMaxStackSize(item.build().getMaxCount()); } diff --git a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemConverter.java b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemConverter.java index 88aad96a4..80d8a2bdf 100644 --- a/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemConverter.java +++ b/minecraft/1.7/src/main/java/nova/core/wrapper/mc/forge/v17/wrapper/item/ItemConverter.java @@ -110,7 +110,7 @@ public ItemStack toNative(Item item) { if (item instanceof BWItem) { return ((BWItem) item).makeItemStack(item.count()); } else { - ItemFactory itemFactory = Game.items().get(item.getID().asString()).get(); // TODO? + ItemFactory itemFactory = Game.items().get(item.getID()).get(); FWNBTTagCompound tag = new FWNBTTagCompound(item); MinecraftItemMapping mapping = get(itemFactory); @@ -164,6 +164,7 @@ public net.minecraft.item.ItemStack updateMCItemStack(ItemStack itemStack, nova. /** * Register all Nova blocks */ + @Override public void preInit() { registerNOVAItemsToMinecraft(); registerMinecraftItemsToNOVA(); @@ -196,9 +197,9 @@ private void registerNOVAItem(ItemFactory itemFactory) { if (itemWrapper == null) { throw new InitializationException("ItemConverter: Missing block: " + itemFactory.getID()); } - if (!itemFactory.getID().asString().equals(net.minecraft.item.Item.itemRegistry.getNameForObject(itemWrapper))) { + if (!itemFactory.getID().equals(net.minecraft.item.Item.itemRegistry.getNameForObject(itemWrapper))) { System.err.println("[NOVA]: ItemConverter: " + net.minecraft.item.Item.itemRegistry.getNameForObject(itemWrapper) + " != " + itemFactory.getID()); - net.minecraft.item.Item newItemWrapper = (net.minecraft.item.Item)net.minecraft.item.Item.itemRegistry.getObject(itemFactory.getID().asString()); + net.minecraft.item.Item newItemWrapper = (net.minecraft.item.Item)net.minecraft.item.Item.itemRegistry.getObject(itemFactory.getID()); itemWrapper = newItemWrapper != null ? newItemWrapper : itemWrapper; } } else { @@ -211,9 +212,8 @@ private void registerNOVAItem(ItemFactory itemFactory) { // Don't register ItemBlocks twice if (!(dummy instanceof ItemBlock)) { NovaMinecraft.proxy.registerItem((FWItem) itemWrapper); - String itemId = itemFactory.getID().asString(); // TODO? - //GameRegistry.registerItem(itemWrapper, itemId); - registerNovaItem((FWItem) itemWrapper, itemId); +// GameRegistry.registerItem(itemWrapper, itemFactory.getID()); + registerNovaItem((FWItem) itemWrapper, itemFactory.getID()); if (dummy.components.has(Category.class) && FMLCommonHandler.instance().getSide().isClient()) { //Add into creative tab diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/recipes/MinecraftItemIngredient.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/recipes/MinecraftItemIngredient.java index 40701caf8..72116bf5e 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/recipes/MinecraftItemIngredient.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/recipes/MinecraftItemIngredient.java @@ -29,6 +29,6 @@ */ public class MinecraftItemIngredient extends SpecificItemIngredient { public MinecraftItemIngredient(net.minecraft.item.ItemStack itemStack) { - super(((Item) Game.natives().toNova(itemStack)).getID().asString()); // TODO? + super(((Item) Game.natives().toNova(itemStack)).getID()); } } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/recipes/RecipeConverter.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/recipes/RecipeConverter.java index 8547f577c..cd616f714 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/recipes/RecipeConverter.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/recipes/RecipeConverter.java @@ -84,7 +84,7 @@ private static ItemIngredient getIngredient(Object ingredient) { if (ingredient == null) { return null; } else if (ingredient instanceof ItemStack) { - return new SpecificItemIngredient(((Item) Game.natives().toNova(ingredient)).getID().asString()); // TODO? + return new SpecificItemIngredient(((Item) Game.natives().toNova(ingredient)).getID()); } else if (ingredient instanceof String) { return new OreItemIngredient((String) ingredient); } else if (ingredient instanceof List) { 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 1794f87ff..a4e257880 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 @@ -141,8 +141,8 @@ public boolean canReplace() { private void registerNovaBlock(BlockFactory blockFactory) { FWBlock blockWrapper = new FWBlock(blockFactory); blockFactoryMap.put(blockFactory, blockWrapper); - String blockId = blockFactory.getID().asString(); // TODO? - registerNovaBlock(blockWrapper, blockId); +// GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, blockFactory.getID()); + registerNovaBlock(blockWrapper, blockFactory.getID()); NovaMinecraft.proxy.postRegisterBlock(blockWrapper); if (blockWrapper.dummy.components.has(Category.class) && FMLCommonHandler.instance().getSide().isClient()) { 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 8a3a4c6f6..36d9eb71a 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 @@ -99,7 +99,7 @@ public FWBlock(BlockFactory factory) { this.stepSound = soundTypeStone; } this.blockClass = dummy.getClass(); - this.setUnlocalizedName(dummy.getID().asString()); // TODO? + this.setUnlocalizedName(dummy.getID()); // Recalculate super constructor things after loading the block properly this.fullBlock = isOpaqueCube(); @@ -179,7 +179,7 @@ public boolean hasTileEntity(IBlockState state) { @Override public TileEntity createTileEntity(World world, IBlockState state) { - FWTile fwTile = FWTileLoader.loadTile(dummy.getID().asString()); // TODO? + FWTile fwTile = FWTileLoader.loadTile(dummy.getID()); if (lastExtendedStatePos != null) { fwTile.block.components.getOrAdd(new MCBlockTransform(dummy, Game.natives().toNova(world), new Vector3D(lastExtendedStatePos.getX(), lastExtendedStatePos.getY(), lastExtendedStatePos.getZ()))); lastExtendedStatePos = null; 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 b62c264db..f7f1326ab 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 @@ -26,7 +26,7 @@ public String getBreakSound() { if (sound.domain.isEmpty() && !sound.name.contains(".")) { return "dig." + sound.name; } - return sound.getID().asString(); // TODO? + return sound.getID(); } return super.getBreakSound(); } @@ -38,7 +38,7 @@ public String getStepSound() { if (sound.domain.isEmpty() && !sound.name.contains(".")) { return "step." + sound.name; } - return sound.getID().asString(); // TODO? + return sound.getID(); } return super.getStepSound(); } @@ -50,7 +50,7 @@ public String getPlaceSound() { if (sound.domain.isEmpty()) { return sound.name; } - return sound.getID().asString(); // TODO? + return sound.getID(); } // By default MC uses the block break sound for block placement return this.getBreakSound(); 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 36eea8f77..d53baf619 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 @@ -31,8 +31,6 @@ import nova.core.entity.EntityFactory; import nova.core.item.Item; import nova.core.sound.Sound; -import nova.core.util.id.Identifier; -import nova.core.util.id.StringIdentifier; import nova.core.util.shape.Cuboid; import nova.core.world.World; import nova.core.wrapper.mc.forge.v18.launcher.NovaMinecraft; @@ -155,12 +153,12 @@ public Optional getEntity(String uniqueID) { } @Override - public Identifier getID() { - return new StringIdentifier(world().provider.getDimensionName()); + public String getID() { + return world().provider.getDimensionName(); } @Override public void playSoundAtPosition(Vector3D position, Sound sound) { - world().playSoundEffect(position.getX(), position.getY(), position.getZ(), sound.getID().asString(), sound.volume, sound.pitch); + world().playSoundEffect(position.getX(), position.getY(), position.getZ(), sound.getID(), sound.volume, sound.pitch); } } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/backward/BWEntity.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/backward/BWEntity.java index acb33bc20..eb68b58ff 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/backward/BWEntity.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/entity/backward/BWEntity.java @@ -28,8 +28,6 @@ import nova.core.entity.Entity; import nova.core.entity.component.Living; import nova.core.entity.component.Player; -import nova.core.util.id.Identifier; -import nova.core.util.id.UUIDIdentifier; import nova.core.wrapper.mc.forge.v18.wrapper.entity.forward.MCEntityTransform; import nova.core.wrapper.mc.forge.v18.wrapper.inventory.BWInventory; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -90,8 +88,8 @@ public String getUsername() { } @Override - public Identifier getID() { - return new UUIDIdentifier(entity.getGameProfile().getId()); + public String getID() { + return entity.getGameProfile().getId().toString(); } @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 72ae58935..d01763dc2 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 @@ -75,13 +75,13 @@ protected void writeEntityToNBT(NBTTagCompound nbt) { ((Storable) wrapped).save(data); DataWrapper.instance().toNative(nbt, data); } - nbt.setString("novaID", wrapped.getID().asString()); // TODO? + nbt.setString("novaID", wrapped.getID()); } @Override public void writeSpawnData(ByteBuf buffer) { //Write the ID of the entity to client - String id = wrapped.getID().asString(); // TODO? + String id = wrapped.getID(); char[] chars = id.toCharArray(); buffer.writeInt(chars.length); diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/BWItem.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/BWItem.java index 490c5b996..7476b9d26 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/BWItem.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/BWItem.java @@ -66,6 +66,6 @@ public ItemStack makeItemStack(int stackSize) { @Override public String toString() { - return getID().asString(); // TODO? + return getID(); } } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/FWItem.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/FWItem.java index 61b7b9adc..6ce3b84a4 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/FWItem.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/FWItem.java @@ -38,7 +38,7 @@ public class FWItem extends net.minecraft.item.Item implements ItemWrapperMethod public FWItem(ItemFactory item) { this.itemFactory = item; - setUnlocalizedName(item.getID().asString()); // TODO? + setUnlocalizedName(item.getID()); setMaxStackSize(item.build().getMaxCount()); } diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/ItemConverter.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/ItemConverter.java index f2df72a8b..5cbad7ff7 100644 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/ItemConverter.java +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/item/ItemConverter.java @@ -111,7 +111,7 @@ public ItemStack toNative(Item item) { if (item instanceof BWItem) { return ((BWItem) item).makeItemStack(item.count()); } else { - ItemFactory itemFactory = Game.items().get(item.getID().asString()).get();// TODO? + ItemFactory itemFactory = Game.items().get(item.getID()).get(); FWNBTTagCompound tag = new FWNBTTagCompound(item); MinecraftItemMapping mapping = get(itemFactory); @@ -166,6 +166,7 @@ public ItemStack updateMCItemStack(ItemStack itemStack, Item item) { /** * Register all Nova blocks */ + @Override public void preInit() { registerNOVAItemsToMinecraft(); registerMinecraftItemsToNOVA(); @@ -198,9 +199,9 @@ private void registerNOVAItem(ItemFactory itemFactory) { if (itemWrapper == null) { throw new InitializationException("ItemConverter: Missing block: " + itemFactory.getID()); } - if (!itemFactory.getID().asString().equals(net.minecraft.item.Item.itemRegistry.getNameForObject(itemWrapper))) { + if (!itemFactory.getID().equals(net.minecraft.item.Item.itemRegistry.getNameForObject(itemWrapper))) { System.err.println("[NOVA]: ItemConverter: " + net.minecraft.item.Item.itemRegistry.getNameForObject(itemWrapper) + " != " + itemFactory.getID()); - net.minecraft.item.Item newItemWrapper = net.minecraft.item.Item.getByNameOrId(itemFactory.getID().asString()); + net.minecraft.item.Item newItemWrapper = net.minecraft.item.Item.getByNameOrId(itemFactory.getID()); itemWrapper = newItemWrapper != null ? newItemWrapper : itemWrapper; } } else { @@ -213,8 +214,8 @@ private void registerNOVAItem(ItemFactory itemFactory) { // Don't register ItemBlocks twice if (!(dummy instanceof ItemBlock)) { NovaMinecraft.proxy.registerItem((FWItem) itemWrapper); - String itemId = itemFactory.getID().asString(); // TODO? - GameRegistry.registerItem(itemWrapper, itemId); +// GameRegistry.registerItem(itemWrapper, itemFactory.getID()); + registerNovaItem((FWItem) itemWrapper, itemFactory.getID()); if (dummy.components.has(Category.class) && FMLCommonHandler.instance().getSide().isClient()) { //Add into creative tab @@ -238,7 +239,7 @@ private void registerNOVAItem(ItemFactory itemFactory) { /** * Prevent forge from prefixing item IDs with "nova:" */ - private void registerNovaBlock(FWItem itemWrapper, String blockId) { + private void registerNovaItem(FWItem itemWrapper, String blockId) { try { Class gameDataClass = GameData.class; Method getMain = gameDataClass.getDeclaredMethod("getMain"); diff --git a/src/main/java/nova/core/block/Block.java b/src/main/java/nova/core/block/Block.java index 1e0e04bf4..7b7f4fb6a 100644 --- a/src/main/java/nova/core/block/Block.java +++ b/src/main/java/nova/core/block/Block.java @@ -30,8 +30,7 @@ import nova.core.item.Item; import nova.core.item.ItemFactory; import nova.core.util.Direction; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; +import nova.core.util.Identifiable; import nova.core.world.World; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -60,7 +59,7 @@ public final BlockFactory getFactory() { } @Override - public final Identifier getID() { + public final String getID() { return getFactory().getID(); } diff --git a/src/main/java/nova/core/component/Category.java b/src/main/java/nova/core/component/Category.java index f8cd3a0df..95c8002d4 100644 --- a/src/main/java/nova/core/component/Category.java +++ b/src/main/java/nova/core/component/Category.java @@ -21,9 +21,7 @@ package nova.core.component; import nova.core.item.Item; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; -import nova.core.util.id.StringIdentifier; +import nova.core.util.Identifiable; import java.util.Optional; @@ -48,7 +46,7 @@ public Category(String name) { } @Override - public Identifier getID() { - return new StringIdentifier(name); + public String getID() { + return name; } } diff --git a/src/main/java/nova/core/component/Component.java b/src/main/java/nova/core/component/Component.java index a0a854b6a..df2ecd0d4 100644 --- a/src/main/java/nova/core/component/Component.java +++ b/src/main/java/nova/core/component/Component.java @@ -21,9 +21,7 @@ package nova.core.component; import nova.core.component.exception.ComponentException; -import nova.core.util.id.ClassIdentifier; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; +import nova.core.util.Identifiable; /** * Base interface for all Components. @@ -53,7 +51,7 @@ public void onProviderChange() { } @Override - public Identifier getID() { - return new ClassIdentifier(getClass()); + public String getID() { + return getClass().getSimpleName(); } } diff --git a/src/main/java/nova/core/component/fluid/Fluid.java b/src/main/java/nova/core/component/fluid/Fluid.java index 675c36a57..809e968ca 100644 --- a/src/main/java/nova/core/component/fluid/Fluid.java +++ b/src/main/java/nova/core/component/fluid/Fluid.java @@ -24,9 +24,7 @@ import nova.core.retention.Data; import nova.core.retention.Storable; import nova.core.retention.Store; -import nova.core.util.id.AbstractIdentifier; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; +import nova.core.util.Identifiable; import nova.internal.core.Game; import java.util.Optional; @@ -128,7 +126,7 @@ public boolean sameType(Fluid stack) { } @Override - public final Identifier getID() { + public final String getID() { return factory.getID(); } @@ -140,12 +138,12 @@ public int hashCode() { @Override public void save(Data data) { Storable.super.save(data); - data.put("id", factory.getID().asString()); // TODO? + data.put("id", factory.getID()); } @Override public void load(Data data) { Storable.super.load(data); - factory = Game.fluids().get(data.get("id")).get(); // FIXME + factory = Game.fluids().get(data.get("id")).get(); } } diff --git a/src/main/java/nova/core/component/misc/Damageable.java b/src/main/java/nova/core/component/misc/Damageable.java index e5e6c9771..5f4c63c7d 100644 --- a/src/main/java/nova/core/component/misc/Damageable.java +++ b/src/main/java/nova/core/component/misc/Damageable.java @@ -21,9 +21,7 @@ package nova.core.component.misc; import nova.core.component.Component; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; -import nova.core.util.id.StringIdentifier; +import nova.core.util.Identifiable; /** * Applied to objects that can take damage. @@ -48,8 +46,8 @@ public DamageType(String name) { } @Override - public Identifier getID() { - return new StringIdentifier(name); + public String getID() { + return name; } } } diff --git a/src/main/java/nova/core/entity/Entity.java b/src/main/java/nova/core/entity/Entity.java index e8edd4958..c0943e100 100644 --- a/src/main/java/nova/core/entity/Entity.java +++ b/src/main/java/nova/core/entity/Entity.java @@ -24,10 +24,8 @@ import nova.core.component.ComponentProvider; import nova.core.component.misc.FactoryProvider; import nova.core.component.transform.EntityTransform; -import nova.core.util.id.Identifiable; -import nova.core.util.id.UniqueIdentifiable; -import nova.core.util.id.Identifier; -import nova.core.util.id.UUIDIdentifier; +import nova.core.util.Identifiable; +import nova.core.util.UniqueIdentifiable; import nova.core.world.World; import org.apache.commons.math3.geometry.euclidean.threed.Rotation; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -98,12 +96,12 @@ public final EntityFactory getFactory() { } @Override - public final Identifier getID() { + public final String getID() { return getFactory().getID(); } @Override - public UUIDIdentifier getUniqueID() { + public String getUniqueID() { return components.get(UniqueIdentifiable.class).getUniqueID(); } } diff --git a/src/main/java/nova/core/item/Item.java b/src/main/java/nova/core/item/Item.java index 255314bc7..61f6c86e1 100644 --- a/src/main/java/nova/core/item/Item.java +++ b/src/main/java/nova/core/item/Item.java @@ -27,8 +27,7 @@ import nova.core.render.Color; import nova.core.retention.Storable; import nova.core.util.Direction; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; +import nova.core.util.Identifiable; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import java.util.List; @@ -51,7 +50,7 @@ public final ItemFactory getFactory() { } @Override - public final Identifier getID() { + public final String getID() { return getFactory().getID(); } diff --git a/src/main/java/nova/core/item/ItemFactory.java b/src/main/java/nova/core/item/ItemFactory.java index 976b927ac..a31f83599 100644 --- a/src/main/java/nova/core/item/ItemFactory.java +++ b/src/main/java/nova/core/item/ItemFactory.java @@ -24,7 +24,7 @@ import nova.core.retention.Data; import nova.core.retention.Storable; import nova.core.util.registry.Factory; -import nova.core.util.id.Identifiable; +import nova.core.util.Identifiable; import java.util.function.Function; import java.util.function.Supplier; diff --git a/src/main/java/nova/core/item/ItemManager.java b/src/main/java/nova/core/item/ItemManager.java index cc22ec355..0b1122279 100644 --- a/src/main/java/nova/core/item/ItemManager.java +++ b/src/main/java/nova/core/item/ItemManager.java @@ -58,11 +58,11 @@ public ItemFactory register(ItemFactory factory) { } public ItemFactory getItemFromBlock(BlockFactory block) { - return registry.get(block.getID().asString()).get(); // TODO + return registry.get(block.getID()).get(); } public Optional getBlockFromItem(Item item) { - return blockManager.get().get(item.getID().asString()); // TODO + return blockManager.get().get(item.getID()); } @Override diff --git a/src/main/java/nova/core/network/Packet.java b/src/main/java/nova/core/network/Packet.java index 258c5c60f..2ad0c0484 100644 --- a/src/main/java/nova/core/network/Packet.java +++ b/src/main/java/nova/core/network/Packet.java @@ -26,12 +26,16 @@ import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; import java.util.stream.IntStream; /** * A packet of data that is writable or readable. - * * @author Calclavia */ public interface Packet { @@ -43,7 +47,6 @@ public interface Packet { /** * Sets the ID of this packet, allowing it to be sent accordingly. - * * @return The packet itself. */ Packet setID(int id); @@ -55,7 +58,6 @@ public interface Packet { /** * Writes an arbitrary object, automatically finding the relevant class. - * * @param data Object to write * @return This packet */ @@ -80,8 +82,6 @@ default Packet write(Object data) { writeString((String) data); } else if (data instanceof Enum) { writeEnum((Enum) data); - } else if (data instanceof Class) { - writeClass((Class) data); } else if (data instanceof Optional) { writeOptional((Optional) data); } else if (data instanceof Data) { @@ -101,8 +101,6 @@ default Packet write(Object data) { } else if (data instanceof Vector2D) { writeDouble(((Vector2D) data).getX()); writeDouble(((Vector2D) data).getY()); - } else if (data instanceof UUID) { - writeString(data.toString()); } else { throw new IllegalArgumentException("Packet attempt to write an invalid object: " + data); } @@ -117,7 +115,6 @@ default Packet write(Object data) { /** * Sets the specified boolean at the current {@code writerIndex} * and increases the {@code writerIndex} by {@code 1} in this buffer. - * * @param value Data to write * @return This packet * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 1} @@ -128,7 +125,6 @@ default Packet write(Object data) { * Sets the specified byte at the current {@code writerIndex} * and increases the {@code writerIndex} by {@code 1} in this buffer. * The 24 high-order bits of the specified value are ignored. - * * @param value Data to write * @return This packet * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 1} @@ -139,7 +135,6 @@ default Packet write(Object data) { * Sets the specified 16-bit short integer at the current * {@code writerIndex} and increases the {@code writerIndex} by {@code 2} * in this buffer. The 16 high-order bits of the specified value are ignored. - * * @param value Data to write * @return This packet * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 2} @@ -149,7 +144,6 @@ default Packet write(Object data) { /** * Sets the specified 32-bit integer at the current {@code writerIndex} * and increases the {@code writerIndex} by {@code 4} in this buffer. - * * @param value Data to write * @return This packet * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 4} @@ -160,7 +154,6 @@ default Packet write(Object data) { * Sets the specified 64-bit long integer at the current * {@code writerIndex} and increases the {@code writerIndex} by {@code 8} * in this buffer. - * * @param value Data to write * @return This packet * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 8} @@ -171,7 +164,6 @@ default Packet write(Object data) { * Sets the specified 2-byte UTF-16 character at the current * {@code writerIndex} and increases the {@code writerIndex} by {@code 2} * in this buffer. The 16 high-order bits of the specified value are ignored. - * * @param value Data to write * @return This packet * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 2} @@ -182,7 +174,6 @@ default Packet write(Object data) { * Sets the specified 32-bit floating point number at the current * {@code writerIndex} and increases the {@code writerIndex} by {@code 4} * in this buffer. - * * @param value Data to write * @return This packet * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 4} @@ -193,7 +184,6 @@ default Packet write(Object data) { * Sets the specified 64-bit floating point number at the current * {@code writerIndex} and increases the {@code writerIndex} by {@code 8} * in this buffer. - * * @param value Data to write * @return This packet * @throws IndexOutOfBoundsException if {@code this.writableBytes} is less than {@code 8} @@ -209,11 +199,6 @@ default Packet writeEnum(Enum data) { return this; } - default Packet writeClass(Class data) { - writeString(data.getName()); - return this; - } - default int getType(Class compare) { return IntStream .range(0, Data.dataTypes.length) @@ -273,7 +258,6 @@ default Packet writeOptional(Optional optional) { /** * Gets a boolean at the current {@code readerIndex} and increases * the {@code readerIndex} by {@code 1} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 1} */ @@ -282,7 +266,6 @@ default Packet writeOptional(Optional optional) { /** * Gets a byte at the current {@code readerIndex} and increases * the {@code readerIndex} by {@code 1} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 1} */ @@ -291,7 +274,6 @@ default Packet writeOptional(Optional optional) { /** * Gets an unsigned byte at the current {@code readerIndex} and increases * the {@code readerIndex} by {@code 1} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 1} */ @@ -300,7 +282,6 @@ default Packet writeOptional(Optional optional) { /** * Gets a 16-bit short integer at the current {@code readerIndex} * and increases the {@code readerIndex} by {@code 2} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 2} */ @@ -309,7 +290,6 @@ default Packet writeOptional(Optional optional) { /** * Gets a 32-bit integer at the current {@code readerIndex} * and increases the {@code readerIndex} by {@code 4} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 4} */ @@ -318,7 +298,6 @@ default Packet writeOptional(Optional optional) { /** * Gets an unsigned 32-bit integer at the current {@code readerIndex} * and increases the {@code readerIndex} by {@code 4} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 4} */ @@ -327,7 +306,6 @@ default Packet writeOptional(Optional optional) { /** * Gets a 64-bit integer at the current {@code readerIndex} * and increases the {@code readerIndex} by {@code 8} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 8} */ @@ -336,7 +314,6 @@ default Packet writeOptional(Optional optional) { /** * Gets a 2-byte UTF-16 character at the current {@code readerIndex} * and increases the {@code readerIndex} by {@code 2} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 2} */ @@ -345,7 +322,6 @@ default Packet writeOptional(Optional optional) { /** * Gets a 32-bit floating point number at the current {@code readerIndex} * and increases the {@code readerIndex} by {@code 4} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 4} */ @@ -354,7 +330,6 @@ default Packet writeOptional(Optional optional) { /** * Gets a 64-bit floating point number at the current {@code readerIndex} * and increases the {@code readerIndex} by {@code 8} in this buffer. - * * @return Data read from this packet * @throws IndexOutOfBoundsException if {@code this.readableBytes} is less than {@code 8} */ @@ -451,20 +426,6 @@ default Vector3D readVector3D() { return new Vector3D(readDouble(), readDouble(), readDouble()); } - default Class readClass() { - try { - String classClassName = readString(); - Class classClass = (Class) Class.forName(classClassName); - return classClass; - } catch (Exception e) { - throw new NetworkException("Failed to read enum.", e); - } - } - - default UUID readUUID() { - return UUID.fromString(readString()); - } - default T read(Class clazz) { if (clazz == Boolean.class || clazz == boolean.class) { return (T) Boolean.valueOf(readBoolean()); @@ -498,10 +459,6 @@ else if (Syncable.class.isAssignableFrom(clazz)) { return (T) readVector3D(); } else if (Vector2D.class.isAssignableFrom(clazz)) { return (T) readVector2D(); - } else if (Class.class.isAssignableFrom(clazz)) { - return (T) readClass(); - } else if (UUID.class.isAssignableFrom(clazz)) { - return (T) readUUID(); } else if (List.class.isAssignableFrom(clazz)) { return (T) readList(); } else if (Set.class.isAssignableFrom(clazz)) { diff --git a/src/main/java/nova/core/recipes/crafting/CraftingRecipeManager.java b/src/main/java/nova/core/recipes/crafting/CraftingRecipeManager.java index 4587cbc5d..6648c79ce 100644 --- a/src/main/java/nova/core/recipes/crafting/CraftingRecipeManager.java +++ b/src/main/java/nova/core/recipes/crafting/CraftingRecipeManager.java @@ -24,7 +24,6 @@ import nova.core.recipes.RecipeAddedEvent; import nova.core.recipes.RecipeManager; import nova.core.recipes.RecipeRemovedEvent; -import nova.core.util.id.Identifier; import java.util.ArrayList; import java.util.Collection; @@ -38,7 +37,6 @@ * @author Stan Hebben */ public class CraftingRecipeManager { - // TODO switch this to using Identifiers private final RecipeManager recipeManager; private final List dynamicRecipes; private final Multimap staticRecipes; @@ -88,7 +86,7 @@ public Optional getRecipe(CraftingGrid grid) { return Optional.empty(); } - String firstItemId = firstItem.get().getID().asString(); // TODO (this is BAD) + String firstItemId = firstItem.get().getID(); if (!staticRecipes.containsKey(firstItemId)) { return Optional.empty(); } diff --git a/src/main/java/nova/core/recipes/crafting/OreItemIngredient.java b/src/main/java/nova/core/recipes/crafting/OreItemIngredient.java index 52d3a473c..6a4661d8e 100644 --- a/src/main/java/nova/core/recipes/crafting/OreItemIngredient.java +++ b/src/main/java/nova/core/recipes/crafting/OreItemIngredient.java @@ -21,7 +21,6 @@ package nova.core.recipes.crafting; import nova.core.item.Item; -import nova.core.util.id.Identifier; import nova.internal.core.Game; import java.util.ArrayList; @@ -47,7 +46,7 @@ public String getName() { @Override public Optional> getPossibleItemIds() { - return Optional.of(Game.itemDictionary().get(name).stream().map(Item::getID).map(Identifier::asString).collect(Collectors.toList())); // TODO? + return Optional.of(Game.itemDictionary().get(name).stream().map(Item::getID).collect(Collectors.toList())); } @Override diff --git a/src/main/java/nova/core/render/Asset.java b/src/main/java/nova/core/render/Asset.java index 5aafccaa4..b5f9b96ec 100644 --- a/src/main/java/nova/core/render/Asset.java +++ b/src/main/java/nova/core/render/Asset.java @@ -20,9 +20,7 @@ package nova.core.render; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; -import nova.core.util.id.StringIdentifier; +import nova.core.util.Identifiable; /** * @author Calclavia @@ -50,7 +48,7 @@ public boolean equals(Object obj) { } @Override - public final Identifier getID() { - return new StringIdentifier(domain + ":" + name); + public final String getID() { + return domain + ":" + name; } } diff --git a/src/main/java/nova/core/render/RenderManager.java b/src/main/java/nova/core/render/RenderManager.java index 4098a8c87..c25f6b8eb 100644 --- a/src/main/java/nova/core/render/RenderManager.java +++ b/src/main/java/nova/core/render/RenderManager.java @@ -43,7 +43,7 @@ public abstract class RenderManager extends Manager { public final Registry modelProviders = new Registry<>(); public ItemTexture registerTexture(ItemTexture texture) { - Optional itemTexture = itemTextures.get(texture.getID().asString()); // TODO? + Optional itemTexture = itemTextures.get(texture.getID()); if (itemTexture.isPresent()) { Game.logger().error("Attempt to register the same texture twice: " + texture); return itemTexture.get(); @@ -53,7 +53,7 @@ public ItemTexture registerTexture(ItemTexture texture) { } public BlockTexture registerTexture(BlockTexture texture) { - Optional blockTexture = blockTextures.get(texture.getID().asString()); // TODO? + Optional blockTexture = blockTextures.get(texture.getID()); if (blockTexture.isPresent()) { Game.logger().error("Attempt to register the same texture twice: " + texture); return blockTexture.get(); @@ -63,7 +63,7 @@ public BlockTexture registerTexture(BlockTexture texture) { } public EntityTexture registerTexture(EntityTexture texture) { - Optional entityTexture = entityTextures.get(texture.getID().asString()); // TODO? + Optional entityTexture = entityTextures.get(texture.getID()); if (entityTexture.isPresent()) { Game.logger().error("Attempt to register the same texture twice: " + texture); return entityTexture.get(); @@ -73,7 +73,7 @@ public EntityTexture registerTexture(EntityTexture texture) { } public ModelProvider registerModel(ModelProvider modelProvider) { - Optional modelProviderCheck = modelProviders.get(modelProvider.getID().asString()); // TODO? + Optional modelProviderCheck = modelProviders.get(modelProvider.getID()); if (modelProviderCheck.isPresent()) { Game.logger().error("Attempt to register the same model twice: " + modelProvider); return modelProviderCheck.get(); diff --git a/src/main/java/nova/core/render/texture/Texture.java b/src/main/java/nova/core/render/texture/Texture.java index 4c62b3c32..ee7596cfa 100644 --- a/src/main/java/nova/core/render/texture/Texture.java +++ b/src/main/java/nova/core/render/texture/Texture.java @@ -18,9 +18,7 @@ * along with NOVA. If not, see . */package nova.core.render.texture; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; -import nova.core.util.id.StringIdentifier; +import nova.core.util.Identifiable; import nova.core.util.math.Vector2DUtil; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; @@ -62,8 +60,8 @@ public String toString() { } @Override - public final Identifier getID() { - return new StringIdentifier(getResource()); + public final String getID() { + return getResource(); } @Override diff --git a/src/main/java/nova/core/retention/Data.java b/src/main/java/nova/core/retention/Data.java index f3e2cea52..71d689c74 100755 --- a/src/main/java/nova/core/retention/Data.java +++ b/src/main/java/nova/core/retention/Data.java @@ -23,7 +23,10 @@ import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; -import java.util.*; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; /** * The data class is capable of storing named data. @@ -63,9 +66,7 @@ public class Data extends HashMap { Data.class, Collection.class, Vector3D.class, - Vector2D.class, - Class.class, - UUID.class }; + Vector2D.class }; public String className; @@ -107,10 +108,6 @@ public static Object unserialize(Data data) { return new Vector3D(data.get("x"), data.get("y"), data.get("z")); } else if (clazz == Vector2D.class) { return new Vector2D(data.get("x"), (double) data.get("y")); - } else if (clazz == UUID.class) { - return UUID.fromString(data.get("uuid")); - } else if (clazz == Class.class) { - return Class.forName(data.get("name")); } else { return unserialize(clazz, data); } @@ -168,14 +165,6 @@ public Object put(String key, Object value) { vectorData.put("x", ((Vector2D) value).getX()); vectorData.put("y", ((Vector2D) value).getY()); value = vectorData; - } else if (value instanceof UUID) { - Data uuidData = new Data(UUID.class); - uuidData.put("uuid", value.toString()); - value = uuidData; - } else if (value instanceof Class) { - Data classData = new Data(Class.class); - classData.put("name", ((Class) value).getName()); - value = classData; } else if (value instanceof Storable) { value = serialize((Storable) value); } @@ -225,19 +214,4 @@ public T getStorable(String key) { } } - public Class getClass(String key) { - Data classData = get(key); - try { - @SuppressWarnings("unchecked") - Class classClass = (Class) Class.forName(classData.className); - return classClass; - } catch (Exception e) { - throw new DataException(e); - } - } - - public UUID getUUID(String key) { - Data data = get(key); - return UUID.fromString(data.get("uuid")); - } } diff --git a/src/main/java/nova/core/retention/Storable.java b/src/main/java/nova/core/retention/Storable.java index 2e1fdb586..84fcfbed7 100644 --- a/src/main/java/nova/core/retention/Storable.java +++ b/src/main/java/nova/core/retention/Storable.java @@ -61,11 +61,11 @@ default void load(Data data) { if (data.containsKey(name)) { try { field.setAccessible(true); - Class type = field.getType(); // FIXME + Class type = field.getType(); Object fieldValue = field.get(this); Object value = data.get(name); - if (Storable.class.isAssignableFrom(type) || value instanceof Data) { // FIXME should test things based on `data` - if (fieldValue instanceof Storable && value instanceof Data) { // this one is fine tho + if (Storable.class.isAssignableFrom(type) || value instanceof Data) { + if (fieldValue instanceof Storable && value instanceof Data) { //We already have an instance. Don't need to create the object. ((Storable) fieldValue).load((Data) value); } else { diff --git a/src/main/java/nova/core/sound/Sound.java b/src/main/java/nova/core/sound/Sound.java index 6dc35697d..127bc23d3 100644 --- a/src/main/java/nova/core/sound/Sound.java +++ b/src/main/java/nova/core/sound/Sound.java @@ -21,7 +21,7 @@ package nova.core.sound; import nova.core.render.Asset; -import nova.core.util.id.Identifiable; +import nova.core.util.Identifiable; /** * An object representing a sound. (including the modification to pitch and volume, etc...) diff --git a/src/main/java/nova/core/util/id/Identifiable.java b/src/main/java/nova/core/util/Identifiable.java similarity index 96% rename from src/main/java/nova/core/util/id/Identifiable.java rename to src/main/java/nova/core/util/Identifiable.java index c4f7eb6aa..3fc6a1d34 100644 --- a/src/main/java/nova/core/util/id/Identifiable.java +++ b/src/main/java/nova/core/util/Identifiable.java @@ -18,7 +18,7 @@ * along with NOVA. If not, see . */ -package nova.core.util.id; +package nova.core.util; /** * A generic interface signifying that this object is identifiable @@ -30,7 +30,7 @@ public interface Identifiable { * * @return the ID */ - Identifier getID(); + String getID(); /** * Compares the ID of the Identifialbes diff --git a/src/main/java/nova/core/util/id/UniqueIdentifiable.java b/src/main/java/nova/core/util/UniqueIdentifiable.java similarity index 87% rename from src/main/java/nova/core/util/id/UniqueIdentifiable.java rename to src/main/java/nova/core/util/UniqueIdentifiable.java index ae37ad60f..a795892d1 100644 --- a/src/main/java/nova/core/util/id/UniqueIdentifiable.java +++ b/src/main/java/nova/core/util/UniqueIdentifiable.java @@ -18,9 +18,7 @@ * along with NOVA. If not, see . */ -package nova.core.util.id; - -import nova.core.util.id.UUIDIdentifier; +package nova.core.util; /** * A generic interface signifying that this object is uniquely identifiable @@ -32,5 +30,5 @@ public interface UniqueIdentifiable { * * @return the ID */ - UUIDIdentifier getUniqueID(); // TODO maybe this should return a simple Identifier + String getUniqueID(); } diff --git a/src/main/java/nova/core/util/id/AbstractIdentifier.java b/src/main/java/nova/core/util/id/AbstractIdentifier.java deleted file mode 100644 index 651b5438d..000000000 --- a/src/main/java/nova/core/util/id/AbstractIdentifier.java +++ /dev/null @@ -1,46 +0,0 @@ -package nova.core.util.id; - -import nova.core.retention.Data; -import nova.core.retention.Storable; -import nova.core.retention.Store; - -/** - * Basic implementation of Identifier. - * - * @author soniex2 - */ -public abstract class AbstractIdentifier implements Identifier { - /** - * The ID. - */ - protected final T id; - - /** - * Constructs a new AbstractIdentifier. - * - * @param id The ID. - */ - public AbstractIdentifier(T id) { - this.id = id; - } - - @Override - public String asString() { - return id.toString(); - } - - @Override - public String toString() { - return id.toString(); - } - - @Override - public int hashCode() { - return id.hashCode(); - } - - @Override - public boolean equals(Object o) { - return this == o || (o != null && getClass() == o.getClass() && id.equals(((AbstractIdentifier) o).id)); - } -} diff --git a/src/main/java/nova/core/util/id/ClassIdentifier.java b/src/main/java/nova/core/util/id/ClassIdentifier.java deleted file mode 100644 index 8fbc7466c..000000000 --- a/src/main/java/nova/core/util/id/ClassIdentifier.java +++ /dev/null @@ -1,32 +0,0 @@ -package nova.core.util.id; - -/** - * A Class Identifier. - * - * @author soniex2 - */ -public final class ClassIdentifier extends AbstractIdentifier> implements Identifier { - - /** - * Constructs a new ClassIdentifier. - * - * @param id The Class. - */ - public ClassIdentifier(Class id) { - super(id); - } - - @Override - public String asString() { - return id.getSimpleName(); - } - - /** - * Returns this Identifier's Class. - * - * @return The Class. - */ - public Class asClass() { - return id; - } -} diff --git a/src/main/java/nova/core/util/id/Identifier.java b/src/main/java/nova/core/util/id/Identifier.java deleted file mode 100644 index 7453cef99..000000000 --- a/src/main/java/nova/core/util/id/Identifier.java +++ /dev/null @@ -1,19 +0,0 @@ -package nova.core.util.id; - -/** - * The interface for all identifiers. - *

- * Implementations should override {@link Object#equals(Object)}, {@link Object#hashCode()} and {@link Object#toString()}. - *

- * - * @author soniex2 - */ -public interface Identifier { - /** - * Converts this Identifier into a String. - * The output from this method may be different than {@link Object#toString()}. - * - * @return A string representation of this Identifier. - */ - String asString(); -} diff --git a/src/main/java/nova/core/util/id/StringIdentifier.java b/src/main/java/nova/core/util/id/StringIdentifier.java deleted file mode 100644 index f52b45030..000000000 --- a/src/main/java/nova/core/util/id/StringIdentifier.java +++ /dev/null @@ -1,18 +0,0 @@ -package nova.core.util.id; - -/** - * A String Identifier. - * - * @author soniex2 - */ -public final class StringIdentifier extends AbstractIdentifier implements Identifier { - - /** - * Constructs a new StringIdentifier. - * - * @param id The String. - */ - public StringIdentifier(String id) { - super(id); - } -} diff --git a/src/main/java/nova/core/util/id/UUIDIdentifier.java b/src/main/java/nova/core/util/id/UUIDIdentifier.java deleted file mode 100644 index 754c214fd..000000000 --- a/src/main/java/nova/core/util/id/UUIDIdentifier.java +++ /dev/null @@ -1,29 +0,0 @@ -package nova.core.util.id; - -import java.util.UUID; - -/** - * An UUID Identifier. - * - * @author soniex2 - */ -public final class UUIDIdentifier extends AbstractIdentifier implements Identifier { - - /** - * Constructs a new UUIDIdentifier. - * - * @param id The UUID. - */ - public UUIDIdentifier(UUID id) { - super(id); - } - - /** - * Returns this Identifier's UUID. - * - * @return The UUID. - */ - public UUID asUUID() { - return id; - } -} diff --git a/src/main/java/nova/core/util/registry/Factory.java b/src/main/java/nova/core/util/registry/Factory.java index 011a861b3..a0f1d659d 100644 --- a/src/main/java/nova/core/util/registry/Factory.java +++ b/src/main/java/nova/core/util/registry/Factory.java @@ -20,9 +20,7 @@ package nova.core.util.registry; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; -import nova.core.util.id.StringIdentifier; +import nova.core.util.Identifiable; import java.util.function.Function; import java.util.function.Supplier; @@ -81,7 +79,7 @@ public T build() { } @Override - public Identifier getID() { - return new StringIdentifier(id); + public String getID() { + return id; } } diff --git a/src/main/java/nova/core/util/registry/FactoryManager.java b/src/main/java/nova/core/util/registry/FactoryManager.java index 8c2281833..20a38d558 100644 --- a/src/main/java/nova/core/util/registry/FactoryManager.java +++ b/src/main/java/nova/core/util/registry/FactoryManager.java @@ -20,7 +20,7 @@ package nova.core.util.registry; -import nova.core.util.id.Identifiable; +import nova.core.util.Identifiable; import java.util.Optional; import java.util.function.Supplier; diff --git a/src/main/java/nova/core/util/registry/Registry.java b/src/main/java/nova/core/util/registry/Registry.java index 24e724416..bf25553d9 100644 --- a/src/main/java/nova/core/util/registry/Registry.java +++ b/src/main/java/nova/core/util/registry/Registry.java @@ -19,8 +19,7 @@ */package nova.core.util.registry; import com.google.common.collect.HashBiMap; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; +import nova.core.util.Identifiable; import java.util.Iterator; import java.util.Optional; @@ -33,7 +32,6 @@ * @param The object type */ public class Registry implements Iterable { - // TODO maybe index by Identifier? Could be nice when the game uses int IDs (e.g. very old versions of minecraft). private final HashBiMap objects = HashBiMap.create(); public Registry() { @@ -47,7 +45,7 @@ public Registry() { * @return Given object */ public T register(T object) { - objects.put(object.getID().asString(), object); + objects.put(object.getID(), object); return object; } diff --git a/src/main/java/nova/core/world/World.java b/src/main/java/nova/core/world/World.java index 22832ac35..d89565221 100644 --- a/src/main/java/nova/core/world/World.java +++ b/src/main/java/nova/core/world/World.java @@ -24,7 +24,7 @@ import nova.core.entity.EntityFactory; import nova.core.item.Item; import nova.core.sound.Sound; -import nova.core.util.id.Identifiable; +import nova.core.util.Identifiable; import nova.core.util.shape.Cuboid; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; diff --git a/src/test/java/nova/core/util/MockIdentifiable.java b/src/test/java/nova/core/util/MockIdentifiable.java index 33569e31c..a69500bc8 100644 --- a/src/test/java/nova/core/util/MockIdentifiable.java +++ b/src/test/java/nova/core/util/MockIdentifiable.java @@ -20,10 +20,6 @@ package nova.core.util; -import nova.core.util.id.Identifiable; -import nova.core.util.id.Identifier; -import nova.core.util.id.StringIdentifier; - public class MockIdentifiable implements Identifiable { String ID; @@ -32,12 +28,12 @@ public MockIdentifiable(String ID) { } @Override - public Identifier getID() { - return new StringIdentifier(ID); + public String getID() { + return ID; } @Override public String toString() { - return getID().asString(); + return getID(); } } diff --git a/src/test/java/nova/core/util/RegistryTest.java b/src/test/java/nova/core/util/RegistryTest.java index 9e80a9313..79afd10d8 100644 --- a/src/test/java/nova/core/util/RegistryTest.java +++ b/src/test/java/nova/core/util/RegistryTest.java @@ -20,8 +20,6 @@ package nova.core.util; -import nova.core.util.id.Identifiable; -import nova.core.util.id.StringIdentifier; import nova.core.util.registry.Registry; import org.junit.Test; @@ -43,8 +41,8 @@ public void testRegistry() throws Exception { assertThat(registry.contains("ID1")).isTrue(); assertThat(registry.contains("ID2")).isTrue(); - assertThat(registry.get("ID1").get().getID()).isEqualTo(new StringIdentifier("ID1")); - assertThat(registry.get("ID2").get().getID()).isEqualTo(new StringIdentifier("ID2")); + assertThat(registry.get("ID1").get().getID()).isEqualTo("ID1"); + assertThat(registry.get("ID2").get().getID()).isEqualTo("ID2"); assertThat(registry.get("ID1").get()).isEqualTo(id1); assertThat(registry.get("ID2").get()).isEqualTo(id2); diff --git a/src/test/java/nova/testutils/FakeWorld.java b/src/test/java/nova/testutils/FakeWorld.java index 522e878ab..c4443bdb5 100644 --- a/src/test/java/nova/testutils/FakeWorld.java +++ b/src/test/java/nova/testutils/FakeWorld.java @@ -28,8 +28,6 @@ import nova.core.entity.EntityFactory; import nova.core.item.Item; import nova.core.sound.Sound; -import nova.core.util.id.Identifier; -import nova.core.util.id.StringIdentifier; import nova.core.util.shape.Cuboid; import nova.core.world.World; import nova.internal.core.Game; @@ -133,7 +131,7 @@ public void playSoundAtPosition(Vector3D position, Sound sound) { } @Override - public Identifier getID() { - return new StringIdentifier("fakeWorld"); + public String getID() { + return "fakeWorld"; } }