From b40b206bf5a24457cad2f12672eaea1f99479529 Mon Sep 17 00:00:00 2001 From: nossr50 Date: Sat, 9 Feb 2019 19:38:31 -0800 Subject: [PATCH] Fleshing out Abstractions for World, Location, Block, BlockState --- .../com/gmail/nossr50/datatypes/Block.java | 10 ----- .../nossr50/datatypes/BlockProperty.java | 8 ---- .../gmail/nossr50/datatypes/BlockState.java | 8 ---- .../com/gmail/nossr50/datatypes/Location.java | 32 ++++++++++++++ .../com/gmail/nossr50/datatypes/Property.java | 9 ++++ .../com/gmail/nossr50/datatypes/World.java | 5 +++ .../gmail/nossr50/datatypes/block/Block.java | 38 ++++++++++++++++ .../nossr50/datatypes/block/BlockState.java | 44 +++++++++++++++++++ .../TargetMinecraftVersion.java | 4 +- 9 files changed, 129 insertions(+), 29 deletions(-) delete mode 100644 core/src/main/java/com/gmail/nossr50/datatypes/Block.java delete mode 100644 core/src/main/java/com/gmail/nossr50/datatypes/BlockProperty.java delete mode 100644 core/src/main/java/com/gmail/nossr50/datatypes/BlockState.java create mode 100644 core/src/main/java/com/gmail/nossr50/datatypes/Location.java create mode 100644 core/src/main/java/com/gmail/nossr50/datatypes/Property.java create mode 100644 core/src/main/java/com/gmail/nossr50/datatypes/World.java create mode 100644 core/src/main/java/com/gmail/nossr50/datatypes/block/Block.java create mode 100644 core/src/main/java/com/gmail/nossr50/datatypes/block/BlockState.java rename core/src/main/java/com/gmail/nossr50/{datatypes => platform}/TargetMinecraftVersion.java (79%) diff --git a/core/src/main/java/com/gmail/nossr50/datatypes/Block.java b/core/src/main/java/com/gmail/nossr50/datatypes/Block.java deleted file mode 100644 index 0fd095d76..000000000 --- a/core/src/main/java/com/gmail/nossr50/datatypes/Block.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.gmail.nossr50.datatypes; - -/** - * Represents a container of properties and values for a Block - * @see BlockProperty - * @see BlockState - */ -public interface Block { - -} diff --git a/core/src/main/java/com/gmail/nossr50/datatypes/BlockProperty.java b/core/src/main/java/com/gmail/nossr50/datatypes/BlockProperty.java deleted file mode 100644 index 58c307e9c..000000000 --- a/core/src/main/java/com/gmail/nossr50/datatypes/BlockProperty.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.gmail.nossr50.datatypes; - -/** - * BlockProperties are key value pairs for a blocks state - */ -public interface BlockProperty { - -} diff --git a/core/src/main/java/com/gmail/nossr50/datatypes/BlockState.java b/core/src/main/java/com/gmail/nossr50/datatypes/BlockState.java deleted file mode 100644 index 2d4652ee3..000000000 --- a/core/src/main/java/com/gmail/nossr50/datatypes/BlockState.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.gmail.nossr50.datatypes; - -/** - * Representation of the state for a Block - */ -public interface BlockState { - -} diff --git a/core/src/main/java/com/gmail/nossr50/datatypes/Location.java b/core/src/main/java/com/gmail/nossr50/datatypes/Location.java new file mode 100644 index 000000000..39e361d2e --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/datatypes/Location.java @@ -0,0 +1,32 @@ +package com.gmail.nossr50.datatypes; + +/** + * This class represents a Location in MC + * Locations have a world and x, y, and z axis values + */ +public interface Location { + + /** + * Returns the position of this location on the x-axis + * @return x-axis position + */ + double getX(); + + /** + * Returns the position of this location on the y-axis + * @return y-axis position + */ + double getY(); + + /** + * Returns the position of this location on the z-axis + * @return z-axis position + */ + double getZ(); + + /** + * The world for this Location + * @return the world of this location + */ + World getWorld(); +} diff --git a/core/src/main/java/com/gmail/nossr50/datatypes/Property.java b/core/src/main/java/com/gmail/nossr50/datatypes/Property.java new file mode 100644 index 000000000..778c1f04f --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/datatypes/Property.java @@ -0,0 +1,9 @@ +package com.gmail.nossr50.datatypes; + +/** + * Properties are Comparable key value pairs for a blocks state + * In MC this exists in three forms, Integer, Booleans, and Enums + */ +public interface Property> { + +} diff --git a/core/src/main/java/com/gmail/nossr50/datatypes/World.java b/core/src/main/java/com/gmail/nossr50/datatypes/World.java new file mode 100644 index 000000000..42b01e6a1 --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/datatypes/World.java @@ -0,0 +1,5 @@ +package com.gmail.nossr50.datatypes; + +public interface World { + +} diff --git a/core/src/main/java/com/gmail/nossr50/datatypes/block/Block.java b/core/src/main/java/com/gmail/nossr50/datatypes/block/Block.java new file mode 100644 index 000000000..95a738ad9 --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/datatypes/block/Block.java @@ -0,0 +1,38 @@ +package com.gmail.nossr50.datatypes.block; + +import com.gmail.nossr50.datatypes.Property; + +/** + * Represents a container of properties and values for a Block + * @see Property + * @see BlockState + */ +public class Block { + + private final String unlocalizedName; //The name before it is localized (english) + private BlockState blockState; + + public Block(String unlocalizedName, BlockState blockState) + { + this.unlocalizedName = unlocalizedName; + this.blockState = blockState; + } + + /** + * Gets the name of this block in English + * @return name of this block in English + */ + public String getUnlocalizedName() + { + return unlocalizedName; + } + + /** + * Gets the state of this block + * @return the state of this block + */ + public BlockState getBlockState() + { + return blockState; + } +} diff --git a/core/src/main/java/com/gmail/nossr50/datatypes/block/BlockState.java b/core/src/main/java/com/gmail/nossr50/datatypes/block/BlockState.java new file mode 100644 index 000000000..ee4df050a --- /dev/null +++ b/core/src/main/java/com/gmail/nossr50/datatypes/block/BlockState.java @@ -0,0 +1,44 @@ +package com.gmail.nossr50.datatypes.block; + +import com.gmail.nossr50.datatypes.Property; +import com.google.common.collect.ImmutableMap; + +import java.util.Collection; + +/** + * Representation of the state for a Block + * This tries to mirror MC internals, but only the parts mcMMO cares about + */ +public interface BlockState { + //This is the immutable map of all properties for this block state + ImmutableMap, Comparable> getImmutablePropertyMap(); + + //This will return the keyset for properties on this block state + Collection> getPropertyKeyset(); + + //TODO: I don't know if we need to mirror the cycling of properties + + /** + * Get the value for the given property key + * @param property the property key + * @param the type of property + * @return the value, can be null + */ + > T getPropertyValue(Property property); + + /** + * This will attempt to find a matching property for this block state + * @param property the property we want to match + * @param value the value we are trying to match + * @param the type of the property + * @param the type of the value + * @return the matching property on this block state, can be null + */ + , V extends T> BlockState findProperty(Property property, V value); + + /** + * This returns the block that this state belongs to + * @return the parent Block + */ + Block getBlock(); +} diff --git a/core/src/main/java/com/gmail/nossr50/datatypes/TargetMinecraftVersion.java b/core/src/main/java/com/gmail/nossr50/platform/TargetMinecraftVersion.java similarity index 79% rename from core/src/main/java/com/gmail/nossr50/datatypes/TargetMinecraftVersion.java rename to core/src/main/java/com/gmail/nossr50/platform/TargetMinecraftVersion.java index 47e4b7683..84148259b 100644 --- a/core/src/main/java/com/gmail/nossr50/datatypes/TargetMinecraftVersion.java +++ b/core/src/main/java/com/gmail/nossr50/platform/TargetMinecraftVersion.java @@ -1,6 +1,4 @@ -package com.gmail.nossr50.datatypes; - -import com.gmail.nossr50.platform.Platform; +package com.gmail.nossr50.platform; /** * Constants for targeted versions of MC