From 70493f68dcb74b36eb6fd8cc024a4f96691c6122 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Sun, 23 Oct 2016 12:32:12 -0200 Subject: [PATCH 1/6] Remove BlockProperties --- .../v18/wrapper/block/backward/BWBlock.java | 14 +- .../v18/wrapper/block/forward/FWBlock.java | 28 ++- .../wrapper/block/forward/FWBlockSound.java | 58 +++++ .../block/forward/MCBlockProperties.java | 116 --------- .../wrapper/block/forward/ProxyMaterial.java | 34 +++ src/main/java/nova/core/block/Block.java | 6 +- .../core/block/component/BlockProperties.java | 142 ----------- .../core/block/component/BlockProperty.java | 231 ++++++++++++++++++ src/main/java/nova/core/item/ItemBlock.java | 6 +- 9 files changed, 358 insertions(+), 277 deletions(-) create mode 100644 minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlockSound.java delete mode 100644 minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/MCBlockProperties.java create mode 100644 minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/ProxyMaterial.java delete mode 100644 src/main/java/nova/core/block/component/BlockProperties.java create mode 100644 src/main/java/nova/core/block/component/BlockProperty.java 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 b5180821d..a7d70ff25 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 @@ -31,7 +31,7 @@ import net.minecraft.util.BlockPos; import net.minecraft.world.IBlockAccess; import nova.core.block.Block; -import nova.core.block.component.BlockProperties; +import nova.core.block.component.BlockProperty; import nova.core.block.component.LightEmitter; import nova.core.component.misc.Collider; import nova.core.component.transform.BlockTransform; @@ -39,6 +39,7 @@ import nova.core.retention.Data; import nova.core.retention.Storable; import nova.core.retention.Store; +import nova.core.sound.Sound; import nova.core.util.shape.Cuboid; import nova.core.world.World; import nova.core.wrapper.mc.forge.v18.wrapper.block.world.BWWorld; @@ -66,11 +67,12 @@ public BWBlock(net.minecraft.block.Block block, World world, Vector3D pos) { transform.setWorld(world); transform.setPosition(pos); - BlockProperties blockMaterial = components.add(new BlockProperties()); - blockMaterial.setLightTransmission(!mcBlock.getMaterial().blocksLight()); - blockMaterial.setBlockSound(BlockProperties.BlockSoundTrigger.PLACE, mcBlock.stepSound.getPlaceSound()); - blockMaterial.setBlockSound(BlockProperties.BlockSoundTrigger.BREAK, mcBlock.stepSound.getBreakSound()); - blockMaterial.setBlockSound(BlockProperties.BlockSoundTrigger.WALK, mcBlock.stepSound.getStepSound()); + components.add(new BlockProperty.Opacity().setLightTransmission(!mcBlock.getMaterial().blocksLight())); + + BlockProperty.BlockSound blockSound = components.add(new BlockProperty.BlockSound()); + blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", mcBlock.stepSound.getPlaceSound())); + blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", mcBlock.stepSound.getBreakSound())); + blockSound.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", mcBlock.stepSound.getStepSound())); components.add(new LightEmitter()).setEmittedLevel(() -> mcBlock.getLightValue(getMcBlockAccess(), new BlockPos(x(), y(), z())) / 15.0F); components.add(new Collider(this)) 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 593f7a376..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 @@ -20,6 +20,7 @@ package nova.core.wrapper.mc.forge.v18.wrapper.block.forward; +import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; @@ -37,11 +38,12 @@ import nova.core.block.Block; import nova.core.block.BlockFactory; import nova.core.block.Stateful; -import nova.core.block.component.BlockProperties; +import nova.core.block.component.BlockProperty; import nova.core.block.component.LightEmitter; import nova.core.component.Updater; import nova.core.component.misc.Collider; import nova.core.retention.Storable; +import nova.core.sound.Sound; import nova.core.util.Direction; import nova.core.util.shape.Cuboid; import nova.core.wrapper.mc.forge.v18.util.WrapperEvent; @@ -72,18 +74,28 @@ public class FWBlock extends net.minecraft.block.Block { public BlockPos lastExtendedStatePos; private Map harvestedBlocks = new HashMap<>(); + private static Material getMcMaterial(BlockFactory factory) { + Block dummy = factory.build(); + if (dummy.components.has(BlockProperty.Opacity.class)) { + // TODO allow color selection + return new ProxyMaterial(MapColor.grayColor, dummy.components.get(BlockProperty.Opacity.class)); + } else { + return Material.piston; + } + } + public FWBlock(BlockFactory factory) { //TODO: Hack build() method - super(factory.build().components.has(BlockProperties.class) ? new MCBlockProperties(factory.build().components.get(BlockProperties.class)).toMcMaterial() : Material.piston); + super(getMcMaterial(factory)); this.factory = factory; this.dummy = factory.build(); - if (this.getMaterial() instanceof MCBlockProperties.ProxyMaterial) { - this.stepSound = ((MCBlockProperties.ProxyMaterial) this.getMaterial()).getSoundType(); + if (dummy.components.has(BlockProperty.BlockSound.class)) { + this.stepSound = new FWBlockSound(dummy.components.get(BlockProperty.BlockSound.class)); } else { - BlockProperties properties = dummy.components.add(new BlockProperties()); - properties.setBlockSound(BlockProperties.BlockSoundTrigger.BREAK, soundTypeStone.getBreakSound()); - properties.setBlockSound(BlockProperties.BlockSoundTrigger.PLACE, soundTypeStone.getPlaceSound()); - properties.setBlockSound(BlockProperties.BlockSoundTrigger.WALK, soundTypeStone.getStepSound()); + BlockProperty.BlockSound properties = dummy.components.add(new BlockProperty.BlockSound()); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.BREAK, new Sound("", soundTypeStone.getBreakSound())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE, new Sound("", soundTypeStone.getPlaceSound())); + properties.setBlockSound(BlockProperty.BlockSound.BlockSoundTrigger.WALK, new Sound("", soundTypeStone.getStepSound())); this.stepSound = soundTypeStone; } this.blockClass = dummy.getClass(); 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 new file mode 100644 index 000000000..f7f1326ab --- /dev/null +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/FWBlockSound.java @@ -0,0 +1,58 @@ +package nova.core.wrapper.mc.forge.v18.wrapper.block.forward; + +import net.minecraft.block.Block; +import nova.core.block.component.BlockProperty.BlockSound; +import nova.core.sound.Sound; + +/** + * @author winsock, soniex2 + */ +public class FWBlockSound extends Block.SoundType { + private final BlockSound blockSound; + + /** + * Construct a new FWBlockSound + * @param blockSound The BlockSound to use. + */ + public FWBlockSound(BlockSound blockSound) { + super("", 1f, 1f); + this.blockSound = blockSound; + } + + @Override + public String getBreakSound() { + if (blockSound.blockSoundSoundMap.containsKey(BlockSound.BlockSoundTrigger.BREAK)) { + Sound sound = blockSound.blockSoundSoundMap.get(BlockSound.BlockSoundTrigger.BREAK); + if (sound.domain.isEmpty() && !sound.name.contains(".")) { + return "dig." + sound.name; + } + return sound.getID(); + } + return super.getBreakSound(); + } + + @Override + public String getStepSound() { + if (blockSound.blockSoundSoundMap.containsKey(BlockSound.BlockSoundTrigger.WALK)) { + Sound sound = blockSound.blockSoundSoundMap.get(BlockSound.BlockSoundTrigger.WALK); + if (sound.domain.isEmpty() && !sound.name.contains(".")) { + return "step." + sound.name; + } + return sound.getID(); + } + return super.getStepSound(); + } + + @Override + public String getPlaceSound() { + if (blockSound.blockSoundSoundMap.containsKey(BlockSound.BlockSoundTrigger.WALK)) { + Sound sound = blockSound.blockSoundSoundMap.get(BlockSound.BlockSoundTrigger.WALK); + if (sound.domain.isEmpty()) { + return sound.name; + } + return sound.getID(); + } + // By default MC uses the block break sound for block placement + return this.getBreakSound(); + } +} diff --git a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/MCBlockProperties.java b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/MCBlockProperties.java deleted file mode 100644 index 45dcacf47..000000000 --- a/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/MCBlockProperties.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Copyright (c) 2015 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; -import net.minecraft.block.material.MapColor; -import net.minecraft.block.material.Material; -import nova.core.block.component.BlockProperties; -import nova.core.sound.Sound; - -/** - * Created by winsock on 7/2/15. - */ -public class MCBlockProperties extends BlockProperties { - private Material mcMaterial = null; - - public MCBlockProperties() { - } - - public MCBlockProperties(BlockProperties copy) { - this.blockSoundSoundMap = copy.blockSoundSoundMap; - this.customDefinedSounds = copy.customDefinedSounds; - this.allowsLightThrough = copy.allowsLightThrough; - } - - public Material toMcMaterial() { - if (mcMaterial == null) { - // TODO: We most likely should offer a way to set the color. - mcMaterial = new ProxyMaterial(MapColor.grayColor); - } - return mcMaterial; - } - - public class ProxyMaterial extends Material { - private final FWBlockSound sound = new FWBlockSound(); - - public ProxyMaterial(MapColor color) { - super(color); - } - - @Override - public boolean blocksLight() { - return !MCBlockProperties.this.allowsLightThrough; - } - - @Override - public boolean isOpaque() { - return !MCBlockProperties.this.allowsLightThrough; - } - - public Block.SoundType getSoundType() { - return sound; - } - - private class FWBlockSound extends Block.SoundType { - public FWBlockSound() { - super("", 1f, 1f); - } - - @Override - public String getBreakSound() { - if (MCBlockProperties.this.blockSoundSoundMap.containsKey(BlockSoundTrigger.BREAK)) { - Sound sound = MCBlockProperties.this.blockSoundSoundMap.get(BlockSoundTrigger.BREAK); - if (sound.domain.isEmpty() && !sound.name.contains(".")) { - return "dig." + sound.name; - } - return sound.getID(); - } - return super.getBreakSound(); - } - - @Override - public String getStepSound() { - if (MCBlockProperties.this.blockSoundSoundMap.containsKey(BlockSoundTrigger.WALK)) { - Sound sound = MCBlockProperties.this.blockSoundSoundMap.get(BlockSoundTrigger.WALK); - if (sound.domain.isEmpty() && !sound.name.contains(".")) { - return "step." + sound.name; - } - return sound.getID(); - } - return super.getStepSound(); - } - - @Override - public String getPlaceSound() { - if (MCBlockProperties.this.blockSoundSoundMap.containsKey(BlockSoundTrigger.WALK)) { - Sound sound = MCBlockProperties.this.blockSoundSoundMap.get(BlockSoundTrigger.WALK); - if (sound.domain.isEmpty()) { - return sound.name; - } - return sound.getID(); - } - // By default MC uses the block break sound for block placement - return this.getBreakSound(); - } - } - } -} 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 new file mode 100644 index 000000000..a5b6cfc4b --- /dev/null +++ b/minecraft/1.8/src/main/java/nova/core/wrapper/mc/forge/v18/wrapper/block/forward/ProxyMaterial.java @@ -0,0 +1,34 @@ +package nova.core.wrapper.mc.forge.v18.wrapper.block.forward; + +import net.minecraft.block.material.MapColor; +import net.minecraft.block.material.Material; +import nova.core.block.component.BlockProperty; +import nova.core.block.component.BlockProperty.Opacity; + +/** + * @author soniex2 + */ +public class ProxyMaterial extends Material { + private final Opacity opacity; + + /** + * Construct a new proxy material. + * @param color The map color. + * @param opacity The Opacity to use. + */ + public ProxyMaterial(MapColor color, Opacity opacity) { + super(color); + this.opacity = opacity; + } + + @Override + public boolean blocksLight() { + return opacity.allowsLightThrough; + } + + @Override + public boolean isOpaque() { + return opacity.allowsLightThrough; + } + +} diff --git a/src/main/java/nova/core/block/Block.java b/src/main/java/nova/core/block/Block.java index fa298f9d7..7b7f4fb6a 100644 --- a/src/main/java/nova/core/block/Block.java +++ b/src/main/java/nova/core/block/Block.java @@ -20,6 +20,7 @@ package nova.core.block; +import nova.core.block.component.BlockProperty; import nova.core.component.ComponentProvider; import nova.core.component.misc.FactoryProvider; import nova.core.component.transform.BlockTransform; @@ -104,7 +105,7 @@ public final int z() { * @return The breaking difficulty. */ public double getHardness() { - return 1; + return components.getOp(BlockProperty.Hardness.class).orElseGet(BlockProperty.Hardness::new).getHardness(); } /** @@ -113,7 +114,7 @@ public double getHardness() { * @return The resistance. */ public double getResistance() { - return 1; + return components.getOp(BlockProperty.Resistance.class).orElseGet(BlockProperty.Resistance::new).getResistance(); } /** @@ -127,6 +128,7 @@ public boolean canReplace() { /** * Called when an ItemBlock tries to place a block in this position whether to displace the place position or not. * If the ItemBlock does not displace the position, it will replace this block. + * TODO move out into BlockProperty * @return True if by right clicking on this block, the placement of the new block should be displaced. */ public boolean shouldDisplacePlacement() { diff --git a/src/main/java/nova/core/block/component/BlockProperties.java b/src/main/java/nova/core/block/component/BlockProperties.java deleted file mode 100644 index 9e7ff1d4a..000000000 --- a/src/main/java/nova/core/block/component/BlockProperties.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright (c) 2015 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 com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import nova.core.component.Component; -import nova.core.sound.Sound; - -import java.util.Optional; - -/** - * This optional component is for properties that alter a blocks function - * These properties are intended to effect all blocks of one type. - * TODO: Make a component for blocks that have instance properties. E.G. In Minecraft NBT data - * - Note(winsock): I think instance block data storage is an agnostic voxel game feature that goes beyond just 'dumb' blocks - * Created by winsock on 7/2/15. - */ -public class BlockProperties extends Component { - - public BiMap blockSoundSoundMap = HashBiMap.create(); - public Optional> customDefinedSounds; - /** - * This boolean determines if the block should allow light through itself or not. - */ - public boolean allowsLightThrough = false; - - /** - * Sets a sound to play on a specified trigger. Note to set a @see{BlockSoundTrigger.CUSTOM_TRIGGER} use @see{BlockProperties.setCustomBlockSound(String,Sound)} - * - * @param trigger The trigger to set the sound for - * @param sound The sound to play on the triggering of the trigger - * @return This instance for chaining if desired. - */ - public BlockProperties setBlockSound(BlockSoundTrigger trigger, Sound sound) { - if (trigger == BlockSoundTrigger.CUSTOM_TRIGGER) { - return this; - } - blockSoundSoundMap.put(trigger, sound); - return this; - } - - public BlockProperties setBlockSound(BlockSoundTrigger trigger, String soundResourceString) { - return setBlockSound(trigger, new Sound("", soundResourceString)); - } - - /** - * Sets a sound to an id of choice - * - * @param id The custom id for the sound - * @param sound The sound to associate with the id - * @return This instance for chaining if desired. - */ - public BlockProperties setCustomBlockSound(String id, Sound sound) { - if (!customDefinedSounds.isPresent()) { - customDefinedSounds = Optional.of(HashBiMap.create()); - } - customDefinedSounds.get().put(id, sound); - return this; - } - - /** - * Get the sound associated with a trigger - * - * @param trigger The trigger to get the sound for - * @return The sound object associated with the trigger - */ - public Sound getSound(BlockSoundTrigger trigger) { - if (trigger == BlockSoundTrigger.CUSTOM_TRIGGER) { - return null; - } - if (blockSoundSoundMap.containsKey(trigger)) { - return blockSoundSoundMap.get(trigger); - } - return null; - } - - /** - * Get the sound associated with a custom Id - * - * @param customId The custom id of the sound - * @return The sound object associated with the custom Id - */ - public Sound getCustomSound(String customId) { - if (!customDefinedSounds.isPresent()) { - return null; - } - if (customDefinedSounds.get().containsKey(customId)) { - return customDefinedSounds.get().get(customId); - } - return null; - } - - /** - * Sets that the block should allow light through - * - * @return This instance for chaining if desired. - */ - public BlockProperties setTransparent() { - allowsLightThrough = true; - return this; - } - - /** - * Sets if light should be transmitted through this block - * - * @param allowLightThrough Boolean flag if light should be allowed through - * @return This instance for chaining if desired. - */ - public BlockProperties setLightTransmission(boolean allowLightThrough) { - this.allowsLightThrough = allowLightThrough; - return this; - } - - /** - * Triggers for sounds to play on the location of a block - */ - public enum BlockSoundTrigger { - BREAK, - PLACE, - WALK, - CUSTOM_TRIGGER - } -} diff --git a/src/main/java/nova/core/block/component/BlockProperty.java b/src/main/java/nova/core/block/component/BlockProperty.java new file mode 100644 index 000000000..c8ffcb8ff --- /dev/null +++ b/src/main/java/nova/core/block/component/BlockProperty.java @@ -0,0 +1,231 @@ +package nova.core.block.component; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import nova.core.component.Component; +import nova.core.sound.Sound; + +import java.util.Optional; + +/** + * Block properties. + * + * @author soniex2 + */ +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. + *

