Fleshing out Abstractions for World, Location, Block, BlockState

This commit is contained in:
nossr50 2019-02-09 19:38:31 -08:00
parent a2c0a02d30
commit b40b206bf5
9 changed files with 129 additions and 29 deletions

View File

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

View File

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

View File

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

View File

@ -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();
}

View File

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

View File

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

View File

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

View File

@ -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();
}

View File

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