فهرست منبع

Fleshing out Abstractions for World, Location, Block, BlockState

nossr50 6 سال پیش
والد
کامیت
b40b206bf5

+ 0 - 10
core/src/main/java/com/gmail/nossr50/datatypes/Block.java

@@ -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 {
-
-}

+ 0 - 8
core/src/main/java/com/gmail/nossr50/datatypes/BlockProperty.java

@@ -1,8 +0,0 @@
-package com.gmail.nossr50.datatypes;
-
-/**
- * BlockProperties are key value pairs for a blocks state
- */
-public interface BlockProperty {
-
-}

+ 0 - 8
core/src/main/java/com/gmail/nossr50/datatypes/BlockState.java

@@ -1,8 +0,0 @@
-package com.gmail.nossr50.datatypes;
-
-/**
- * Representation of the state for a Block
- */
-public interface BlockState {
-
-}

+ 32 - 0
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();
+}

+ 9 - 0
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<T extends Comparable<T>> {
+
+}

+ 5 - 0
core/src/main/java/com/gmail/nossr50/datatypes/World.java

@@ -0,0 +1,5 @@
+package com.gmail.nossr50.datatypes;
+
+public interface World {
+
+}

+ 38 - 0
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;
+    }
+}

+ 44 - 0
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<Property<?>, Comparable<? >> getImmutablePropertyMap();
+
+    //This will return the keyset for properties on this block state
+    Collection<Property<?>> 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 <T> the type of property
+     * @return the value, can be null
+     */
+    <T extends Comparable<T>> T getPropertyValue(Property<T> 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 <T> the type of the property
+     * @param <V> the type of the value
+     * @return the matching property on this block state, can be null
+     */
+    <T extends Comparable<T>, V extends T> BlockState findProperty(Property<T> property, V value);
+
+    /**
+     * This returns the block that this state belongs to
+     * @return the parent Block
+     */
+    Block getBlock();
+}

+ 1 - 3
core/src/main/java/com/gmail/nossr50/datatypes/TargetMinecraftVersion.java → 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