+ */ + public static class Hardness extends Component implements BlockProperty { + private double hardness = 1.0; + + /** + * Sets the breaking difficulty. + * + * @param hardness The breaking difficulty. + * @return This instance for chaining if desired. + */ + public Hardness setHardness(double hardness) { + this.hardness = hardness; + return this; + } + + /** + * Gets the breaking difficulty. + * + * @return The breaking difficulty. + */ + public double getHardness() { + return hardness; + } + } + + /** + * The blast resistance of a block. + *

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

+ */ + public static class Resistance extends Component implements BlockProperty { + private double resistance = 1.0; + + /** + * Sets the blast resistance + * + * @param resistance The blast resistance. + * @return This instance for chaining if desired. + */ + public Resistance setResistance(double resistance) { + this.resistance = resistance; + return this; + } + + /** + * Gets the blast resistance. + * + * @return The blast resistance. + */ + public double getResistance() { + return resistance; + } + } + + /** + * The block sounds associated with a block. + * + * @author winsock + */ + public static class BlockSound extends Component implements BlockProperty { + public BiMap blockSoundSoundMap = HashBiMap.create(); + public Optional> customDefinedSounds; + + /** + * Sets a sound to play on a specified trigger. Note to set a {@link BlockSoundTrigger#CUSTOM_TRIGGER} use {@link BlockSound#setCustomBlockSound(String,Sound)} + * + * @param trigger The trigger to set the sound for + * @param sound The sound to play on the triggering of the trigger + * @return This instance for chaining if desired. + */ + public BlockSound setBlockSound(BlockSoundTrigger trigger, Sound sound) { + if (trigger == BlockSoundTrigger.CUSTOM_TRIGGER) { + return this; + } + blockSoundSoundMap.put(trigger, sound); + return this; + } + + /** + * Sets a sound to an id of choice + * + * @param id The custom id for the sound + * @param sound The sound to associate with the id + * @return This instance for chaining if desired. + */ + public BlockSound setCustomBlockSound(String id, Sound sound) { + if (!customDefinedSounds.isPresent()) { + customDefinedSounds = Optional.of(HashBiMap.create()); + } + customDefinedSounds.get().put(id, sound); + return this; + } + + /** + * Get the sound associated with a trigger + * + * @param trigger The trigger to get the sound for + * @return The sound object associated with the trigger + */ + public Sound getSound(BlockSoundTrigger trigger) { + if (trigger == BlockSoundTrigger.CUSTOM_TRIGGER) { + return null; + } + if (blockSoundSoundMap.containsKey(trigger)) { + return blockSoundSoundMap.get(trigger); + } + return null; + } + + /** + * Get the sound associated with a custom Id + * + * @param customId The custom id of the sound + * @return The sound object associated with the custom Id + */ + public Sound getCustomSound(String customId) { + if (!customDefinedSounds.isPresent()) { + return null; + } + if (customDefinedSounds.get().containsKey(customId)) { + return customDefinedSounds.get().get(customId); + } + return null; + } + + /** + * Triggers for sounds to play on the location of a block + */ + public enum BlockSoundTrigger { + BREAK, + PLACE, + WALK, + CUSTOM_TRIGGER + } + + } + + /** + * The opacity associated with a block. + * + * @author winsock + */ + public static class Opacity extends Component implements BlockProperty { + // TODO maybe consider a double for opacity? Where 0 is 100% transparent and 1 is 100% opaque? + + /** + * This boolean determines if the block should allow light through itself or not. + */ + public boolean allowsLightThrough = false; + + /** + * Sets that the block should allow light through + * + * @return This instance for chaining if desired. + */ + public Opacity setTransparent() { + allowsLightThrough = true; + return this; + } + + /** + * Sets if light should be transmitted through this block + * + * @param allowLightThrough Boolean flag if light should be allowed through + * @return This instance for chaining if desired. + */ + public Opacity setLightTransmission(boolean allowLightThrough) { + this.allowsLightThrough = allowLightThrough; + return this; + } + } + + // TODO +// /** +// * Indicates whether the block is replaceable. +// */ +// public static final class Replaceable extends Component implements BlockProperty { +// /** +// * Singleton for Replaceable. +// */ +// private static Replaceable theInstance = null; +// +// /** +// * Gets the singleton for Replaceable. +// * +// * @return The singleton for Replaceable. +// */ +// public static Replaceable instance() { +// if (theInstance == null) { +// theInstance = new Replaceable(); +// } +// +// return theInstance; +// } +// +// private Replaceable() { +// } +// +// @Override +// public boolean equals(Object o) { +// return this == o || o instanceof Replaceable; +// } +// +// @Override +// public int hashCode() { +// return Replaceable.class.hashCode(); +// } +// } +} diff --git a/src/main/java/nova/core/item/ItemBlock.java b/src/main/java/nova/core/item/ItemBlock.java index 62e9e013d..f30af52f5 100644 --- a/src/main/java/nova/core/item/ItemBlock.java +++ b/src/main/java/nova/core/item/ItemBlock.java @@ -20,7 +20,7 @@ import nova.core.block.Block; import nova.core.block.BlockFactory; -import nova.core.block.component.BlockProperties; +import nova.core.block.component.BlockProperty; import nova.core.entity.Entity; import nova.core.util.Direction; import nova.core.world.World; @@ -67,8 +67,8 @@ protected boolean onPostPlace(Entity entity, World world, Vector3D placePos, Dir if (opBlock.isPresent() && opBlock.get().sameType(blockFactory)) { //TODO: What if the block is NOT placed by a player? opBlock.get().events.publish(new Block.PlaceEvent(entity, side, hit, this)); - if (opBlock.get().components.has(BlockProperties.class)) { - world.playSoundAtPosition(placePos, opBlock.get().components.get(BlockProperties.class).getSound(BlockProperties.BlockSoundTrigger.PLACE)); + if (opBlock.get().components.has(BlockProperty.BlockSound.class)) { + world.playSoundAtPosition(placePos, opBlock.get().components.get(BlockProperty.BlockSound.class).getSound(BlockProperty.BlockSound.BlockSoundTrigger.PLACE)); } } From 5e56559d932bca50a691d69bf6e7b545825dfaac Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Wed, 26 Oct 2016 22:06:35 -0200 Subject: [PATCH 2/6] String -> Identifier. WIP. --- .../v17/recipes/MinecraftItemIngredient.java | 2 +- .../mc/forge/v17/recipes/RecipeConverter.java | 2 +- .../v17/wrapper/block/BlockConverter.java | 2 +- .../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 | 4 +- .../v18/recipes/MinecraftItemIngredient.java | 2 +- .../mc/forge/v18/recipes/RecipeConverter.java | 2 +- .../v18/wrapper/block/BlockConverter.java | 2 +- .../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 | 4 +- 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/AbstractIdentifier.java | 46 ++++++++++++++++ .../nova/core/util/id/ClassIdentifier.java | 32 +++++++++++ .../nova/core/util/{ => id}/Identifiable.java | 4 +- .../java/nova/core/util/id/Identifier.java | 19 +++++++ .../nova/core/util/id/StringIdentifier.java | 18 ++++++ .../nova/core/util/id/UUIDIdentifier.java | 29 ++++++++++ .../util/{ => id}/UniqueIdentifiable.java | 6 +- .../java/nova/core/util/registry/Factory.java | 9 ++- .../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, 359 insertions(+), 104 deletions(-) create mode 100644 src/main/java/nova/core/util/id/AbstractIdentifier.java create mode 100644 src/main/java/nova/core/util/id/ClassIdentifier.java rename src/main/java/nova/core/util/{ => id}/Identifiable.java (96%) create mode 100644 src/main/java/nova/core/util/id/Identifier.java create mode 100644 src/main/java/nova/core/util/id/StringIdentifier.java create mode 100644 src/main/java/nova/core/util/id/UUIDIdentifier.java rename src/main/java/nova/core/util/{ => id}/UniqueIdentifiable.java (87%) 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 97582befa..ddf1fbe86 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()); + super(((Item) Game.natives().toNova(itemStack)).getID().asString()); // TODO? } } 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 298f3d266..f02af76db 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()); + return new SpecificItemIngredient(((Item) Game.natives().toNova(ingredient)).getID().asString()); // TODO? } 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 58b2c817a..9e7c845cc 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 @@ -136,7 +136,7 @@ private void registerNovaBlock(BlockFactory blockFactory) { FWBlock blockWrapper = new FWBlock(blockFactory); blockFactoryMap.put(blockFactory, blockWrapper); NovaMinecraft.proxy.registerBlock(blockWrapper); - GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, blockFactory.getID()); + GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, blockFactory.getID().asString()); // TODO? 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 123d2e4f9..b4710f806 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()); + this.setBlockName(dummy.getID().asString()); // TODO? // 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()); + return FWTileLoader.loadTile(dummy.getID().asString()); // TODO? } @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 28f892222..858f4bc37 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,6 +29,8 @@ 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; @@ -144,12 +146,12 @@ public Optional getEntity(String uniqueID) { } @Override - public String getID() { - return world().provider.getDimensionName(); + public Identifier getID() { + return new StringIdentifier(world().provider.getDimensionName()); } @Override public void playSoundAtPosition(Vector3D position, Sound sound) { - world().playSound(position.getX(), position.getY(), position.getZ(), sound.getID(), sound.pitch, sound.volume, false); + world().playSound(position.getX(), position.getY(), position.getZ(), sound.getID().asString(), 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 bc58ff023..83dda3ee3 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,6 +28,8 @@ 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; @@ -88,8 +90,8 @@ public String getUsername() { } @Override - public String getID() { - return entity.getGameProfile().getId().toString(); + public Identifier getID() { + return new UUIDIdentifier(entity.getGameProfile().getId()); } @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 02a7bb50e..9e4a91a4b 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()); + nbt.setString("novaID", wrapped.getID().asString()); // TODO? } @Override public void writeSpawnData(ByteBuf buffer) { //Write the ID of the entity to client - String id = wrapped.getID(); + String id = wrapped.getID().asString(); // TODO? 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 9bb8b6925..08fd8ebae 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(); + return getID().asString(); // TODO? } } 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 7c4e8c8ec..ebc78662b 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()); + setUnlocalizedName(item.getID().asString()); // TODO? 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 969162193..17b988425 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 @@ -106,7 +106,7 @@ public ItemStack toNative(Item item) { if (item instanceof BWItem) { return ((BWItem) item).makeItemStack(item.count()); } else { - ItemFactory itemFactory = Game.items().get(item.getID()).get(); + ItemFactory itemFactory = Game.items().get(item.getID().asString()).get(); // TODO? FWNBTTagCompound tag = new FWNBTTagCompound(item); MinecraftItemMapping mapping = get(itemFactory); @@ -202,7 +202,7 @@ private void registerNOVAItem(ItemFactory itemFactory) { // Don't register ItemBlocks twice if (!(dummy instanceof ItemBlock)) { NovaMinecraft.proxy.registerItem((FWItem) itemWrapper); - GameRegistry.registerItem(itemWrapper, itemFactory.getID()); + GameRegistry.registerItem(itemWrapper, itemFactory.getID().asString()); // TODO? 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 72116bf5e..40701caf8 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()); + super(((Item) Game.natives().toNova(itemStack)).getID().asString()); // TODO? } } 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 cd616f714..8547f577c 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()); + return new SpecificItemIngredient(((Item) Game.natives().toNova(ingredient)).getID().asString()); // TODO? } 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 17514f534..680d891bb 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 @@ -136,7 +136,7 @@ public boolean canReplace() { private void registerNovaBlock(BlockFactory blockFactory) { FWBlock blockWrapper = new FWBlock(blockFactory); blockFactoryMap.put(blockFactory, blockWrapper); - GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, blockFactory.getID()); + GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, blockFactory.getID().asString()); 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 36d9eb71a..8a3a4c6f6 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()); + this.setUnlocalizedName(dummy.getID().asString()); // TODO? // 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()); + FWTile fwTile = FWTileLoader.loadTile(dummy.getID().asString()); // TODO? 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 f7f1326ab..b62c264db 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(); + return sound.getID().asString(); // TODO? } return super.getBreakSound(); } @@ -38,7 +38,7 @@ public String getStepSound() { if (sound.domain.isEmpty() && !sound.name.contains(".")) { return "step." + sound.name; } - return sound.getID(); + return sound.getID().asString(); // TODO? } return super.getStepSound(); } @@ -50,7 +50,7 @@ public String getPlaceSound() { if (sound.domain.isEmpty()) { return sound.name; } - return sound.getID(); + return sound.getID().asString(); // TODO? } // 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 d53baf619..36eea8f77 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,6 +31,8 @@ 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; @@ -153,12 +155,12 @@ public Optional getEntity(String uniqueID) { } @Override - public String getID() { - return world().provider.getDimensionName(); + public Identifier getID() { + return new StringIdentifier(world().provider.getDimensionName()); } @Override public void playSoundAtPosition(Vector3D position, Sound sound) { - world().playSoundEffect(position.getX(), position.getY(), position.getZ(), sound.getID(), sound.volume, sound.pitch); + world().playSoundEffect(position.getX(), position.getY(), position.getZ(), sound.getID().asString(), 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 eb68b58ff..acb33bc20 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,6 +28,8 @@ 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; @@ -88,8 +90,8 @@ public String getUsername() { } @Override - public String getID() { - return entity.getGameProfile().getId().toString(); + public Identifier getID() { + return new UUIDIdentifier(entity.getGameProfile().getId()); } @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 d01763dc2..72ae58935 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()); + nbt.setString("novaID", wrapped.getID().asString()); // TODO? } @Override public void writeSpawnData(ByteBuf buffer) { //Write the ID of the entity to client - String id = wrapped.getID(); + String id = wrapped.getID().asString(); // TODO? 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 7476b9d26..490c5b996 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(); + return getID().asString(); // TODO? } } 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 6ce3b84a4..61b7b9adc 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()); + setUnlocalizedName(item.getID().asString()); // TODO? 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 793bb2fd1..2b5c54df3 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 @@ -107,7 +107,7 @@ public ItemStack toNative(Item item) { if (item instanceof BWItem) { return ((BWItem) item).makeItemStack(item.count()); } else { - ItemFactory itemFactory = Game.items().get(item.getID()).get(); + ItemFactory itemFactory = Game.items().get(item.getID().asString()).get();// TODO? FWNBTTagCompound tag = new FWNBTTagCompound(item); MinecraftItemMapping mapping = get(itemFactory); @@ -204,7 +204,7 @@ private void registerNOVAItem(ItemFactory itemFactory) { // Don't register ItemBlocks twice if (!(dummy instanceof ItemBlock)) { NovaMinecraft.proxy.registerItem((FWItem) itemWrapper); - GameRegistry.registerItem(itemWrapper, itemFactory.getID()); + GameRegistry.registerItem(itemWrapper, itemFactory.getID().asString()); if (dummy.components.has(Category.class) && FMLCommonHandler.instance().getSide().isClient()) { //Add into creative tab diff --git a/src/main/java/nova/core/block/Block.java b/src/main/java/nova/core/block/Block.java index 7b7f4fb6a..1e0e04bf4 100644 --- a/src/main/java/nova/core/block/Block.java +++ b/src/main/java/nova/core/block/Block.java @@ -30,7 +30,8 @@ import nova.core.item.Item; import nova.core.item.ItemFactory; import nova.core.util.Direction; -import nova.core.util.Identifiable; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; import nova.core.world.World; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -59,7 +60,7 @@ public final BlockFactory getFactory() { } @Override - public final String getID() { + public final Identifier 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 95c8002d4..f8cd3a0df 100644 --- a/src/main/java/nova/core/component/Category.java +++ b/src/main/java/nova/core/component/Category.java @@ -21,7 +21,9 @@ package nova.core.component; import nova.core.item.Item; -import nova.core.util.Identifiable; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; +import nova.core.util.id.StringIdentifier; import java.util.Optional; @@ -46,7 +48,7 @@ public Category(String name) { } @Override - public String getID() { - return name; + public Identifier getID() { + return new StringIdentifier(name); } } diff --git a/src/main/java/nova/core/component/Component.java b/src/main/java/nova/core/component/Component.java index df2ecd0d4..a0a854b6a 100644 --- a/src/main/java/nova/core/component/Component.java +++ b/src/main/java/nova/core/component/Component.java @@ -21,7 +21,9 @@ package nova.core.component; import nova.core.component.exception.ComponentException; -import nova.core.util.Identifiable; +import nova.core.util.id.ClassIdentifier; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; /** * Base interface for all Components. @@ -51,7 +53,7 @@ public void onProviderChange() { } @Override - public String getID() { - return getClass().getSimpleName(); + public Identifier getID() { + return new ClassIdentifier(getClass()); } } diff --git a/src/main/java/nova/core/component/fluid/Fluid.java b/src/main/java/nova/core/component/fluid/Fluid.java index 809e968ca..675c36a57 100644 --- a/src/main/java/nova/core/component/fluid/Fluid.java +++ b/src/main/java/nova/core/component/fluid/Fluid.java @@ -24,7 +24,9 @@ import nova.core.retention.Data; import nova.core.retention.Storable; import nova.core.retention.Store; -import nova.core.util.Identifiable; +import nova.core.util.id.AbstractIdentifier; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; import nova.internal.core.Game; import java.util.Optional; @@ -126,7 +128,7 @@ public boolean sameType(Fluid stack) { } @Override - public final String getID() { + public final Identifier getID() { return factory.getID(); } @@ -138,12 +140,12 @@ public int hashCode() { @Override public void save(Data data) { Storable.super.save(data); - data.put("id", factory.getID()); + data.put("id", factory.getID().asString()); // TODO? } @Override public void load(Data data) { Storable.super.load(data); - factory = Game.fluids().get(data.get("id")).get(); + factory = Game.fluids().get(data.get("id")).get(); // FIXME } } diff --git a/src/main/java/nova/core/component/misc/Damageable.java b/src/main/java/nova/core/component/misc/Damageable.java index 5f4c63c7d..e5e6c9771 100644 --- a/src/main/java/nova/core/component/misc/Damageable.java +++ b/src/main/java/nova/core/component/misc/Damageable.java @@ -21,7 +21,9 @@ package nova.core.component.misc; import nova.core.component.Component; -import nova.core.util.Identifiable; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; +import nova.core.util.id.StringIdentifier; /** * Applied to objects that can take damage. @@ -46,8 +48,8 @@ public DamageType(String name) { } @Override - public String getID() { - return name; + public Identifier getID() { + return new StringIdentifier(name); } } } diff --git a/src/main/java/nova/core/entity/Entity.java b/src/main/java/nova/core/entity/Entity.java index c0943e100..e8edd4958 100644 --- a/src/main/java/nova/core/entity/Entity.java +++ b/src/main/java/nova/core/entity/Entity.java @@ -24,8 +24,10 @@ import nova.core.component.ComponentProvider; import nova.core.component.misc.FactoryProvider; import nova.core.component.transform.EntityTransform; -import nova.core.util.Identifiable; -import nova.core.util.UniqueIdentifiable; +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.world.World; import org.apache.commons.math3.geometry.euclidean.threed.Rotation; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; @@ -96,12 +98,12 @@ public final EntityFactory getFactory() { } @Override - public final String getID() { + public final Identifier getID() { return getFactory().getID(); } @Override - public String getUniqueID() { + public UUIDIdentifier 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 61f6c86e1..255314bc7 100644 --- a/src/main/java/nova/core/item/Item.java +++ b/src/main/java/nova/core/item/Item.java @@ -27,7 +27,8 @@ import nova.core.render.Color; import nova.core.retention.Storable; import nova.core.util.Direction; -import nova.core.util.Identifiable; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import java.util.List; @@ -50,7 +51,7 @@ public final ItemFactory getFactory() { } @Override - public final String getID() { + public final Identifier 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 a31f83599..976b927ac 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.Identifiable; +import nova.core.util.id.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 d31b79dcb..a95d91e6c 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()).get(); + return registry.get(block.getID().asString()).get(); // TODO } public Optional getBlockFromItem(Item item) { - return blockManager.get().get(item.getID()); + return blockManager.get().get(item.getID().asString()); // TODO } @Override diff --git a/src/main/java/nova/core/network/Packet.java b/src/main/java/nova/core/network/Packet.java index 2ad0c0484..258c5c60f 100644 --- a/src/main/java/nova/core/network/Packet.java +++ b/src/main/java/nova/core/network/Packet.java @@ -26,16 +26,12 @@ import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; -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.*; import java.util.stream.IntStream; /** * A packet of data that is writable or readable. + * * @author Calclavia */ public interface Packet { @@ -47,6 +43,7 @@ public interface Packet { /** * Sets the ID of this packet, allowing it to be sent accordingly. + * * @return The packet itself. */ Packet setID(int id); @@ -58,6 +55,7 @@ public interface Packet { /** * Writes an arbitrary object, automatically finding the relevant class. + * * @param data Object to write * @return This packet */ @@ -82,6 +80,8 @@ 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,6 +101,8 @@ 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); } @@ -115,6 +117,7 @@ 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} @@ -125,6 +128,7 @@ 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} @@ -135,6 +139,7 @@ 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} @@ -144,6 +149,7 @@ 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} @@ -154,6 +160,7 @@ 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} @@ -164,6 +171,7 @@ 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} @@ -174,6 +182,7 @@ 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} @@ -184,6 +193,7 @@ 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} @@ -199,6 +209,11 @@ 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) @@ -258,6 +273,7 @@ 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} */ @@ -266,6 +282,7 @@ 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} */ @@ -274,6 +291,7 @@ 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} */ @@ -282,6 +300,7 @@ 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} */ @@ -290,6 +309,7 @@ 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} */ @@ -298,6 +318,7 @@ 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} */ @@ -306,6 +327,7 @@ 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} */ @@ -314,6 +336,7 @@ 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} */ @@ -322,6 +345,7 @@ 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} */ @@ -330,6 +354,7 @@ 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} */ @@ -426,6 +451,20 @@ 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()); @@ -459,6 +498,10 @@ 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 6648c79ce..4587cbc5d 100644 --- a/src/main/java/nova/core/recipes/crafting/CraftingRecipeManager.java +++ b/src/main/java/nova/core/recipes/crafting/CraftingRecipeManager.java @@ -24,6 +24,7 @@ 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; @@ -37,6 +38,7 @@ * @author Stan Hebben */ public class CraftingRecipeManager { + // TODO switch this to using Identifiers private final RecipeManager recipeManager; private final List dynamicRecipes; private final Multimap staticRecipes; @@ -86,7 +88,7 @@ public Optional getRecipe(CraftingGrid grid) { return Optional.empty(); } - String firstItemId = firstItem.get().getID(); + String firstItemId = firstItem.get().getID().asString(); // TODO (this is BAD) 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 6a4661d8e..52d3a473c 100644 --- a/src/main/java/nova/core/recipes/crafting/OreItemIngredient.java +++ b/src/main/java/nova/core/recipes/crafting/OreItemIngredient.java @@ -21,6 +21,7 @@ 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; @@ -46,7 +47,7 @@ public String getName() { @Override public Optional> getPossibleItemIds() { - return Optional.of(Game.itemDictionary().get(name).stream().map(Item::getID).collect(Collectors.toList())); + return Optional.of(Game.itemDictionary().get(name).stream().map(Item::getID).map(Identifier::asString).collect(Collectors.toList())); // TODO? } @Override diff --git a/src/main/java/nova/core/render/Asset.java b/src/main/java/nova/core/render/Asset.java index b5f9b96ec..5aafccaa4 100644 --- a/src/main/java/nova/core/render/Asset.java +++ b/src/main/java/nova/core/render/Asset.java @@ -20,7 +20,9 @@ package nova.core.render; -import nova.core.util.Identifiable; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; +import nova.core.util.id.StringIdentifier; /** * @author Calclavia @@ -48,7 +50,7 @@ public boolean equals(Object obj) { } @Override - public final String getID() { - return domain + ":" + name; + public final Identifier getID() { + return new StringIdentifier(domain + ":" + name); } } diff --git a/src/main/java/nova/core/render/RenderManager.java b/src/main/java/nova/core/render/RenderManager.java index c25f6b8eb..4098a8c87 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()); + Optional itemTexture = itemTextures.get(texture.getID().asString()); // TODO? 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()); + Optional blockTexture = blockTextures.get(texture.getID().asString()); // TODO? 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()); + Optional entityTexture = entityTextures.get(texture.getID().asString()); // TODO? 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()); + Optional modelProviderCheck = modelProviders.get(modelProvider.getID().asString()); // TODO? 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 ee7596cfa..4c62b3c32 100644 --- a/src/main/java/nova/core/render/texture/Texture.java +++ b/src/main/java/nova/core/render/texture/Texture.java @@ -18,7 +18,9 @@ * along with NOVA. If not, see . */package nova.core.render.texture; -import nova.core.util.Identifiable; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; +import nova.core.util.id.StringIdentifier; import nova.core.util.math.Vector2DUtil; import nova.internal.core.Game; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; @@ -60,8 +62,8 @@ public String toString() { } @Override - public final String getID() { - return getResource(); + public final Identifier getID() { + return new StringIdentifier(getResource()); } @Override diff --git a/src/main/java/nova/core/retention/Data.java b/src/main/java/nova/core/retention/Data.java index 71d689c74..f3e2cea52 100755 --- a/src/main/java/nova/core/retention/Data.java +++ b/src/main/java/nova/core/retention/Data.java @@ -23,10 +23,7 @@ import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; import org.apache.commons.math3.geometry.euclidean.twod.Vector2D; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.*; /** * The data class is capable of storing named data. @@ -66,7 +63,9 @@ public class Data extends HashMap { Data.class, Collection.class, Vector3D.class, - Vector2D.class }; + Vector2D.class, + Class.class, + UUID.class }; public String className; @@ -108,6 +107,10 @@ 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); } @@ -165,6 +168,14 @@ 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); } @@ -214,4 +225,19 @@ 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 84fcfbed7..2e1fdb586 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(); + Class type = field.getType(); // FIXME Object fieldValue = field.get(this); Object value = data.get(name); - if (Storable.class.isAssignableFrom(type) || value instanceof Data) { - if (fieldValue instanceof Storable && value instanceof Data) { + 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 //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 127bc23d3..6dc35697d 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.Identifiable; +import nova.core.util.id.Identifiable; /** * An object representing a sound. (including the modification to pitch and volume, etc...) diff --git a/src/main/java/nova/core/util/id/AbstractIdentifier.java b/src/main/java/nova/core/util/id/AbstractIdentifier.java new file mode 100644 index 000000000..651b5438d --- /dev/null +++ b/src/main/java/nova/core/util/id/AbstractIdentifier.java @@ -0,0 +1,46 @@ +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 new file mode 100644 index 000000000..8fbc7466c --- /dev/null +++ b/src/main/java/nova/core/util/id/ClassIdentifier.java @@ -0,0 +1,32 @@ +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/Identifiable.java b/src/main/java/nova/core/util/id/Identifiable.java similarity index 96% rename from src/main/java/nova/core/util/Identifiable.java rename to src/main/java/nova/core/util/id/Identifiable.java index e98159e43..3ff8c86ff 100644 --- a/src/main/java/nova/core/util/Identifiable.java +++ b/src/main/java/nova/core/util/id/Identifiable.java @@ -18,7 +18,7 @@ * along with NOVA. If not, see . */ -package nova.core.util; +package nova.core.util.id; /** * A generic interface signifying that this object is identifiable @@ -30,7 +30,7 @@ public interface Identifiable { * * @return the ID */ - String getID(); + Identifier getID(); /** * Compares the ID of the Identifialbes diff --git a/src/main/java/nova/core/util/id/Identifier.java b/src/main/java/nova/core/util/id/Identifier.java new file mode 100644 index 000000000..7453cef99 --- /dev/null +++ b/src/main/java/nova/core/util/id/Identifier.java @@ -0,0 +1,19 @@ +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 new file mode 100644 index 000000000..f52b45030 --- /dev/null +++ b/src/main/java/nova/core/util/id/StringIdentifier.java @@ -0,0 +1,18 @@ +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 new file mode 100644 index 000000000..754c214fd --- /dev/null +++ b/src/main/java/nova/core/util/id/UUIDIdentifier.java @@ -0,0 +1,29 @@ +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/UniqueIdentifiable.java b/src/main/java/nova/core/util/id/UniqueIdentifiable.java similarity index 87% rename from src/main/java/nova/core/util/UniqueIdentifiable.java rename to src/main/java/nova/core/util/id/UniqueIdentifiable.java index a795892d1..ae37ad60f 100644 --- a/src/main/java/nova/core/util/UniqueIdentifiable.java +++ b/src/main/java/nova/core/util/id/UniqueIdentifiable.java @@ -18,7 +18,9 @@ * along with NOVA. If not, see . */ -package nova.core.util; +package nova.core.util.id; + +import nova.core.util.id.UUIDIdentifier; /** * A generic interface signifying that this object is uniquely identifiable @@ -30,5 +32,5 @@ public interface UniqueIdentifiable { * * @return the ID */ - String getUniqueID(); + UUIDIdentifier getUniqueID(); // TODO maybe this should return a simple Identifier } diff --git a/src/main/java/nova/core/util/registry/Factory.java b/src/main/java/nova/core/util/registry/Factory.java index 7ce169d1e..2034a3168 100644 --- a/src/main/java/nova/core/util/registry/Factory.java +++ b/src/main/java/nova/core/util/registry/Factory.java @@ -20,7 +20,10 @@ package nova.core.util.registry; -import nova.core.util.Identifiable; +import nova.core.component.ComponentProvider; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; +import nova.core.util.id.StringIdentifier; import java.util.function.Function; import java.util.function.Supplier; @@ -78,7 +81,7 @@ public T build() { return processor.apply(constructor.get()); } - public String getID() { - return id; + public Identifier getID() { + return new StringIdentifier(id); } } diff --git a/src/main/java/nova/core/util/registry/FactoryManager.java b/src/main/java/nova/core/util/registry/FactoryManager.java index 20a38d558..8c2281833 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.Identifiable; +import nova.core.util.id.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 bf25553d9..24e724416 100644 --- a/src/main/java/nova/core/util/registry/Registry.java +++ b/src/main/java/nova/core/util/registry/Registry.java @@ -19,7 +19,8 @@ */package nova.core.util.registry; import com.google.common.collect.HashBiMap; -import nova.core.util.Identifiable; +import nova.core.util.id.Identifiable; +import nova.core.util.id.Identifier; import java.util.Iterator; import java.util.Optional; @@ -32,6 +33,7 @@ * @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() { @@ -45,7 +47,7 @@ public Registry() { * @return Given object */ public T register(T object) { - objects.put(object.getID(), object); + objects.put(object.getID().asString(), object); return object; } diff --git a/src/main/java/nova/core/world/World.java b/src/main/java/nova/core/world/World.java index d89565221..22832ac35 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.Identifiable; +import nova.core.util.id.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 a69500bc8..33569e31c 100644 --- a/src/test/java/nova/core/util/MockIdentifiable.java +++ b/src/test/java/nova/core/util/MockIdentifiable.java @@ -20,6 +20,10 @@ 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; @@ -28,12 +32,12 @@ public MockIdentifiable(String ID) { } @Override - public String getID() { - return ID; + public Identifier getID() { + return new StringIdentifier(ID); } @Override public String toString() { - return getID(); + return getID().asString(); } } diff --git a/src/test/java/nova/core/util/RegistryTest.java b/src/test/java/nova/core/util/RegistryTest.java index 79afd10d8..9e80a9313 100644 --- a/src/test/java/nova/core/util/RegistryTest.java +++ b/src/test/java/nova/core/util/RegistryTest.java @@ -20,6 +20,8 @@ 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; @@ -41,8 +43,8 @@ public void testRegistry() throws Exception { assertThat(registry.contains("ID1")).isTrue(); assertThat(registry.contains("ID2")).isTrue(); - assertThat(registry.get("ID1").get().getID()).isEqualTo("ID1"); - assertThat(registry.get("ID2").get().getID()).isEqualTo("ID2"); + 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()).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 c4443bdb5..522e878ab 100644 --- a/src/test/java/nova/testutils/FakeWorld.java +++ b/src/test/java/nova/testutils/FakeWorld.java @@ -28,6 +28,8 @@ 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; @@ -131,7 +133,7 @@ public void playSoundAtPosition(Vector3D position, Sound sound) { } @Override - public String getID() { - return "fakeWorld"; + public Identifier getID() { + return new StringIdentifier("fakeWorld"); } } From cc6df4e12aa7a768ede8955a2298d76994b8dcf5 Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Fri, 6 Jan 2017 17:58:18 +0100 Subject: [PATCH 3/6] Create ItemEvent and move some events there --- .../forge/v17/wrapper/item/ItemConverter.java | 11 +++-- .../forge/v18/wrapper/item/ItemConverter.java | 11 +++-- src/main/java/nova/core/event/ItemEvent.java | 45 +++++++++++++++++++ src/main/java/nova/core/item/ItemManager.java | 21 +++------ .../core/item/event/ItemIDNotFoundEvent.java | 43 ------------------ 5 files changed, 61 insertions(+), 70 deletions(-) create mode 100644 src/main/java/nova/core/event/ItemEvent.java delete mode 100644 src/main/java/nova/core/item/event/ItemIDNotFoundEvent.java 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 17b988425..98bd59df8 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 @@ -27,11 +27,10 @@ import net.minecraft.item.ItemStack; import nova.core.block.BlockFactory; import nova.core.component.Category; +import nova.core.event.ItemEvent; import nova.core.item.Item; import nova.core.item.ItemBlock; import nova.core.item.ItemFactory; -import nova.core.item.ItemManager; -import nova.core.item.event.ItemIDNotFoundEvent; import nova.core.loader.Loadable; import nova.core.nativewrapper.NativeConverter; import nova.core.retention.Data; @@ -169,10 +168,10 @@ public void preInit() { private void registerNOVAItemsToMinecraft() { //There should be no items registered during Native Converter preInit() // item.registry.forEach(this::registerNOVAItem); - Game.events().on(ItemManager.ItemRegistrationEvent.class).bind(this::onItemRegistered); + Game.events().on(ItemEvent.Register.class).bind(this::onItemRegistered); } - private void onItemRegistered(ItemManager.ItemRegistrationEvent event) { + private void onItemRegistered(ItemEvent.Register event) { registerNOVAItem(event.itemFactory); } @@ -232,10 +231,10 @@ private void registerMinecraftItemsToNOVA() { } private void registerSubtypeResolution() { - Game.events().on(ItemIDNotFoundEvent.class).bind(this::onIDNotFound); + Game.events().on(ItemEvent.IDNotFound.class).bind(this::onIDNotFound); } - private void onIDNotFound(ItemIDNotFoundEvent event) { + private void onIDNotFound(ItemEvent.IDNotFound event) { // if item minecraft:planks:2 is detected, this code will register minecraft:planks:2 dynamically // we cannot do this up front since there is **NO** reliable way to get the sub-items of an item 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 2b5c54df3..d28013574 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 @@ -28,11 +28,10 @@ import net.minecraftforge.fml.common.registry.GameRegistry; import nova.core.block.BlockFactory; import nova.core.component.Category; +import nova.core.event.ItemEvent; import nova.core.item.Item; import nova.core.item.ItemBlock; import nova.core.item.ItemFactory; -import nova.core.item.ItemManager; -import nova.core.item.event.ItemIDNotFoundEvent; import nova.core.loader.Loadable; import nova.core.nativewrapper.NativeConverter; import nova.core.retention.Data; @@ -171,10 +170,10 @@ public void preInit() { private void registerNOVAItemsToMinecraft() { //There should be no items registered during Native Converter preInit() // item.registry.forEach(this::registerNOVAItem); - Game.events().on(ItemManager.ItemRegistrationEvent.class).bind(this::onItemRegistered); + Game.events().on(ItemEvent.Register.class).bind(this::onItemRegistered); } - private void onItemRegistered(ItemManager.ItemRegistrationEvent event) { + private void onItemRegistered(ItemEvent.Register event) { registerNOVAItem(event.itemFactory); } @@ -234,10 +233,10 @@ private void registerMinecraftItemsToNOVA() { } private void registerSubtypeResolution() { - Game.events().on(ItemIDNotFoundEvent.class).bind(this::onIDNotFound); + Game.events().on(ItemEvent.IDNotFound.class).bind(this::onIDNotFound); } - private void onIDNotFound(ItemIDNotFoundEvent event) { + private void onIDNotFound(ItemEvent.IDNotFound event) { // if item minecraft:planks:2 is detected, this code will register minecraft:planks:2 dynamically // we cannot do this up front since there is **NO** reliable way to get the sub-items of an item diff --git a/src/main/java/nova/core/event/ItemEvent.java b/src/main/java/nova/core/event/ItemEvent.java new file mode 100644 index 000000000..78a808e71 --- /dev/null +++ b/src/main/java/nova/core/event/ItemEvent.java @@ -0,0 +1,45 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package nova.core.event; + +import nova.core.event.bus.CancelableEvent; +import nova.core.event.bus.Event; +import nova.core.item.ItemFactory; + +/** + * @author ExE Boss + */ +public abstract class ItemEvent extends CancelableEvent { + + public static class Register extends CancelableEvent { + public ItemFactory itemFactory; + + public Register(ItemFactory itemFactory) { + this.itemFactory = itemFactory; + } + } + + /** + * @author Stan + */ + public static class IDNotFound extends Event { + public final String id; + + private ItemFactory remappedFactory = null; + + public IDNotFound(String id) { + this.id = id; + } + + public ItemFactory getRemappedFactory() { + return remappedFactory; + } + + public void setRemappedFactory(ItemFactory remappedFactory) { + this.remappedFactory = remappedFactory; + } + } +} diff --git a/src/main/java/nova/core/item/ItemManager.java b/src/main/java/nova/core/item/ItemManager.java index a95d91e6c..cc22ec355 100644 --- a/src/main/java/nova/core/item/ItemManager.java +++ b/src/main/java/nova/core/item/ItemManager.java @@ -22,8 +22,7 @@ import nova.core.block.BlockFactory; import nova.core.block.BlockManager; -import nova.core.event.bus.CancelableEvent; -import nova.core.item.event.ItemIDNotFoundEvent; +import nova.core.event.ItemEvent; import nova.core.util.registry.FactoryManager; import nova.core.util.registry.Registry; import nova.internal.core.Game; @@ -52,9 +51,10 @@ public ItemFactory register(String id, Supplier constructor) { @Override public ItemFactory register(ItemFactory factory) { - registry.register(factory); - Game.events().publish(new ItemRegistrationEvent(factory)); - return factory; + ItemEvent.Register event = new ItemEvent.Register(factory); + Game.events().publish(event); + registry.register(event.itemFactory); + return event.itemFactory; } public ItemFactory getItemFromBlock(BlockFactory block) { @@ -68,7 +68,7 @@ public Optional getBlockFromItem(Item item) { @Override public Optional get(String name) { if (!registry.contains(name)) { - ItemIDNotFoundEvent event = new ItemIDNotFoundEvent(name); + ItemEvent.IDNotFound event = new ItemEvent.IDNotFound(name); Game.events().publish(event); if (event.getRemappedFactory() != null) { @@ -79,15 +79,6 @@ public Optional get(String name) { return registry.get(name); } - //TODO: Move to item event - public class ItemRegistrationEvent extends CancelableEvent { - public final ItemFactory itemFactory; - - public ItemRegistrationEvent(ItemFactory itemFactory) { - this.itemFactory = itemFactory; - } - } - @Override public void init() { Game.events().publish(new Init(this)); diff --git a/src/main/java/nova/core/item/event/ItemIDNotFoundEvent.java b/src/main/java/nova/core/item/event/ItemIDNotFoundEvent.java deleted file mode 100644 index 160eaf06b..000000000 --- a/src/main/java/nova/core/item/event/ItemIDNotFoundEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2015 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.item.event; - -import nova.core.event.bus.Event; -import nova.core.item.ItemFactory; - -/** - * @author Stan - */ -public class ItemIDNotFoundEvent extends Event { - public final String id; - - private ItemFactory remappedFactory = null; - - public ItemIDNotFoundEvent(String id) { - this.id = id; - } - - public ItemFactory getRemappedFactory() { - return remappedFactory; - } - - public void setRemappedFactory(ItemFactory remappedFactory) { - this.remappedFactory = remappedFactory; - } -} From 14157ef351efcd25ce07036d0bf6a77da7d442f4 Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Fri, 6 Jan 2017 18:02:56 +0100 Subject: [PATCH 4/6] Fix license header --- src/main/java/nova/core/event/ItemEvent.java | 21 +++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/java/nova/core/event/ItemEvent.java b/src/main/java/nova/core/event/ItemEvent.java index 78a808e71..008a1d9fc 100644 --- a/src/main/java/nova/core/event/ItemEvent.java +++ b/src/main/java/nova/core/event/ItemEvent.java @@ -1,8 +1,23 @@ /* - * To change this license header, choose License Headers in Project Properties. - * To change this template file, choose Tools | Templates - * and open the template in the editor. + * 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.event; import nova.core.event.bus.CancelableEvent; From e25bfc60f3351f1fc8b1a8d2cbc06da7f5ed93dc Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Fri, 6 Jan 2017 18:47:32 +0100 Subject: [PATCH 5/6] Add javadoc to the event classes --- src/main/java/nova/core/event/BlockEvent.java | 12 +++++++++++- src/main/java/nova/core/event/EntityEvent.java | 2 +- src/main/java/nova/core/event/ItemEvent.java | 10 ++++++++++ src/main/java/nova/core/event/ServerEvent.java | 4 ++-- src/main/java/nova/core/event/WorldEvent.java | 7 +++++-- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/main/java/nova/core/event/BlockEvent.java b/src/main/java/nova/core/event/BlockEvent.java index 68978201e..e73138b05 100644 --- a/src/main/java/nova/core/event/BlockEvent.java +++ b/src/main/java/nova/core/event/BlockEvent.java @@ -26,6 +26,9 @@ import nova.core.world.World; import org.apache.commons.math3.geometry.euclidean.threed.Vector3D; +/** + * All events related to the block. + */ public abstract class BlockEvent extends CancelableEvent { //The world public final World world; @@ -37,6 +40,13 @@ public BlockEvent(World world, Vector3D position) { this.position = position; } + /** + * Event is triggered when a BlockFactory is registered. + * + * @see BlockFactory + * @see nova.core.block.BlockManager#register(nova.core.block.BlockFactory) + * @see nova.core.block.BlockManager#register(java.lang.String, java.util.function.Supplier) + */ public static class Register extends CancelableEvent { public BlockFactory blockFactory; @@ -46,7 +56,7 @@ public Register(BlockFactory blockFactory) { } /** - * Called when a block in the world changes. + * Event is triggered when a block in the world changes. */ public static class Change extends BlockEvent { diff --git a/src/main/java/nova/core/event/EntityEvent.java b/src/main/java/nova/core/event/EntityEvent.java index 608bbf484..04b68bf12 100644 --- a/src/main/java/nova/core/event/EntityEvent.java +++ b/src/main/java/nova/core/event/EntityEvent.java @@ -24,7 +24,7 @@ import nova.core.event.bus.CancelableEvent; /** - * All events related to the entity + * All events related to the entity. * @author Calclavia */ public class EntityEvent extends CancelableEvent { diff --git a/src/main/java/nova/core/event/ItemEvent.java b/src/main/java/nova/core/event/ItemEvent.java index 008a1d9fc..e910b7638 100644 --- a/src/main/java/nova/core/event/ItemEvent.java +++ b/src/main/java/nova/core/event/ItemEvent.java @@ -25,10 +25,18 @@ import nova.core.item.ItemFactory; /** + * All events related to the item. * @author ExE Boss */ public abstract class ItemEvent extends CancelableEvent { + /** + * Event is triggered when an ItemFactory is registered. + * + * @see ItemFactory + * @see nova.core.item.ItemManager#register(nova.core.item.ItemFactory) + * @see nova.core.item.ItemManager#register(java.lang.String, java.util.function.Supplier) + */ public static class Register extends CancelableEvent { public ItemFactory itemFactory; @@ -38,6 +46,8 @@ public Register(ItemFactory itemFactory) { } /** + * Event is triggered when an Item ID is not found. + * * @author Stan */ public static class IDNotFound extends Event { diff --git a/src/main/java/nova/core/event/ServerEvent.java b/src/main/java/nova/core/event/ServerEvent.java index a5ce5057f..a078a1421 100644 --- a/src/main/java/nova/core/event/ServerEvent.java +++ b/src/main/java/nova/core/event/ServerEvent.java @@ -28,14 +28,14 @@ */ public abstract class ServerEvent extends Event { /** - * Called when the server starts running + * Event is triggered when the server starts running. */ public static class Start extends ServerEvent { } /** - * Called when the server stops running. + * Event is triggered when the server stops running. */ public static class Stop extends ServerEvent { diff --git a/src/main/java/nova/core/event/WorldEvent.java b/src/main/java/nova/core/event/WorldEvent.java index cf148530c..c97e4af93 100644 --- a/src/main/java/nova/core/event/WorldEvent.java +++ b/src/main/java/nova/core/event/WorldEvent.java @@ -23,6 +23,9 @@ import nova.core.event.bus.Event; import nova.core.world.World; +/** + * All events related to the world. + */ public abstract class WorldEvent extends Event { public final World world; @@ -31,7 +34,7 @@ public WorldEvent(World world) { } /** - * Called when a world loads. + * Event is triggered when a world loads. */ public static class Load extends WorldEvent { public Load(World world) { @@ -40,7 +43,7 @@ public Load(World world) { } /** - * Called when a world unloads. + * Event is triggered when a world unloads. */ public static class Unload extends WorldEvent { public Unload(World world) { From 6d7327e2c170497823cde37dbda601384e3a016a Mon Sep 17 00:00:00 2001 From: ExE Boss Date: Sat, 7 Jan 2017 19:06:36 +0100 Subject: [PATCH 6/6] Remove dependency on #229 --- .../v17/recipes/MinecraftItemIngredient.java | 2 +- .../mc/forge/v17/recipes/RecipeConverter.java | 2 +- .../v17/wrapper/block/BlockConverter.java | 2 +- .../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 | 4 +- .../v18/recipes/MinecraftItemIngredient.java | 2 +- .../mc/forge/v18/recipes/RecipeConverter.java | 2 +- .../v18/wrapper/block/BlockConverter.java | 2 +- .../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 | 4 +- 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 | 9 +-- .../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, 104 insertions(+), 359 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 9e7c845cc..58b2c817a 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 @@ -136,7 +136,7 @@ private void registerNovaBlock(BlockFactory blockFactory) { FWBlock blockWrapper = new FWBlock(blockFactory); blockFactoryMap.put(blockFactory, blockWrapper); NovaMinecraft.proxy.registerBlock(blockWrapper); - GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, blockFactory.getID().asString()); // TODO? + GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, 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 98bd59df8..f6dd217f5 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 @@ -105,7 +105,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); @@ -201,7 +201,7 @@ private void registerNOVAItem(ItemFactory itemFactory) { // Don't register ItemBlocks twice if (!(dummy instanceof ItemBlock)) { NovaMinecraft.proxy.registerItem((FWItem) itemWrapper); - GameRegistry.registerItem(itemWrapper, itemFactory.getID().asString()); // TODO? + GameRegistry.registerItem(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 680d891bb..17514f534 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 @@ -136,7 +136,7 @@ public boolean canReplace() { private void registerNovaBlock(BlockFactory blockFactory) { FWBlock blockWrapper = new FWBlock(blockFactory); blockFactoryMap.put(blockFactory, blockWrapper); - GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, blockFactory.getID().asString()); + GameRegistry.registerBlock(blockWrapper, FWItemBlock.class, 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 d28013574..c496eaa89 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 @@ -106,7 +106,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); @@ -203,7 +203,7 @@ private void registerNOVAItem(ItemFactory itemFactory) { // Don't register ItemBlocks twice if (!(dummy instanceof ItemBlock)) { NovaMinecraft.proxy.registerItem((FWItem) itemWrapper); - GameRegistry.registerItem(itemWrapper, itemFactory.getID().asString()); + GameRegistry.registerItem(itemWrapper, itemFactory.getID()); if (dummy.components.has(Category.class) && FMLCommonHandler.instance().getSide().isClient()) { //Add into creative tab 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 3ff8c86ff..e98159e43 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 2034a3168..7ce169d1e 100644 --- a/src/main/java/nova/core/util/registry/Factory.java +++ b/src/main/java/nova/core/util/registry/Factory.java @@ -20,10 +20,7 @@ package nova.core.util.registry; -import nova.core.component.ComponentProvider; -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 +78,7 @@ public T build() { return processor.apply(constructor.get()); } - 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"; } }