diff --git a/pom.xml b/pom.xml
index d236c05..a4e9bd1 100644
--- a/pom.xml
+++ b/pom.xml
@@ -10,7 +10,7 @@
UTF-8
5.7.1
- 2.13.1
+ 2.13.2
3.18.1
@@ -42,7 +42,7 @@
org.projectlombok
lombok
- 1.18.22
+ 1.18.24
provided
@@ -81,7 +81,7 @@
com.fasterxml.jackson.core
jackson-databind
- ${jackson.version}
+ 2.13.2.2
com.fasterxml.jackson.dataformat
@@ -103,13 +103,19 @@
com.google.guava
guava
- 29.0-jre
+ 30.0-android
+
+
+ org.checkerframework
+ checker-compat-qual
+
+
- com.nukkitx
- math
- 1.1.1
+ org.cloudburstmc.math
+ immutable
+ 2.0
@@ -138,9 +144,15 @@
org.projectlombok
lombok
- 1.18.22
+ 1.18.24
+
+ -Xmaxerrs
+ 1000
+ -Xmaxwarns
+ 2000
+
diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java
index bfff087..d61f6b5 100644
--- a/src/main/java/module-info.java
+++ b/src/main/java/module-info.java
@@ -10,7 +10,7 @@
requires static javax.inject;
requires java.desktop;
requires static lombok;
- requires com.nukkitx.math;
+ requires org.cloudburstmc.math.immutable;
requires org.slf4j;
exports org.cloudburstmc.api;
@@ -21,6 +21,7 @@
exports org.cloudburstmc.api.blockentity;
exports org.cloudburstmc.api.command;
exports org.cloudburstmc.api.crafting;
+ exports org.cloudburstmc.api.data;
exports org.cloudburstmc.api.enchantment;
exports org.cloudburstmc.api.enchantment.behavior;
exports org.cloudburstmc.api.entity;
@@ -57,5 +58,7 @@
exports org.cloudburstmc.api.potion;
exports org.cloudburstmc.api.registry;
exports org.cloudburstmc.api.util;
+ exports org.cloudburstmc.api.util.behavior;
exports org.cloudburstmc.api.util.data;
-}
\ No newline at end of file
+ exports org.cloudburstmc.api.inventory.screen;
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/Block.java b/src/main/java/org/cloudburstmc/api/block/Block.java
index 3e6c5d5..dd9894f 100644
--- a/src/main/java/org/cloudburstmc/api/block/Block.java
+++ b/src/main/java/org/cloudburstmc/api/block/Block.java
@@ -1,10 +1,11 @@
package org.cloudburstmc.api.block;
-import com.nukkitx.math.vector.Vector3i;
-import com.nukkitx.math.vector.Vector4i;
import org.cloudburstmc.api.level.Level;
import org.cloudburstmc.api.level.chunk.Chunk;
import org.cloudburstmc.api.util.Direction;
+import org.cloudburstmc.api.util.behavior.BehaviorCollection;
+import org.cloudburstmc.math.vector.Vector3i;
+import org.cloudburstmc.math.vector.Vector4i;
public interface Block extends BlockSnapshot {
@@ -18,6 +19,10 @@ public interface Block extends BlockSnapshot {
Vector3i getPosition();
+ BehaviorCollection getBehaviors();
+
+ int getBrightness();
+
default int getX() {
return getPosition().getX();
}
@@ -34,102 +39,10 @@ default Block up() {
return getSide(Direction.UP, 1);
}
- default Block up(int step) {
- return getSide(Direction.UP, step);
- }
-
- default Block down() {
- return getSide(Direction.DOWN, 1);
- }
-
- default Block down(int step) {
- return getSide(Direction.DOWN, step);
- }
-
- default Block north() {
- return getSide(Direction.NORTH, 1);
- }
-
- default Block north(int step) {
- return getSide(Direction.NORTH, step);
- }
-
- default Block east() {
- return getSide(Direction.EAST, 1);
- }
-
- default Block east(int step) {
- return getSide(Direction.EAST, step);
- }
-
- default Block south() {
- return getSide(Direction.SOUTH, 1);
- }
-
- default Block south(int step) {
- return getSide(Direction.SOUTH, step);
- }
-
- default Block west() {
- return getSide(Direction.WEST, 1);
- }
-
- default Block west(int step) {
- return getSide(Direction.WEST, step);
- }
-
default Block getSide(Direction face) {
return getSide(face, 1);
}
- default BlockState upState() {
- return getSideState(Direction.UP, 1);
- }
-
- default BlockState upState(int step) {
- return getSideState(Direction.UP, step);
- }
-
- default BlockState downState() {
- return getSideState(Direction.DOWN, 1);
- }
-
- default BlockState downState(int step) {
- return getSideState(Direction.DOWN, step);
- }
-
- default BlockState northState() {
- return getSideState(Direction.NORTH, 1);
- }
-
- default BlockState northState(int step) {
- return getSideState(Direction.NORTH, step);
- }
-
- default BlockState eastState() {
- return getSideState(Direction.EAST, 1);
- }
-
- default BlockState eastState(int step) {
- return getSideState(Direction.EAST, step);
- }
-
- default BlockState southState() {
- return getSideState(Direction.SOUTH, 1);
- }
-
- default BlockState southState(int step) {
- return getSideState(Direction.SOUTH, step);
- }
-
- default BlockState westState() {
- return getSideState(Direction.WEST, 1);
- }
-
- default BlockState westState(int step) {
- return getSideState(Direction.WEST, step);
- }
-
default BlockState getSideState(Direction face) {
return getSideState(face, 1);
}
diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java
new file mode 100644
index 0000000..6dd2e3a
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java
@@ -0,0 +1,163 @@
+package org.cloudburstmc.api.block;
+
+import org.cloudburstmc.api.block.behavior.*;
+import org.cloudburstmc.api.block.material.MaterialType;
+import org.cloudburstmc.api.blockentity.BlockEntityType;
+import org.cloudburstmc.api.data.BehaviorKey;
+import org.cloudburstmc.api.data.DataKey;
+import org.cloudburstmc.api.util.Identifier;
+
+import java.util.Optional;
+
+public final class BlockBehaviors {
+
+ private BlockBehaviors() {
+ }
+
+ public static final BehaviorKey GET_DESCRIPTION_ID = DataKey.behavior(Identifier.fromString("get_description_id"), DescriptionBlockBehavior.class, DescriptionBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_BOUNDING_BOX = DataKey.behavior(Identifier.fromString("get_bounding_box"), AABBBlockBehavior.class, AABBBlockBehavior.Executor.class);
+
+ public static final BehaviorKey CAN_BE_SILK_TOUCHED = DataKey.behavior(Identifier.fromString("can_be_silk_touched"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class);
+
+ public static final BehaviorKey CAN_BE_USED_IN_COMMANDS = DataKey.behavior(Identifier.fromString("can_be_used_in_commands"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class);
+
+ public static final BehaviorKey CAN_CONTAIN_LIQUID = DataKey.behavior(Identifier.fromString("can_contain_liquid"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class);
+
+ public static final BehaviorKey CAN_SPAWN_ON = DataKey.behavior(Identifier.fromString("can_spawn_on"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class);
+
+ public static final BehaviorKey CAN_BE_USED = DataKey.behavior(Identifier.fromString("can_be_used"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_FRICTION = DataKey.behavior(Identifier.fromString("get_friction"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_HARDNESS = DataKey.behavior(Identifier.fromString("get_hardness"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_BURN_ODDS = DataKey.behavior(Identifier.fromString("get_burn_odds"), IntBlockBehavior.class, IntBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_FLAME_ODDS = DataKey.behavior(Identifier.fromString("get_flame_odds"), IntBlockBehavior.class, IntBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_GRAVITY = DataKey.behavior(Identifier.fromString("get_gravity"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_THICKNESS = DataKey.behavior(Identifier.fromString("get_thickness"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_DESTROY_SPEED = DataKey.behavior(Identifier.fromString("get_destroy_speed"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_EXPERIENCE_DROP = DataKey.behavior(Identifier.fromString("get_experience_drop"), ExpBlockBehavior.class, ExpBlockBehavior.Executor.class);
+
+// public static final BehaviorKey, FloatBlockBehavior.Executor> GET_EXPLOSION_RESISTANCE = DataKey.behavior(Identifier.fromString("get_explosion_resistance"), ToFloatTriFunction.class, FloatBlockBehavior.Executor.class);
+
+// public static final BehaviorKey, ItemStack> GET_SILK_TOUCH_ITEM_STACK = DataKey.behavior(Identifier.fromString("get_silk_touch_item_stack"), BiFunction.class, ItemStack.class);
+
+// public static final BehaviorKey, BasicBlockBehavior.Executor> GET_STRIPPED_BLOCK = DataKey.behavior(Identifier.fromString("get_stripped_block"), BasicBlockBehavior.class, BasicBlockBehavior.Executor.class);
+
+ public static final BehaviorKey>>, GenericBlockBehavior.Executor>>> GET_BLOCK_ENTITY = DataKey.behavior(Identifier.fromString("get_block_entity"), GenericBlockBehavior.class, GenericBlockBehavior.Executor.class);
+
+ public static final BehaviorKey MAY_PICK = DataKey.behavior(Identifier.fromString("may_pick"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class);
+
+ public static final BehaviorKey MAY_PLACE = DataKey.behavior(Identifier.fromString("may_place"), MayPlaceBlockBehavior.class, MayPlaceBlockBehavior.Executor.class);
+
+ public static final BehaviorKey MAY_PLACE_ON = DataKey.behavior(Identifier.fromString("may_place_on"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_DESTROY = DataKey.behavior(Identifier.fromString("on_destroy"), PlayerBlockBehavior.class, PlayerBlockBehavior.Executor.class);
+
+ public static final BehaviorKey POST_DESTROY = DataKey.behavior(Identifier.fromString("post_destroy"), PlayerBlockBehavior.class, PlayerBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_NEIGHBOUR_CHANGED = DataKey.behavior(Identifier.fromString("on_neighbour_changed"), NeighborBlockBehavior.class, NeighborBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_FALL_ON = DataKey.behavior(Identifier.fromString("on_fall_on"), FallOnBlockBehavior.class, FallOnBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_LIGHTNING_HIT = DataKey.behavior(Identifier.fromString("on_lightning_hit"), ComplexBlockBehavior.class, ComplexBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_PLACE = DataKey.behavior(Identifier.fromString("on_place"), PlaceBlockBehavior.class, PlaceBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_PROJECTILE_HIT = DataKey.behavior(Identifier.fromString("on_projectile_hit"), EntityBlockBehavior.class, EntityBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_REDSTONE_UPDATE = DataKey.behavior(Identifier.fromString("on_redstone_update"), ComplexBlockBehavior.class, ComplexBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_REMOVE = DataKey.behavior(Identifier.fromString("on_remove"), ComplexBlockBehavior.class, ComplexBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_RANDOM_TICK = DataKey.behavior(Identifier.fromString("on_random_tick"), TickBlockBehavior.class, TickBlockBehavior.Executor.class);
+
+ public static final BehaviorKey CAN_RANDOM_TICK = DataKey.behavior(Identifier.fromString("can_random_tick"), Boolean.class);
+
+ public static final BehaviorKey ON_TICK = DataKey.behavior(Identifier.fromString("on_tick"), TickBlockBehavior.class, TickBlockBehavior.Executor.class);
+
+ public static final BehaviorKey USE = DataKey.behavior(Identifier.fromString("use"), UseBlockBehavior.class, UseBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_STAND_ON = DataKey.behavior(Identifier.fromString("on_stand_on"), EntityBlockBehavior.class, EntityBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_STEP_ON = DataKey.behavior(Identifier.fromString("on_step_on"), EntityBlockBehavior.class, EntityBlockBehavior.Executor.class);
+
+ public static final BehaviorKey ON_STEP_OFF = DataKey.behavior(Identifier.fromString("on_step_off"), EntityBlockBehavior.class, EntityBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_MATERIAL = DataKey.behavior(Identifier.fromString("get_material"), MaterialType.class, MaterialType.class);
+
+ public static final BehaviorKey GET_SILK_TOUCH_RESOURCE = DataKey.behavior(Identifier.fromString("get_silk_touch_resource"), ResourceBlockBehavior.class, ResourceBlockBehavior.Executor.class);
+
+ public static final BehaviorKey DROP_RESOURCE = DataKey.behavior(Identifier.fromString("drop_resource"), DropResourceBlockBehavior.class, DropResourceBlockBehavior.Executor.class);
+
+ public static final BehaviorKey SPAWN_RESOURCES = DataKey.behavior(Identifier.fromString("spawn_resources"), SpawnResourcesBlockBehavior.class, SpawnResourcesBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_RESOURCE = DataKey.behavior(Identifier.fromString("get_resource"), ResourceBlockBehavior.class, ResourceBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_RESOURCE_COUNT = DataKey.behavior(Identifier.fromString("get_resource_count"), ResourceCountBlockBehavior.class, ResourceCountBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_TRANSLUCENCY = DataKey.behavior(Identifier.fromString("get_translucency"), Float.class);
+
+ public static final BehaviorKey IS_SOLID = DataKey.behavior(Identifier.fromString("is_solid"), Boolean.class);
+
+ public static final BehaviorKey IS_LIQUID = DataKey.behavior(Identifier.fromString("is_liquid"), Boolean.class);
+
+ public static final BehaviorKey USES_WATERLOGGING = DataKey.behavior(Identifier.fromString("uses_waterlogging"), Boolean.class);
+
+ public static final BehaviorKey IS_TOP_SOLID = DataKey.behavior(Identifier.fromString("is_top_solid"), Boolean.class);
+
+ public static final BehaviorKey IS_STAIRS = DataKey.behavior(Identifier.fromString("is_stairs"), Boolean.class);
+
+ public static final BehaviorKey IS_SLAB = DataKey.behavior(Identifier.fromString("is_slab"), Boolean.class);
+
+ public static final BehaviorKey IS_REPLACEABLE = DataKey.behavior(Identifier.fromString("is_replaceable"), Boolean.class);
+
+ public static final BehaviorKey IS_SUPER_HOT = DataKey.behavior(Identifier.fromString("is_super_hot"), Boolean.class);
+
+ public static final BehaviorKey IS_FLAMMABLE = DataKey.behavior(Identifier.fromString("is_flammable"), Boolean.class);
+
+ public static final BehaviorKey GET_COLOR = DataKey.behavior(Identifier.fromString("get_color"), ColorBlockBehavior.class, ColorBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_LIGHT = DataKey.behavior(Identifier.fromString("get_light"), Integer.class);
+
+ public static final BehaviorKey IS_ALWAYS_DESTROYABLE = DataKey.behavior(Identifier.fromString("is_always_destroyable"), Boolean.class);
+
+ public static final BehaviorKey GET_TICK_DELAY = DataKey.behavior(Identifier.fromString("get_tick_delay"), Integer.class);
+
+ public static final BehaviorKey CAN_SURVIVE = DataKey.behavior(Identifier.fromString("can_survive"), SurviveBlockBehavior.class, SurviveBlockBehavior.Executor.class);
+
+ public static final BehaviorKey CHECK_ALIVE = DataKey.behavior(Identifier.fromString("check_alive"), ComplexBlockBehavior.class, ComplexBlockBehavior.Executor.class);
+
+ public static final BehaviorKey IS_FLOODABLE = DataKey.behavior(Identifier.fromString("is_floodable"), Boolean.class);
+
+ public static final BehaviorKey CAN_INSTATICK = DataKey.behavior(Identifier.fromString("is_instaticking"), Boolean.class);
+
+ public static final BehaviorKey CAN_SLIDE = DataKey.behavior(Identifier.fromString("can_slide"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class);
+
+ public static final BehaviorKey IS_FREE_TO_FALL = DataKey.behavior(Identifier.fromString("is_free_to_fall"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class);
+
+ public static final BehaviorKey START_FALLING = DataKey.behavior(Identifier.fromString("start_falling"), ComplexBlockBehavior.class, ComplexBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_LIQUID_HEIGHT = DataKey.behavior(Identifier.fromString("get_fluid_height"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_RESISTANCE = DataKey.behavior(Identifier.fromString("get_resistance"), Float.class);
+
+ public static final BehaviorKey ON_ENTITY_COLLIDE = DataKey.behavior(Identifier.fromString("on_entity_collide"), EntityBlockBehavior.class, EntityBlockBehavior.Executor.class);
+
+ public static final BehaviorKey GET_FILTERED_LIGHT = DataKey.behavior(Identifier.fromString("get_filtered_light"), Integer.class, Integer.class);
+
+ public static final BehaviorKey CAN_DAMAGE_ITEM = DataKey.behavior(Identifier.fromString("can_damage_item"), Boolean.class);
+
+ public static final BehaviorKey GET_MAP_COLOR = DataKey.behavior(Identifier.fromString("get_map_color"), MapColorBehavior.class, MapColorBehavior.Executor.class);
+
+ public static final BehaviorKey CAN_PASS_THROUGH = DataKey.behavior(Identifier.fromString("can_pass_through"), BooleanBlockStateBehavior.class, BooleanBlockStateBehavior.Executor.class);
+
+ public static final BehaviorKey IS_BREAKABLE = DataKey.behavior(Identifier.fromString("is_breakable"), CanBreakBlockBehavior.class, CanBreakBlockBehavior.Executor.class);
+
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/BlockState.java b/src/main/java/org/cloudburstmc/api/block/BlockState.java
index c4cbf7a..bff7834 100644
--- a/src/main/java/org/cloudburstmc/api/block/BlockState.java
+++ b/src/main/java/org/cloudburstmc/api/block/BlockState.java
@@ -1,7 +1,6 @@
package org.cloudburstmc.api.block;
import com.google.common.collect.ImmutableMap;
-import org.cloudburstmc.api.block.behavior.BlockBehavior;
import org.cloudburstmc.api.block.trait.BlockTrait;
import org.cloudburstmc.api.block.trait.BooleanBlockTrait;
import org.cloudburstmc.api.block.trait.IntegerBlockTrait;
@@ -18,20 +17,10 @@ public class BlockState {
private final BlockType type;
private final Map, Comparable>> traits;
private Map, BlockState[]> blockStates;
- private BlockBehavior behavior;
public BlockState(BlockType type, Map, Comparable>> traits) {
- this(type, traits, null);
- }
-
- public BlockState(BlockType type, Map, Comparable>> traits, BlockBehavior behavior) {
this.type = type;
this.traits = traits;
- this.behavior = behavior;
- }
-
- public void setBehavior(BlockBehavior behavior) {
- this.behavior = behavior;
}
public BlockType getType() {
@@ -104,10 +93,6 @@ public String toString() {
return builder.toString();
}
- public BlockBehavior getBehavior() {
- return this.behavior;
- }
-
public BlockState toggleTrait(BooleanBlockTrait trait) {
return this.blockStates.get(trait)[trait.getIndex(!((Boolean) this.traits.get(trait)))];
}
diff --git a/src/main/java/org/cloudburstmc/api/block/BlockStates.java b/src/main/java/org/cloudburstmc/api/block/BlockStates.java
index 4a831ff..ef96ba4 100644
--- a/src/main/java/org/cloudburstmc/api/block/BlockStates.java
+++ b/src/main/java/org/cloudburstmc/api/block/BlockStates.java
@@ -287,7 +287,6 @@ public class BlockStates {
public static final BlockState WOODEN_STAIRS = BlockTypes.WOODEN_STAIRS.getDefaultState();
public static final BlockState WOODEN_TRAPDOOR = BlockTypes.WOODEN_TRAPDOOR.getDefaultState();
public static final BlockState WOOL = BlockTypes.WOOL.getDefaultState();
- public static final BlockState MANGROVE_LEAVES = BlockTypes.MANGROVE_LEAVES.getDefaultState();
public static final BlockState MANGROVE_PROPAGULE = BlockTypes.MANGROVE_PROPAGULE.getDefaultState();
public static final BlockState MANGROVE_ROOTS = BlockTypes.MANGROVE_ROOTS.getDefaultState();
public static final BlockState MUDDY_MANGROVE_ROOTS = BlockTypes.MUDDY_MANGROVE_ROOTS.getDefaultState();
diff --git a/src/main/java/org/cloudburstmc/api/block/BlockType.java b/src/main/java/org/cloudburstmc/api/block/BlockType.java
index 69af521..7c7d6aa 100644
--- a/src/main/java/org/cloudburstmc/api/block/BlockType.java
+++ b/src/main/java/org/cloudburstmc/api/block/BlockType.java
@@ -3,13 +3,9 @@
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
-import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.api.block.trait.BlockTrait;
-import org.cloudburstmc.api.item.ItemStack;
+import org.cloudburstmc.api.item.ItemKeys;
import org.cloudburstmc.api.item.ItemType;
-import org.cloudburstmc.api.item.TierType;
-import org.cloudburstmc.api.item.ToolType;
-import org.cloudburstmc.api.util.AxisAlignedBB;
import org.cloudburstmc.api.util.Identifier;
import java.util.*;
@@ -19,15 +15,14 @@
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
-public final class BlockType implements ItemType {
+public final class BlockType extends ItemType {
- private final Identifier id;
private final Set> traits;
private final List states;
private final BlockState defaultState;
private BlockType(Identifier id, BlockTrait>[] traits) {
- this.id = id;
+ super(id, Collections.singleton(ItemKeys.BLOCK_STATE));
this.traits = ImmutableSet.copyOf(traits);
this.states = getPermutations(this, traits);
@@ -45,10 +40,6 @@ private BlockType(Identifier id, BlockTrait>[] traits) {
}
}
- public Identifier getId() {
- return id;
- }
-
public Set> getTraits() {
return traits;
}
@@ -65,10 +56,20 @@ public void forEachPermutation(Consumer action) {
this.states.forEach(action);
}
+ private static final BlockTrait>[] EMPTY = new BlockTrait[0];
+
+ public static BlockType of(Identifier id) {
+ return of(id, EMPTY);
+ }
+
public static BlockType of(Identifier id, BlockTrait>... traits) {
checkNotNull(id, "id");
checkNotNull(traits, "traits");
+ if (traits == EMPTY) {
+ return new BlockType(id, EMPTY);
+ }
+
// Check for duplicate block traits.
LinkedHashSet> traitSet = new LinkedHashSet<>();
Collections.addAll(traitSet, traits);
@@ -130,129 +131,6 @@ private static List getPermutations(BlockType type, BlockTrait>[]
return states.build();
}
- @Override
- public boolean isBlock() {
- return true;
- }
-
- @Override
- public boolean isPlaceable() {
- return true;
- }
-
- //TODO - move a lot of this to block/item behavior classes?
- public boolean blocksMotion() {
- return this != BlockTypes.AIR;
- }
-
- public boolean blocksWater() {
- return true;
- }
-
- public boolean isFloodable() {
- return false;
- }
-
- public boolean isReplaceable() {
- return false;
- }
-
- public boolean isTransparent() {
- return BlockCategories.inCategory(this, BlockCategory.TRANSPARENT);
- }
-
- public int getTranslucency() {
- return 0;
- }
-
- public int getFilterLevel() {
- return 0;
- }
-
- public boolean isSolid() {
- return BlockCategories.inCategory(this, BlockCategory.SOLID);
- }
-
- public boolean isDiggable() {
- return false;
- }
-
- public int getBurnChance() {
- return 0;
- }
-
- public int getBurnAbility() {
- return 0;
- }
-
- public float getHardness() {
- return 0f;
- }
-
- public float getFriction() {
- return 0f;
- }
-
- public float getResistance() {
- return 0f;
- }
-
- @Nullable
- @Override
- public BlockType getBlock() {
- return this;
- }
-
- @Nullable
- @Override
- public Class> getMetadataClass() {
- return null;
- }
-
- @Override
- public int getMaximumStackSize() {
- return 64;
- }
-
- @Override
- public ItemStack createItem(int amount, Object... metadata) {
- return null; // TODO - Need to inject an Item or Block Registry? Or make ItemStack not an interface so we can create a new instance?
- }
-
- @Nullable
- @Override
- public ToolType getToolType() {
- return null;
- }
-
- @Nullable
- @Override
- public TierType getTierType() {
- return null;
- }
-
- public AxisAlignedBB getBoundingBox() {
- return null;
- //TODO
- }
-
- // Move these to BlockBehavior instead?
- public boolean isPowerSource() {
- return false;
- }
-
- public boolean canBeSilkTouched() {
- return true;
- }
-
- public boolean waterlogsSource() {
- return false;
- }
-
- public boolean breaksFlowing() {
- return false;
- }
-
@Override
public String toString() {
return getId().toString();
diff --git a/src/main/java/org/cloudburstmc/api/block/BlockTypes.java b/src/main/java/org/cloudburstmc/api/block/BlockTypes.java
index 856ba18..ac9d371 100644
--- a/src/main/java/org/cloudburstmc/api/block/BlockTypes.java
+++ b/src/main/java/org/cloudburstmc/api/block/BlockTypes.java
@@ -337,7 +337,6 @@ public class BlockTypes {
public static final BlockType PEARLESCENT_FROGLIGHT = BlockType.of(BlockIds.PEARLESCENT_FROGLIGHT, BlockTraits.AXIS);
public static final BlockType VERDANT_FROGLIGHT = BlockType.of(BlockIds.VERDANT_FROGLIGHT, BlockTraits.AXIS);
public static final BlockType OCHRE_FROGLIGHT = BlockType.of(BlockIds.OCHRE_FROGLIGHT, BlockTraits.AXIS);
- public static final BlockType MANGROVE_LEAVES = BlockType.of(BlockIds.MANGROVE_LEAVES, BlockTraits.IS_PERSISTENT, BlockTraits.HAS_UPDATE);
public static final BlockType MANGROVE_PROPAGULE = BlockType.of(BlockIds.MANGROVE_PROPAGULE, BlockTraits.IS_HANGING, BlockTraits.PROPAGULE_STAGE);
public static final BlockType MANGROVE_ROOTS = BlockType.of(BlockIds.MANGROVE_ROOTS);
public static final BlockType MUDDY_MANGROVE_ROOTS = BlockType.of(BlockIds.MUDDY_MANGROVE_ROOTS, BlockTraits.AXIS);
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/AABBBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/AABBBlockBehavior.java
new file mode 100644
index 0000000..8900bbf
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/AABBBlockBehavior.java
@@ -0,0 +1,15 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.BlockState;
+import org.cloudburstmc.api.util.AxisAlignedBB;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface AABBBlockBehavior {
+
+ AxisAlignedBB getBoundingBox(Behavior behavior, BlockState state);
+
+ @FunctionalInterface
+ interface Executor {
+ AxisAlignedBB execute(BlockState state);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/BlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/BlockBehavior.java
deleted file mode 100644
index 7d7a9b4..0000000
--- a/src/main/java/org/cloudburstmc/api/block/behavior/BlockBehavior.java
+++ /dev/null
@@ -1,317 +0,0 @@
-package org.cloudburstmc.api.block.behavior;
-
-import com.nukkitx.math.vector.Vector3f;
-import com.nukkitx.math.vector.Vector3i;
-import org.cloudburstmc.api.block.Block;
-import org.cloudburstmc.api.block.BlockState;
-import org.cloudburstmc.api.entity.Entity;
-import org.cloudburstmc.api.item.ItemStack;
-import org.cloudburstmc.api.item.TierType;
-import org.cloudburstmc.api.item.ToolType;
-import org.cloudburstmc.api.player.Player;
-import org.cloudburstmc.api.util.AxisAlignedBB;
-import org.cloudburstmc.api.util.Direction;
-import org.cloudburstmc.api.util.data.BlockColor;
-
-import static org.cloudburstmc.api.block.BlockStates.AIR;
-
-public abstract class BlockBehavior {
-
- public boolean canHarvestWithHand(BlockState state) { //used for calculating breaking time
- var type = state.getType();
- return type.isDiggable() && type.getToolType() == null && type.getTierType() == null;
- }
-
- public boolean isBreakable(BlockState state, ItemStack item) {
- return state.getType().isDiggable();
- }
-
- public int tickRate() {
- return 10;
- }
-
- public int onUpdate(Block block, int type) {
- return 0;
- }
-
- public boolean onActivate(Block block, ItemStack item) {
- return this.onActivate(block, item, null);
- }
-
- public boolean onActivate(Block block, ItemStack item, Player player) {
- return false;
- }
-
- public int getBurnChance(BlockState state) {
- return state.getType().getBurnChance();
- }
-
- public int getBurnAbility(BlockState state) {
- return state.getType().getBurnAbility();
- }
-
- public ToolType getToolType(BlockState state) {
- return state.getType().getToolType();
- }
-
- public TierType getMinimalTier(BlockState state) {
- return state.getType().getTierType();
- }
-
- public boolean checkTool(BlockState state, ItemStack item) {
- var toolType = getToolType(state);
- var tier = getMinimalTier(state);
-
- var type = item.getType();
- if (toolType != null && type.getToolType() != toolType) {
- return false;
- }
-
- if (tier == null) {
- return true;
- }
-
- return type.getTierType() != null && type.getTierType().compareTo(tier) >= 0;
- }
-
- public int getLightLevel(Block block) {
- return 0;
- }
-
- public boolean canBePlaced() {
- return true;
- }
-
- public boolean canBeReplaced(Block block) {
- return block.getState()
- .getType()
- .isReplaceable();
- }
-
- public boolean isTransparent(BlockState state) {
- var type = state.getType();
- return type.isTransparent() || type.getTranslucency() > 0;
- }
-
- public boolean isSolid(BlockState state) {
- return state.getType().isSolid();
- }
-
- public boolean isLiquid() {
- return false;
- }
-
- public int getFilterLevel(BlockState state) {
- return state.getType().getFilterLevel();
- }
-
- public boolean canBeActivated(Block block) {
- return false;
- }
-
- public boolean hasEntityCollision() {
- return false;
- }
-
- public boolean canPassThrough(BlockState state) {
- return !state.getType().blocksMotion();
- }
-
- public boolean canBePushed() {
- return true;
- }
-
- public boolean hasComparatorInputOverride(BlockState state) {
- //return state.getType().hasComparatorSignal();
- return false;
- }
-
- public int getComparatorInputOverride(Block block) {
- return 0;
- }
-
- public boolean canBeClimbed() {
- return false;
- }
-
- public BlockColor getColor(Block block) {
- return BlockColor.VOID_BLOCK_COLOR;
- }
-
- public boolean canBeFlooded(BlockState state) {
- var type = state.getType();
- return type.isFloodable() || !type.blocksWater();
- }
-
- public boolean place(ItemStack item, Block block, Block target, Direction face, Vector3f clickPos, Player player) {
- return placeBlock(block, item);
- }
-
- public boolean placeBlock(Block block, ItemStack item) {
- return placeBlock(block, item, true);
- }
-
- public boolean placeBlock(Block block, ItemStack item, boolean update) {
- return placeBlock(block, item.getBehavior().getBlock(item), update);
- }
-
- public boolean placeBlock(Block block, BlockState newState) {
- return placeBlock(block, newState, true);
- }
-
- public abstract boolean placeBlock(Block block, BlockState newState, boolean update);
-
- public boolean onBreak(Block block, ItemStack item) {
- return removeBlock(block, true);
- }
-
- final protected boolean removeBlock(Block block) {
- return removeBlock(block, true);
- }
-
- final public boolean removeBlock(Block block, boolean update) {
- BlockState state;
-
- if (block.isWaterlogged()) {
- state = block.getExtra();
-
- block.setExtra(AIR, true, false);
- } else {
- state = AIR;
- }
-
- return block.getLevel().setBlockState(block.getPosition(), state, true, update);
- }
-
- public boolean onBreak(Block block, ItemStack item, Player player) {
- return onBreak(block, item);
- }
-
- public float getHardness(BlockState blockState) {
- return blockState.getType().getHardness();
- }
-
- public String getDescriptionId(BlockState state) {
- return "tile." + state.getType().getId().getName() + ".name";
- }
-
- public float getResistance(BlockState blockState) {
- return blockState.getType().getResistance();
- }
-
- public float getFrictionFactor(BlockState blockState) {
- return blockState.getType().getFriction();
- }
-
- public Vector3f addVelocityToEntity(Block block, Vector3f vector, Entity entity) {
- return vector;
- }
-
- public ItemStack[] getDrops(Block block, ItemStack hand) {
- if (checkTool(block.getState(), hand)) {
- return new ItemStack[]{
- this.toItem(block)
- };
- } else {
- return new ItemStack[0];
- }
- }
-
- public abstract float getBreakTime(BlockState state, ItemStack item, Player player);
-
- public boolean canBeBrokenWith(BlockState state, ItemStack item) {
- return this.getHardness(state) != -1;
- }
-
- public boolean collidesWithBB(Block block, AxisAlignedBB bb) {
- return collidesWithBB(block, bb, false);
- }
-
- public boolean collidesWithBB(Block block, AxisAlignedBB bb, boolean collisionBB) {
- AxisAlignedBB bb1 = collisionBB ? this.getCollisionBoxes(block.getPosition(), block.getState()) : this.getBoundingBox(block);
- return bb1 != null && bb.intersectsWith(bb1);
- }
-
- public void onEntityCollide(Block block, Entity entity) {
-
- }
-
- public AxisAlignedBB getBoundingBox(BlockState state) {
- return getBoundingBox(null, state);
- }
-
- public final AxisAlignedBB getBoundingBox(Block block) {
- return getBoundingBox(block.getPosition(), block.getState());
- }
-
- public AxisAlignedBB getBoundingBox(Vector3i pos, BlockState state) {
- var type = state.getType();
-
- AxisAlignedBB bb = type.getBoundingBox();
-
- if (bb != null && pos != null) {
- bb = bb.offset(pos);
- }
-
- return bb;
- }
-
- public final AxisAlignedBB getCollisionBoxes(Block block) {
- return getCollisionBoxes(block.getPosition(), block.getState());
- }
-
- public AxisAlignedBB getCollisionBoxes(Vector3i pos, BlockState state) {
- return getBoundingBox(pos, state);
- }
-
- public String getSaveId() {
- String name = getClass().getName();
- return name.substring(16);
- }
-
- public int getWeakPower(Block block, Direction face) {
- return 0;
- }
-
- public int getStrongPower(Block block, Direction side) {
- return 0;
- }
-
- public boolean isPowerSource(Block block) {
- return block.getState().getType().isPowerSource();
- }
-
- public int getDropExp() {
- return 0;
- }
-
- public boolean isNormalBlock(Block block) {
- var state = block.getState();
- return !isTransparent(state) && isSolid(state) && !isPowerSource(block);
- }
-
- public BlockBehavior clone() {
- try {
- return (BlockBehavior) super.clone();
- } catch (CloneNotSupportedException e) {
- throw new IllegalStateException(e);
- }
- }
-
- public ItemStack toItem(Block block) {
- return block.getState().getType().createItem();
- }
-
- public boolean canSilkTouch(BlockState state) {
- return state.getType().canBeSilkTouched();
- }
-
- public boolean canWaterlogSource(BlockState state) {
- return state.getType().waterlogsSource();
- }
-
- public boolean canWaterlogFlowing(BlockState state) {
- var type = state.getType();
- return !type.breaksFlowing() && !type.blocksWater();
- }
-}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java
new file mode 100644
index 0000000..72985be
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java
@@ -0,0 +1,14 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface BooleanBlockBehavior {
+
+ boolean test(Behavior behavior, Block block);
+
+ @FunctionalInterface
+ interface Executor {
+ boolean execute(Block block);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockStateBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockStateBehavior.java
new file mode 100644
index 0000000..42b98f6
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockStateBehavior.java
@@ -0,0 +1,14 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.BlockState;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface BooleanBlockStateBehavior {
+
+ boolean test(Behavior behavior, BlockState block);
+
+ @FunctionalInterface
+ interface Executor {
+ boolean execute(BlockState block);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/CanBreakBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/CanBreakBlockBehavior.java
new file mode 100644
index 0000000..20ca077
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/CanBreakBlockBehavior.java
@@ -0,0 +1,16 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.item.ItemStack;
+import org.cloudburstmc.api.util.Direction;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface CanBreakBlockBehavior {
+
+ boolean canBreak(Behavior behavior, Block block, ItemStack item);
+
+ @FunctionalInterface
+ interface Executor {
+ boolean execute(Block block, ItemStack item);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/ColorBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/ColorBlockBehavior.java
new file mode 100644
index 0000000..b5ed891
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/ColorBlockBehavior.java
@@ -0,0 +1,15 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.behavior.Behavior;
+import org.cloudburstmc.api.util.data.BlockColor;
+
+public interface ColorBlockBehavior {
+
+ BlockColor execute(Behavior behavior, Block block);
+
+ @FunctionalInterface
+ interface Executor {
+ BlockColor execute(Block block);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/ComplexBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/ComplexBlockBehavior.java
new file mode 100644
index 0000000..560b30a
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/ComplexBlockBehavior.java
@@ -0,0 +1,14 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface ComplexBlockBehavior {
+
+ void execute(Behavior behavior, Block block);
+
+ @FunctionalInterface
+ interface Executor {
+ void execute(Block block);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/DescriptionBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/DescriptionBlockBehavior.java
new file mode 100644
index 0000000..1b66862
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/DescriptionBlockBehavior.java
@@ -0,0 +1,14 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.BlockState;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface DescriptionBlockBehavior {
+
+ String getDescription(Behavior behavior, BlockState state);
+
+ @FunctionalInterface
+ interface Executor {
+ String execute(BlockState state);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/DropResourceBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/DropResourceBlockBehavior.java
new file mode 100644
index 0000000..eb235a5
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/DropResourceBlockBehavior.java
@@ -0,0 +1,17 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.entity.misc.DroppedItem;
+import org.cloudburstmc.api.item.ItemStack;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface DropResourceBlockBehavior {
+
+ DroppedItem dropResource(Behavior behavior, Block block, ItemStack itemStack);
+
+ @FunctionalInterface
+ interface Executor {
+
+ DroppedItem execute(Block block, ItemStack itemStack);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/EntityBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/EntityBlockBehavior.java
new file mode 100644
index 0000000..f978fc9
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/EntityBlockBehavior.java
@@ -0,0 +1,15 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.entity.Entity;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface EntityBlockBehavior {
+
+ void execute(Behavior behavior, Block block, Entity entity);
+
+ @FunctionalInterface
+ interface Executor {
+ void execute(Block block, Entity entity);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/ExpBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/ExpBlockBehavior.java
new file mode 100644
index 0000000..4045e21
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/ExpBlockBehavior.java
@@ -0,0 +1,16 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.BlockState;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+import java.util.random.RandomGenerator;
+
+public interface ExpBlockBehavior {
+
+ int getExperience(Behavior behavior, BlockState state, RandomGenerator random);
+
+ @FunctionalInterface
+ interface Executor {
+ int execute(BlockState state, RandomGenerator random);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/FallOnBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/FallOnBlockBehavior.java
new file mode 100644
index 0000000..02b63a9
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/FallOnBlockBehavior.java
@@ -0,0 +1,15 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.entity.Entity;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface FallOnBlockBehavior {
+
+ void onFallOn(Behavior behavior, Block block, Entity entity);
+
+ @FunctionalInterface
+ interface Executor {
+ void execute(Block block, Entity entity);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockBehavior.java
new file mode 100644
index 0000000..c2d4d4d
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockBehavior.java
@@ -0,0 +1,14 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.BlockState;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface FloatBlockBehavior {
+
+ float getProperty(Behavior behavior, BlockState state);
+
+ @FunctionalInterface
+ interface Executor {
+ float execute(BlockState state);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/GenericBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/GenericBlockBehavior.java
new file mode 100644
index 0000000..ab07a07
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/GenericBlockBehavior.java
@@ -0,0 +1,14 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface GenericBlockBehavior {
+
+ void execute(Behavior> behavior, Block block);
+
+ @FunctionalInterface
+ interface Executor {
+ void execute(Block block);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/IntBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/IntBlockBehavior.java
new file mode 100644
index 0000000..eae506d
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/IntBlockBehavior.java
@@ -0,0 +1,14 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.BlockState;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface IntBlockBehavior {
+
+ int getProperty(Behavior behavior, BlockState state);
+
+ @FunctionalInterface
+ interface Executor {
+ int execute(BlockState state);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/MapColorBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/MapColorBehavior.java
new file mode 100644
index 0000000..9a6afa8
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/MapColorBehavior.java
@@ -0,0 +1,17 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+import java.awt.*;
+
+public interface MapColorBehavior {
+
+ Color getMapColor(Behavior behavior, Block block);
+
+ @FunctionalInterface
+ interface Executor {
+
+ Color execute(Block block);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/MayPlaceBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/MayPlaceBlockBehavior.java
new file mode 100644
index 0000000..ca4c42d
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/MayPlaceBlockBehavior.java
@@ -0,0 +1,15 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.Direction;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface MayPlaceBlockBehavior {
+
+ boolean mayPlace(Behavior behavior, Block block, Direction direction);
+
+ @FunctionalInterface
+ interface Executor {
+ boolean execute(Block block, Direction direction);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/NeighborBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/NeighborBlockBehavior.java
new file mode 100644
index 0000000..d2c72b7
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/NeighborBlockBehavior.java
@@ -0,0 +1,14 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface NeighborBlockBehavior {
+
+ void onNeighborChanged(Behavior behavior, Block block, Block neighbor);
+
+ @FunctionalInterface
+ interface Executor {
+ void executor(Block block, Block neighbor);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java
new file mode 100644
index 0000000..9e90d0e
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java
@@ -0,0 +1,21 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.BlockState;
+import org.cloudburstmc.api.player.Player;
+import org.cloudburstmc.api.util.Direction;
+import org.cloudburstmc.api.util.behavior.Behavior;
+import org.cloudburstmc.math.vector.Vector3f;
+import org.cloudburstmc.math.vector.Vector3i;
+
+public interface PlaceBlockBehavior {
+
+ boolean execute(Behavior behavior, BlockState blockState, Player player,
+ Vector3i blockPosition, Direction face, Vector3f clickPosition);
+
+ @FunctionalInterface
+ interface Executor {
+
+ boolean execute(BlockState blockState, Player player, Vector3i blockPosition, Direction face,
+ Vector3f clickPosition);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/PlayerBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/PlayerBlockBehavior.java
new file mode 100644
index 0000000..631bd04
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/PlayerBlockBehavior.java
@@ -0,0 +1,15 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.player.Player;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface PlayerBlockBehavior {
+
+ void execute(Behavior behavior, Block block, Player player);
+
+ @FunctionalInterface
+ interface Executor {
+ void execute(Block block, Player player);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/ResourceBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/ResourceBlockBehavior.java
new file mode 100644
index 0000000..64416ae
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/ResourceBlockBehavior.java
@@ -0,0 +1,17 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.item.ItemStack;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+import java.util.random.RandomGenerator;
+
+public interface ResourceBlockBehavior {
+
+ ItemStack getResource(Behavior behavior, Block block, RandomGenerator random, int bonusLevel);
+
+ @FunctionalInterface
+ interface Executor {
+ ItemStack execute(Block block, RandomGenerator random, int bonusLevel);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/ResourceCountBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/ResourceCountBlockBehavior.java
new file mode 100644
index 0000000..489f253
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/ResourceCountBlockBehavior.java
@@ -0,0 +1,16 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+import java.util.random.RandomGenerator;
+
+public interface ResourceCountBlockBehavior {
+
+ int getResourceCount(Behavior behavior, Block block, RandomGenerator random, int bonusLevel);
+
+ @FunctionalInterface
+ interface Executor {
+ int execute(Block block, RandomGenerator random, int bonusLevel);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/SpawnResourcesBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/SpawnResourcesBlockBehavior.java
new file mode 100644
index 0000000..3e286d8
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/SpawnResourcesBlockBehavior.java
@@ -0,0 +1,18 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.item.ItemStack;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+import java.util.random.RandomGenerator;
+
+public interface SpawnResourcesBlockBehavior {
+
+ void spawnResource(Behavior behavior, Block block, RandomGenerator random, ItemStack tool, int bonusLootLevel);
+
+ @FunctionalInterface
+ interface Executor {
+
+ void execute(Block block, RandomGenerator random, ItemStack tool, int bonusLootLevel);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/SurviveBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/SurviveBlockBehavior.java
new file mode 100644
index 0000000..3748b58
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/SurviveBlockBehavior.java
@@ -0,0 +1,14 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface SurviveBlockBehavior {
+
+ boolean canSurvive(Behavior behavior, Block block);
+
+ @FunctionalInterface
+ interface Executor {
+ boolean execute(Block block);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/TickBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/TickBlockBehavior.java
new file mode 100644
index 0000000..45db9bd
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/TickBlockBehavior.java
@@ -0,0 +1,16 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+import java.util.random.RandomGenerator;
+
+public interface TickBlockBehavior {
+
+ void onTick(Behavior behavior, Block block, RandomGenerator random);
+
+ @FunctionalInterface
+ interface Executor {
+ void execute(Block block, RandomGenerator random);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/UseBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/UseBlockBehavior.java
new file mode 100644
index 0000000..48d72f7
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/block/behavior/UseBlockBehavior.java
@@ -0,0 +1,16 @@
+package org.cloudburstmc.api.block.behavior;
+
+import org.cloudburstmc.api.block.Block;
+import org.cloudburstmc.api.player.Player;
+import org.cloudburstmc.api.util.Direction;
+import org.cloudburstmc.api.util.behavior.Behavior;
+
+public interface UseBlockBehavior {
+
+ boolean use(Behavior behavior, Block block, Player player, Direction direction);
+
+ @FunctionalInterface
+ interface Executor {
+ boolean execute(Block block, Player player, Direction direction);
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/block/material/MaterialTypes.java b/src/main/java/org/cloudburstmc/api/block/material/MaterialTypes.java
index d79dd6a..ef1864f 100644
--- a/src/main/java/org/cloudburstmc/api/block/material/MaterialTypes.java
+++ b/src/main/java/org/cloudburstmc/api/block/material/MaterialTypes.java
@@ -84,5 +84,9 @@ public class MaterialTypes {
public static MaterialType DECORATION_FLAMMABLE = MaterialType.builder().translucency(1.0f).alwaysDestroyable().blockingPrecipitation().flammable().build();
- public static MaterialType ANY = MaterialType.builder().alwaysDestroyable().blockingPrecipitation().solid().build();
+ public static MaterialType DECORATION_SOLID = MaterialType.builder().blockingPrecipitation().solid().blockingMotion().build();
+
+ public static MaterialType DRIPSTONE = MaterialType.builder().blockingPrecipitation().solid().blockingMotion().build();
+
+ public static MaterialType SCULK = MaterialType.builder().blockingPrecipitation().solid().blockingMotion().build();
}
diff --git a/src/main/java/org/cloudburstmc/api/blockentity/BlockEntity.java b/src/main/java/org/cloudburstmc/api/blockentity/BlockEntity.java
index 69a2a1e..de65b66 100644
--- a/src/main/java/org/cloudburstmc/api/blockentity/BlockEntity.java
+++ b/src/main/java/org/cloudburstmc/api/blockentity/BlockEntity.java
@@ -1,11 +1,11 @@
package org.cloudburstmc.api.blockentity;
-import com.nukkitx.math.vector.Vector3i;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.cloudburstmc.api.block.Block;
import org.cloudburstmc.api.block.BlockState;
import org.cloudburstmc.api.level.Level;
import org.cloudburstmc.api.player.Player;
+import org.cloudburstmc.math.vector.Vector3i;
public interface BlockEntity {
diff --git a/src/main/java/org/cloudburstmc/api/blockentity/BlockEntityFactory.java b/src/main/java/org/cloudburstmc/api/blockentity/BlockEntityFactory.java
index 0aca999..9a558a2 100644
--- a/src/main/java/org/cloudburstmc/api/blockentity/BlockEntityFactory.java
+++ b/src/main/java/org/cloudburstmc/api/blockentity/BlockEntityFactory.java
@@ -1,7 +1,7 @@
package org.cloudburstmc.api.blockentity;
-import com.nukkitx.math.vector.Vector3i;
import org.cloudburstmc.api.level.chunk.Chunk;
+import org.cloudburstmc.math.vector.Vector3i;
public interface BlockEntityFactory {
diff --git a/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java b/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java
new file mode 100644
index 0000000..d5e5851
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java
@@ -0,0 +1,52 @@
+package org.cloudburstmc.api.data;
+
+import org.cloudburstmc.api.util.Identifier;
+
+import java.util.function.Function;
+
+public final class BehaviorKey implements DataKey {
+
+ private final Identifier id;
+ private final Class functionType;
+ private final Class executorType;
+
+ BehaviorKey(Identifier id, Class functionType, Class executorType) {
+ this.id = id;
+ this.functionType = functionType;
+ this.executorType = executorType;
+ }
+
+ @Override
+ public Identifier getId() {
+ return id;
+ }
+
+ @Override
+ public Class getType() {
+ return functionType;
+ }
+
+ @Override
+ public Class getMutableType() {
+ return executorType;
+ }
+
+ public Class getExecutorType() {
+ return executorType;
+ }
+
+ @Override
+ public Function getImmutableFunction() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public Function getMutableFunction() {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public String toString() {
+ return id.toString();
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/data/DataKey.java b/src/main/java/org/cloudburstmc/api/data/DataKey.java
new file mode 100644
index 0000000..57ab9a7
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/data/DataKey.java
@@ -0,0 +1,56 @@
+package org.cloudburstmc.api.data;
+
+import org.cloudburstmc.api.util.Identifier;
+
+import java.util.function.Function;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+
+public sealed interface DataKey permits BehaviorKey, ListDataKey, SimpleDataKey, MapDataKey {
+
+ @SuppressWarnings("unchecked")
+ static SimpleDataKey simple(Identifier id, Class super T> type) {
+ checkNotNull(id, "id");
+ checkNotNull(type, "type");
+ return new SimpleDataKey<>(id, (Class) type);
+ }
+
+ static ListDataKey list(Identifier id, Class type) {
+ checkNotNull(id, "id");
+ checkNotNull(type, "type");
+ return new ListDataKey<>(id, type);
+ }
+
+ static MapDataKey map(Identifier id, Class keyType, Class valueType) {
+ checkNotNull(id, "id");
+ checkNotNull(keyType, "keyType");
+ checkNotNull(valueType, "valueType");
+ return new MapDataKey<>(id, keyType, valueType);
+ }
+
+ static BehaviorKey behavior(Identifier id, Class type) {
+ return behavior(id, type, type);
+ }
+
+ @SuppressWarnings("unchecked")
+ static BehaviorKey behavior(Identifier id, Class super F> functionType, Class super E> returnType) {
+ checkNotNull(id, "id");
+ checkNotNull(functionType, "functionType");
+ checkNotNull(returnType, "returnType");
+ return new BehaviorKey<>(id, (Class) functionType, (Class) returnType);
+ }
+
+ Identifier getId();
+
+ Class getType();
+
+ Class getMutableType();
+
+ Function getImmutableFunction();
+
+ Function getMutableFunction();
+
+ default T getDefaultValue() {
+ return null;
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/data/DataStore.java b/src/main/java/org/cloudburstmc/api/data/DataStore.java
new file mode 100644
index 0000000..26beb82
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/data/DataStore.java
@@ -0,0 +1,6 @@
+package org.cloudburstmc.api.data;
+
+public interface DataStore {
+
+ T get(DataKey key);
+}
diff --git a/src/main/java/org/cloudburstmc/api/data/ListDataKey.java b/src/main/java/org/cloudburstmc/api/data/ListDataKey.java
new file mode 100644
index 0000000..e53e409
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/data/ListDataKey.java
@@ -0,0 +1,50 @@
+package org.cloudburstmc.api.data;
+
+import com.google.common.collect.ImmutableList;
+import org.cloudburstmc.api.util.Identifier;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.function.Function;
+
+@SuppressWarnings({"unchecked", "rawtypes"})
+public final class ListDataKey implements DataKey, List> {
+
+ private final Identifier id;
+ private final Class type;
+
+ ListDataKey(Identifier id, Class type) {
+ this.id = id;
+ this.type = type;
+ }
+
+ @Override
+ public Identifier getId() {
+ return id;
+ }
+
+ @Override
+ public Class> getType() {
+ return (Class) ImmutableList.class;
+ }
+
+ @Override
+ public Class> getMutableType() {
+ return (Class) List.class;
+ }
+
+ @Override
+ public Function, List> getImmutableFunction() {
+ return ImmutableList::copyOf;
+ }
+
+ @Override
+ public Function, List> getMutableFunction() {
+ return ArrayList::new;
+ }
+
+ @Override
+ public List getDefaultValue() {
+ return ImmutableList.of();
+ }
+}
diff --git a/src/main/java/org/cloudburstmc/api/data/MapDataKey.java b/src/main/java/org/cloudburstmc/api/data/MapDataKey.java
new file mode 100644
index 0000000..9d6e78b
--- /dev/null
+++ b/src/main/java/org/cloudburstmc/api/data/MapDataKey.java
@@ -0,0 +1,52 @@
+package org.cloudburstmc.api.data;
+
+import com.google.common.collect.ImmutableMap;
+import org.cloudburstmc.api.util.Identifier;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.function.Function;
+
+@SuppressWarnings({"unchecked", "rawtypes"})
+public final class MapDataKey implements DataKey