From 571d41a50c00955f6c6887dc4924b66b4a048094 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 16 Oct 2021 16:01:05 +0100 Subject: [PATCH 01/42] Begin implementing DataKey components This should make modification of block and item behaviours far easier as well as changing data within ItemStack. It also allows for different types to be declared for when the data is being mutated in a builder class. --- src/main/java/module-info.java | 1 + .../api/block/BlockBehaviorKeys.java | 14 + .../org/cloudburstmc/api/block/BlockType.java | 142 +--- .../api/block/behavior/BlockBehavior.java | 363 +++++---- .../block/behavior/BlockStateBehavior.java | 9 + .../behavior/FloatBlockStateBehavior.java | 9 + .../org/cloudburstmc/api/data/DataKey.java | 33 + .../org/cloudburstmc/api/data/DataStore.java | 6 + .../cloudburstmc/api/data/ListDataKey.java | 45 ++ .../cloudburstmc/api/data/SimpleDataKey.java | 41 + .../api/enchantment/Enchantment.java | 4 + .../cloudburstmc/api/item/ItemFactory.java | 9 - .../org/cloudburstmc/api/item/ItemKeys.java | 17 + .../org/cloudburstmc/api/item/ItemStack.java | 149 +--- .../api/item/ItemStackBuilder.java | 105 +-- .../org/cloudburstmc/api/item/ItemStacks.java | 496 ------------ .../org/cloudburstmc/api/item/ItemType.java | 63 +- .../org/cloudburstmc/api/item/ItemTypes.java | 738 ++++++------------ .../api/item/behavior/ItemBehavior.java | 7 + 19 files changed, 773 insertions(+), 1478 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/block/BlockBehaviorKeys.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/BlockStateBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockStateBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/data/DataKey.java create mode 100644 src/main/java/org/cloudburstmc/api/data/DataStore.java create mode 100644 src/main/java/org/cloudburstmc/api/data/ListDataKey.java create mode 100644 src/main/java/org/cloudburstmc/api/data/SimpleDataKey.java create mode 100644 src/main/java/org/cloudburstmc/api/enchantment/Enchantment.java delete mode 100644 src/main/java/org/cloudburstmc/api/item/ItemFactory.java create mode 100644 src/main/java/org/cloudburstmc/api/item/ItemKeys.java delete mode 100644 src/main/java/org/cloudburstmc/api/item/ItemStacks.java diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index bfff087..f2c9c31 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -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; diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviorKeys.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviorKeys.java new file mode 100644 index 0000000..5514490 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviorKeys.java @@ -0,0 +1,14 @@ +package org.cloudburstmc.api.block; + +import org.cloudburstmc.api.block.behavior.BlockStateBehavior; +import org.cloudburstmc.api.data.DataKey; +import org.cloudburstmc.api.data.SimpleDataKey; +import org.cloudburstmc.api.util.AxisAlignedBB; +import org.cloudburstmc.api.util.Identifier; + +public class BlockBehaviorKeys { + + public static final SimpleDataKey> GET_DESCRIPTION_ID = DataKey.simple(Identifier.fromString("get_description_id"), BlockStateBehavior.class); + + public static final SimpleDataKey> GET_BOUNDING_BOX = DataKey.simple(Identifier.fromString("get_bounding_box"), BlockStateBehavior.class); +} diff --git a/src/main/java/org/cloudburstmc/api/block/BlockType.java b/src/main/java/org/cloudburstmc/api/block/BlockType.java index 69af521..efff073 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockType.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockType.java @@ -19,15 +19,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, null); this.traits = ImmutableSet.copyOf(traits); this.states = getPermutations(this, traits); @@ -45,10 +44,6 @@ private BlockType(Identifier id, BlockTrait[] traits) { } } - public Identifier getId() { - return id; - } - public Set> getTraits() { return traits; } @@ -65,10 +60,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 +135,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/behavior/BlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/BlockBehavior.java index 7d7a9b4..5df6aa1 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/BlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/BlockBehavior.java @@ -2,12 +2,14 @@ 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.checkerframework.checker.nullness.qual.Nullable; +import org.cloudburstmc.api.block.*; +import org.cloudburstmc.api.enchantment.Enchantment; 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.item.behavior.ItemBehavior; import org.cloudburstmc.api.player.Player; import org.cloudburstmc.api.util.AxisAlignedBB; import org.cloudburstmc.api.util.Direction; @@ -15,15 +17,15 @@ import static org.cloudburstmc.api.block.BlockStates.AIR; -public abstract class BlockBehavior { +public abstract class BlockBehavior implements ItemBehavior { public boolean canHarvestWithHand(BlockState state) { //used for calculating breaking time var type = state.getType(); - return type.isDiggable() && type.getToolType() == null && type.getTierType() == null; + return isDiggable(type) && getToolType(type) == null && getTierType(type) == null; } public boolean isBreakable(BlockState state, ItemStack item) { - return state.getType().isDiggable(); + return isDiggable(state.getType()); } public int tickRate() { @@ -42,37 +44,37 @@ 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 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; @@ -82,28 +84,28 @@ public boolean canBePlaced() { return true; } - public boolean canBeReplaced(Block block) { - return block.getState() - .getType() - .isReplaceable(); - } +// 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 isTransparent(BlockState state) { +// var type = state.getType(); +// return type.isTransparent() || type.getTranslucency() > 0; +// } - public boolean isSolid(BlockState state) { - return state.getType().isSolid(); - } +// public boolean isSolid(BlockState state) { +// return state.getType().isSolid(); +// } public boolean isLiquid() { return false; } - public int getFilterLevel(BlockState state) { - return state.getType().getFilterLevel(); - } +// public int getFilterLevel(BlockState state) { +// return state.getType().getFilterLevel(); +// } public boolean canBeActivated(Block block) { return false; @@ -113,9 +115,9 @@ public boolean hasEntityCollision() { return false; } - public boolean canPassThrough(BlockState state) { - return !state.getType().blocksMotion(); - } +// public boolean canPassThrough(BlockState state) { +// return !state.getType().blocksMotion(); +// } public boolean canBePushed() { return true; @@ -138,22 +140,22 @@ 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 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 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) { +// 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, ItemStack item, boolean update) { +// return placeBlock(block, item.getBehavior().getBlock(item), update); +// } public boolean placeBlock(Block block, BlockState newState) { return placeBlock(block, newState, true); @@ -187,131 +189,220 @@ public boolean onBreak(Block block, ItemStack item, Player player) { return onBreak(block, item); } - public float getHardness(BlockState blockState) { - return blockState.getType().getHardness(); - } +// 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 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 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 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) { - 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 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 AxisAlignedBB getBoundingBox(BlockState state) { - return getBoundingBox(null, state); + public int getWeakPower(Block block, Direction face) { + return 0; } - public final AxisAlignedBB getBoundingBox(Block block) { - return getBoundingBox(block.getPosition(), block.getState()); + public int getStrongPower(Block block, Direction side) { + return 0; } - public AxisAlignedBB getBoundingBox(Vector3i pos, BlockState state) { - var type = state.getType(); +// public boolean isPowerSource(Block block) { +// return block.getState().getType().isPowerSource(); +// } + + public int getDropExp() { + return 0; + } - AxisAlignedBB bb = type.getBoundingBox(); +// public boolean isNormalBlock(Block block) { +// var state = block.getState(); +// return !isTransparent(state) && isSolid(state) && !isPowerSource(block); +// } - if (bb != null && pos != null) { - bb = bb.offset(pos); + public BlockBehavior clone() { + try { + return (BlockBehavior) super.clone(); + } catch (CloneNotSupportedException e) { + throw new IllegalStateException(e); } + } - return bb; +// 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(); +// } + + public boolean isPlaceable() { + return true; } - public final AxisAlignedBB getCollisionBoxes(Block block) { - return getCollisionBoxes(block.getPosition(), block.getState()); + //TODO - move a lot of this to block/item behavior classes? +// public boolean blocksMotion() { +// return this != BlockTypes.AIR; +// } + + public boolean blocksWater() { + return true; } - public AxisAlignedBB getCollisionBoxes(Vector3i pos, BlockState state) { - return getBoundingBox(pos, state); + public boolean isFloodable() { + return false; } - public String getSaveId() { - String name = getClass().getName(); - return name.substring(16); + public boolean isReplaceable() { + return false; } - public int getWeakPower(Block block, Direction face) { +// public boolean isTransparent() { +// return BlockCategories.inCategory(this, BlockCategory.TRANSPARENT); +// } + + public int getTranslucency() { return 0; } - public int getStrongPower(Block block, Direction side) { + public int getFilterLevel() { return 0; } - public boolean isPowerSource(Block block) { - return block.getState().getType().isPowerSource(); +// public boolean isSolid() { +// return BlockCategories.inCategory(this, BlockCategory.SOLID); +// } + + public boolean isDiggable(BlockType type) { + return false; } - public int getDropExp() { + public int getBurnChance() { return 0; } - public boolean isNormalBlock(Block block) { - var state = block.getState(); - return !isTransparent(state) && isSolid(state) && !isPowerSource(block); + public int getBurnAbility() { + return 0; } - public BlockBehavior clone() { - try { - return (BlockBehavior) super.clone(); - } catch (CloneNotSupportedException e) { - throw new IllegalStateException(e); - } + public float getHardness() { + return 1f; } - public ItemStack toItem(Block block) { - return block.getState().getType().createItem(); + public float getFriction() { + return 0f; } - public boolean canSilkTouch(BlockState state) { - return state.getType().canBeSilkTouched(); + public float getResistance() { + return 0f; } - public boolean canWaterlogSource(BlockState state) { - return state.getType().waterlogsSource(); + public int getMaximumStackSize() { + return 64; } - public boolean canWaterlogFlowing(BlockState state) { - var type = state.getType(); - return !type.breaksFlowing() && !type.blocksWater(); + 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? + } + + public AxisAlignedBB getBoundingBox() { + return null; // FIXME + } + + public boolean isPowerSource() { + return false; + } + + public boolean canBeSilkTouched() { + return true; + } + + public boolean waterlogsSource() { + return false; + } + + public boolean breaksFlowing() { + return false; } } diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/BlockStateBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/BlockStateBehavior.java new file mode 100644 index 0000000..971f5b9 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/block/behavior/BlockStateBehavior.java @@ -0,0 +1,9 @@ +package org.cloudburstmc.api.block.behavior; + +import org.cloudburstmc.api.block.BlockState; + +@FunctionalInterface +public interface BlockStateBehavior { + + T evaluate(BlockState value); +} diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockStateBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockStateBehavior.java new file mode 100644 index 0000000..fbe06b0 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockStateBehavior.java @@ -0,0 +1,9 @@ +package org.cloudburstmc.api.block.behavior; + +import org.cloudburstmc.api.block.BlockState; + +@FunctionalInterface +public interface FloatBlockStateBehavior { + + float evaluate(BlockState state); +} 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..9ca8c02 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/data/DataKey.java @@ -0,0 +1,33 @@ +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 SimpleDataKey, ListDataKey { + + @SuppressWarnings("unchecked") + static SimpleDataKey simple(Identifier id, Class 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); + } + + Identifier getId(); + + Class getType(); + + Class getMutableType(); + + Function getImmutableFunction(); + + Function getMutableFunction(); +} 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..e4c17c4 --- /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 getData(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..64dbbc0 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/data/ListDataKey.java @@ -0,0 +1,45 @@ +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; + } +} diff --git a/src/main/java/org/cloudburstmc/api/data/SimpleDataKey.java b/src/main/java/org/cloudburstmc/api/data/SimpleDataKey.java new file mode 100644 index 0000000..7643d1f --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/data/SimpleDataKey.java @@ -0,0 +1,41 @@ +package org.cloudburstmc.api.data; + +import org.cloudburstmc.api.util.Identifier; + +import java.util.function.Function; + +public final class SimpleDataKey implements DataKey { + + private final Identifier id; + private final Class type; + + SimpleDataKey(Identifier id, Class type) { + this.id = id; + this.type = type; + } + + @Override + public Identifier getId() { + return id; + } + + @Override + public Class getType() { + return type; + } + + @Override + public Class getMutableType() { + return type; + } + + @Override + public Function getImmutableFunction() { + return Function.identity(); + } + + @Override + public Function getMutableFunction() { + return Function.identity(); + } +} diff --git a/src/main/java/org/cloudburstmc/api/enchantment/Enchantment.java b/src/main/java/org/cloudburstmc/api/enchantment/Enchantment.java new file mode 100644 index 0000000..2d0f446 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/enchantment/Enchantment.java @@ -0,0 +1,4 @@ +package org.cloudburstmc.api.enchantment; + +public record Enchantment(EnchantmentType type, int level) { +} diff --git a/src/main/java/org/cloudburstmc/api/item/ItemFactory.java b/src/main/java/org/cloudburstmc/api/item/ItemFactory.java deleted file mode 100644 index 1e50008..0000000 --- a/src/main/java/org/cloudburstmc/api/item/ItemFactory.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.cloudburstmc.api.item; - -import org.cloudburstmc.api.util.Identifier; - -@FunctionalInterface -public interface ItemFactory { - - ItemStack create(Identifier identifier); -} diff --git a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java new file mode 100644 index 0000000..1873538 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java @@ -0,0 +1,17 @@ +package org.cloudburstmc.api.item; + +import org.cloudburstmc.api.block.BlockState; +import org.cloudburstmc.api.data.DataKey; +import org.cloudburstmc.api.data.ListDataKey; +import org.cloudburstmc.api.data.SimpleDataKey; +import org.cloudburstmc.api.enchantment.Enchantment; +import org.cloudburstmc.api.util.Identifier; + +public final class ItemKeys { + + public static final SimpleDataKey BLOCK_STATE = DataKey.simple(Identifier.fromString("block_state"), BlockState.class); + + public static final SimpleDataKey DAMAGE = DataKey.simple(Identifier.fromString("item_damage"), Integer.class); + + public static final ListDataKey ENCHANTMENTS = DataKey.list(Identifier.fromString("enchantments"), Enchantment.class); +} diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStack.java b/src/main/java/org/cloudburstmc/api/item/ItemStack.java index 80d7b98..bb3517c 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStack.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStack.java @@ -1,153 +1,70 @@ package org.cloudburstmc.api.item; +import com.google.common.collect.ImmutableMap; import com.nukkitx.math.GenericMath; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.block.BlockState; -import org.cloudburstmc.api.enchantment.EnchantmentInstance; -import org.cloudburstmc.api.enchantment.EnchantmentType; -import org.cloudburstmc.api.item.behavior.ItemBehavior; -import org.cloudburstmc.api.registry.ItemRegistry; -import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.api.data.DataKey; +import org.cloudburstmc.api.data.DataStore; -import javax.inject.Inject; -import java.util.Collection; -import java.util.List; +import java.util.Collections; import java.util.Map; -@NonNull -public interface ItemStack extends Comparable { +public final class ItemStack implements DataStore, Comparable { - @Inject - ItemRegistry registry = null; //does that work? + private final ItemType type; + private final int amount; + private final ImmutableMap, ?> metadata; - ItemType getType(); - - int getAmount(); - - default boolean isNull() { - return true; - } - - String getName(); - - default boolean hasName() { - return getName() != null; + ItemStack(ItemType type, int amount, Map, ?> metadata) { + this.type = type; + this.amount = amount; + this.metadata = ImmutableMap.copyOf(metadata); } - List getLore(); - - default boolean hasEnchantments() { - return !getEnchantments().isEmpty(); + public static ItemStackBuilder builder() { + return new ItemStackBuilder(null, 1, Collections.emptyMap()); } - Map getEnchantments(); - - default EnchantmentInstance getEnchantment(EnchantmentType enchantment) { - for (EnchantmentInstance ench : getEnchantments().values()) { - if (ench.getType() == enchantment) { - return ench; - } - } - - return null; + public ItemType getType() { + return type; } - Collection getCanDestroy(); - - default boolean canDestroy(BlockState state) { - return getCanDestroy().contains(state.getType().getId()); + public int getAmount() { + return amount; } - Collection getCanPlaceOn(); - - default boolean canPlaceOn(BlockState state) { - return getCanPlaceOn().contains(state.getType().getId()); + public ItemStackBuilder toBuilder() { + return new ItemStackBuilder(this.type, this.amount, this.metadata); } - default T getMetadata(Class metadataClass) { - return getMetadata(metadataClass, null); + public ItemStack reduceAmount() { + return withAmount(this.amount - 1); } - T getMetadata(Class metadataClass, T defaultValue); - - boolean hasMetadata(Class metadataClass); - - boolean hasTag(); - - ItemStackBuilder toBuilder(); - -// RecipeItemStackBuilder toRecipeBuilder(); - - ItemBehavior getBehavior(); - - boolean isMergeable(@NonNull ItemStack itemStack); - - boolean equals(@Nullable ItemStack item); - - default boolean isFull() { - return getAmount() >= getType().getMaximumStackSize(); + public ItemStack increaseAmount() { + return addAmount(1); } - default boolean equals(@Nullable ItemStack other, boolean checkAmount) { - return equals(other, checkAmount, true); + public ItemStack addAmount(int delta) { + return withAmount(this.amount + delta); } - boolean equals(@Nullable ItemStack other, boolean checkAmount, boolean checkData); - - default ItemStack decrementAmount() { - return decrementAmount(1); - } - - default ItemStack decrementAmount(int amount) { - return withAmount(getAmount() - amount); - } - - default ItemStack incrementAmount() { - return incrementAmount(1); - } - - default ItemStack incrementAmount(int amount) { - return withAmount(getAmount() + amount); - } - - default ItemStack withAmount(int amount) { - if (this.getAmount() == amount) { + public ItemStack withAmount(int amount) { + if (this.amount == amount) { return this; } - return toBuilder().amount(GenericMath.clamp(amount, 0, getBehavior().getMaxStackSize(this))).build(); + return toBuilder().amount(amount).build(); } - default ItemStack withEnchantment(EnchantmentInstance enchantment) { - return toBuilder().addEnchantment(enchantment).build(); + @SuppressWarnings("unchecked") + public T getData(DataKey key) { + return (T) metadata.get(key); } - ItemStack withData(Object data); - - ItemStack withData(Class metadataClass, Object data); - - default BlockState getBlockState() { - throw new UnsupportedOperationException("Item " + this.getType() + " cannot be converted to a block state"); - } - -/* static ItemStack get(BlockState state) { // Do we need get methods in ItemStack? - return get(state, 1); - } - - static ItemStack get(BlockState state, int amount) { - return this.registry.getItem(state, amount); - } - - static ItemStack get(ItemType type) { - return get(type, 1); - } - - static ItemStack get(ItemType type, int amount, Object... metadata) { - return ItemRegistry.get().getItem(type, amount, metadata); - }*/ - @Override - default int compareTo(ItemStack other) { + public int compareTo(ItemStack other) { if (other.getType().equals(this.getType())) { return this.getAmount() - other.getAmount(); } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java b/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java index a9ed16e..87ae528 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java @@ -1,63 +1,64 @@ package org.cloudburstmc.api.item; +import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.api.block.BlockState; +import org.cloudburstmc.api.block.BlockType; +import org.cloudburstmc.api.data.DataKey; import org.cloudburstmc.api.enchantment.EnchantmentInstance; import org.cloudburstmc.api.enchantment.EnchantmentType; import org.cloudburstmc.api.util.Identifier; import java.util.Collection; +import java.util.IdentityHashMap; import java.util.List; - -public interface ItemStackBuilder { - - ItemStackBuilder itemType(@NonNull ItemType itemType); - - ItemStackBuilder blockState(BlockState blockState); - - ItemStackBuilder amount(int amount); - - ItemStackBuilder name(@NonNull String name); - - ItemStackBuilder clearName(); - - ItemStackBuilder lore(List lines); - - ItemStackBuilder clearLore(); - - ItemStackBuilder itemData(Object data); - - ItemStackBuilder itemData(Class metadataClass, Object data); - - ItemStackBuilder clearData(); - - ItemStackBuilder clearData(Class metadataClass); - - ItemStackBuilder addEnchantment(EnchantmentInstance enchantment); - - ItemStackBuilder addEnchantments(Collection enchantmentInstanceCollection); - - ItemStackBuilder clearEnchantments(); - - ItemStackBuilder removeEnchantment(EnchantmentType enchantment); - - ItemStackBuilder removeEnchantments(Collection enchantments); - - ItemStackBuilder addCanPlaceOn(Identifier id); - - ItemStackBuilder addCanPlaceOn(ItemType type); - - ItemStackBuilder removeCanPlaceOn(Identifier id); - - ItemStackBuilder clearCanPlaceOn(); - - ItemStackBuilder addCanDestroy(Identifier id); - - ItemStackBuilder addCanDestroy(ItemType type); - - ItemStackBuilder removeCanDestroy(Identifier id); - - ItemStackBuilder clearCanDestroy(); - - ItemStack build(); +import java.util.Map; + +import static com.google.common.base.Preconditions.checkArgument; +import static lombok.Lombok.checkNotNull; +import static org.cloudburstmc.api.item.ItemKeys.BLOCK_STATE; + +public final class ItemStackBuilder { + + private ItemType itemType; + private int amount; + private final Map, Object> metadata; + + ItemStackBuilder(ItemType itemType, int amount, Map, ?> metadata) { + this.itemType = itemType; + this.amount = amount; + this.metadata = new IdentityHashMap<>(metadata); + } + + public ItemStackBuilder itemType(@NonNull ItemType itemType) { + checkNotNull(itemType, "itemType is null"); + this.itemType = itemType; + return this; + } + + public ItemStackBuilder amount(@NonNegative int amount) { + checkArgument(amount > 0, "amount cannot be less than zero"); + this.amount = amount; + return this; + } + + public ItemStackBuilder clearData() { + this.metadata.clear(); + return this; + } + + public ItemStackBuilder data(DataKey key, M value) { + checkNotNull(key, "key"); + checkNotNull(value, "value"); + this.metadata.put(key, key.getImmutableFunction().apply(value)); + return this; + } + + public ItemStack build() { + checkNotNull(this.itemType, "itemType is null"); + checkArgument(this.amount > 0, "amount cannot be less than zero"); + checkArgument(!(this.itemType instanceof BlockType) || this.metadata.containsKey(BLOCK_STATE), + "ItemStack with a BlockType requires BlockState data"); + return new ItemStack(itemType, amount, metadata); + } } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStacks.java b/src/main/java/org/cloudburstmc/api/item/ItemStacks.java deleted file mode 100644 index 58984b8..0000000 --- a/src/main/java/org/cloudburstmc/api/item/ItemStacks.java +++ /dev/null @@ -1,496 +0,0 @@ -package org.cloudburstmc.api.item; - -import lombok.experimental.UtilityClass; - -@UtilityClass -public class ItemStacks { -/* // TODO these can't be used until BlockTypes.createItem() is implemented - public static final ItemStack AIR = BlockTypes.AIR.createItem(); - //blocks - public static final ItemStack ACTIVATOR_RAIL = BlockTypes.ACTIVATOR_RAIL.createItem(); - public static final ItemStack ALLOW = BlockTypes.ALLOW.createItem(); - public static final ItemStack ANCIENT_DEBRIS = BlockTypes.ANCIENT_DEBRIS.createItem(); - public static final ItemStack ANVIL = BlockTypes.ANVIL.createItem(); - public static final ItemStack BAMBOO = BlockTypes.BAMBOO.createItem(); - public static final ItemStack BAMBOO_SAPLING = BlockTypes.BAMBOO_SAPLING.createItem(); - public static final ItemStack BARREL = BlockTypes.BARREL.createItem(); - public static final ItemStack BARRIER = BlockTypes.BARRIER.createItem(); - public static final ItemStack BASALT = BlockTypes.BASALT.createItem(); - public static final ItemStack BEACON = BlockTypes.BEACON.createItem(); - public static final ItemStack BED = BlockTypes.BED.createItem(); - public static final ItemStack BEDROCK = BlockTypes.BEDROCK.createItem(); - public static final ItemStack BEEHIVE = BlockTypes.BEEHIVE.createItem(); - public static final ItemStack BEETROOT = BlockTypes.BEETROOT.createItem(); - public static final ItemStack BEE_NEST = BlockTypes.BEE_NEST.createItem(); - public static final ItemStack BELL = BlockTypes.BELL.createItem(); - public static final ItemStack BLACKSTONE = BlockTypes.BLACKSTONE.createItem(); - public static final ItemStack BLAST_FURNACE = BlockTypes.BLAST_FURNACE.createItem(); - public static final ItemStack BLUE_ICE = BlockTypes.BLUE_ICE.createItem(); - public static final ItemStack BONE_BLOCK = BlockTypes.BONE_BLOCK.createItem(); - public static final ItemStack BOOKSHELF = BlockTypes.BOOKSHELF.createItem(); - public static final ItemStack BORDER_BLOCK = BlockTypes.BORDER_BLOCK.createItem(); - public static final ItemStack BREWING_STAND = BlockTypes.BREWING_STAND.createItem(); - public static final ItemStack BRICK_BLOCK = BlockTypes.BRICK_BLOCK.createItem(); - public static final ItemStack BROWN_MUSHROOM = BlockTypes.BROWN_MUSHROOM.createItem(); - public static final ItemStack BROWN_MUSHROOM_BLOCK = BlockTypes.BROWN_MUSHROOM_BLOCK.createItem(); - public static final ItemStack BUBBLE_COLUMN = BlockTypes.BUBBLE_COLUMN.createItem(); - public static final ItemStack CACTUS = BlockTypes.CACTUS.createItem(); - public static final ItemStack CAKE = BlockTypes.CAKE.createItem(); - public static final ItemStack CAMERA = BlockTypes.CAMERA.createItem(); - public static final ItemStack CAMPFIRE = BlockTypes.CAMPFIRE.createItem(); - public static final ItemStack CARPET = BlockTypes.CARPET.createItem(); - public static final ItemStack CARROTS = BlockTypes.CARROTS.createItem(); - public static final ItemStack CARTOGRAPHY_TABLE = BlockTypes.CARTOGRAPHY_TABLE.createItem(); - public static final ItemStack CARVED_PUMPKIN = BlockTypes.CARVED_PUMPKIN.createItem(); - public static final ItemStack CAULDRON = BlockTypes.CAULDRON.createItem(); - public static final ItemStack CHAIN = BlockTypes.CHAIN.createItem(); - public static final ItemStack CHAIN_COMMAND_BLOCK = BlockTypes.CHAIN_COMMAND_BLOCK.createItem(); - public static final ItemStack CHEMICAL_HEAT = BlockTypes.CHEMICAL_HEAT.createItem(); - public static final ItemStack CHEMISTRY_TABLE = BlockTypes.CHEMISTRY_TABLE.createItem(); - public static final ItemStack CHEST = BlockTypes.CHEST.createItem(); - public static final ItemStack CHISELED_POLISHED_BLACKSTONE = BlockTypes.CHISELED_POLISHED_BLACKSTONE.createItem(); - public static final ItemStack CHORUS_FLOWER = BlockTypes.CHORUS_FLOWER.createItem(); - public static final ItemStack CHORUS_PLANT = BlockTypes.CHORUS_PLANT.createItem(); - public static final ItemStack CLAY = BlockTypes.CLAY.createItem(); - public static final ItemStack COAL_BLOCK = BlockTypes.COAL_BLOCK.createItem(); - public static final ItemStack COAL_ORE = BlockTypes.COAL_ORE.createItem(); - public static final ItemStack COBBLESTONE = BlockTypes.COBBLESTONE.createItem(); - public static final ItemStack COCOA = BlockTypes.COCOA.createItem(); - public static final ItemStack COLORED_TORCH_BP = BlockTypes.COLORED_TORCH_BP.createItem(); - public static final ItemStack COLORED_TORCH_RG = BlockTypes.COLORED_TORCH_RG.createItem(); - public static final ItemStack COMMAND_BLOCK = BlockTypes.COMMAND_BLOCK.createItem(); - public static final ItemStack COMPARATOR = BlockTypes.COMPARATOR.createItem(); - public static final ItemStack COMPOSTER = BlockTypes.COMPOSTER.createItem(); - public static final ItemStack CONCRETE = BlockTypes.CONCRETE.createItem(); - public static final ItemStack CONCRETE_POWDER = BlockTypes.CONCRETE_POWDER.createItem(); - public static final ItemStack CONDUIT = BlockTypes.CONDUIT.createItem(); - public static final ItemStack CORAL = BlockTypes.CORAL.createItem(); - public static final ItemStack CORAL_BLOCK = BlockTypes.CORAL_BLOCK.createItem(); - public static final ItemStack CORAL_FAN = BlockTypes.CORAL_FAN.createItem(); - public static final ItemStack CORAL_FAN_DEAD = BlockTypes.CORAL_FAN_DEAD.createItem(); - public static final ItemStack CORAL_FAN_HANG = BlockTypes.CORAL_FAN_HANG.createItem(); - public static final ItemStack CRACKED_POLISHED_BLACKSTONE_BRICKS = BlockTypes.CRACKED_POLISHED_BLACKSTONE_BRICKS.createItem(); - public static final ItemStack CRAFTING_TABLE = BlockTypes.CRAFTING_TABLE.createItem(); - public static final ItemStack CRYING_OBSIDIAN = BlockTypes.CRYING_OBSIDIAN.createItem(); - public static final ItemStack DAYLIGHT_DETECTOR = BlockTypes.DAYLIGHT_DETECTOR.createItem(); - public static final ItemStack DAYLIGHT_DETECTOR_INVERTED = BlockTypes.DAYLIGHT_DETECTOR_INVERTED.createItem(); - public static final ItemStack DEADBUSH = BlockTypes.DEADBUSH.createItem(); - public static final ItemStack DENY = BlockTypes.DENY.createItem(); - public static final ItemStack DETECTOR_RAIL = BlockTypes.DETECTOR_RAIL.createItem(); - public static final ItemStack DIAMOND_BLOCK = BlockTypes.DIAMOND_BLOCK.createItem(); - public static final ItemStack DIAMOND_ORE = BlockTypes.DIAMOND_ORE.createItem(); - public static final ItemStack DIRT = BlockTypes.DIRT.createItem(); - public static final ItemStack DISPENSER = BlockTypes.DISPENSER.createItem(); - public static final ItemStack DOUBLE_PLANT = BlockTypes.DOUBLE_PLANT.createItem(); - public static final ItemStack DRAGON_EGG = BlockTypes.DRAGON_EGG.createItem(); - public static final ItemStack DRIED_KELP_BLOCK = BlockTypes.DRIED_KELP_BLOCK.createItem(); - public static final ItemStack DROPPER = BlockTypes.DROPPER.createItem(); - public static final ItemStack ELEMENT = BlockTypes.ELEMENT.createItem(); - public static final ItemStack EMERALD_BLOCK = BlockTypes.EMERALD_BLOCK.createItem(); - public static final ItemStack EMERALD_ORE = BlockTypes.EMERALD_ORE.createItem(); - public static final ItemStack ENCHANTING_TABLE = BlockTypes.ENCHANTING_TABLE.createItem(); - public static final ItemStack ENDER_CHEST = BlockTypes.ENDER_CHEST.createItem(); - public static final ItemStack END_BRICKS = BlockTypes.END_BRICKS.createItem(); - public static final ItemStack END_GATEWAY = BlockTypes.END_GATEWAY.createItem(); - public static final ItemStack END_PORTAL = BlockTypes.END_PORTAL.createItem(); - public static final ItemStack END_PORTAL_FRAME = BlockTypes.END_PORTAL_FRAME.createItem(); - public static final ItemStack END_ROD = BlockTypes.END_ROD.createItem(); - public static final ItemStack END_STONE = BlockTypes.END_STONE.createItem(); - public static final ItemStack FARMLAND = BlockTypes.FARMLAND.createItem(); - public static final ItemStack FIRE = BlockTypes.FIRE.createItem(); - public static final ItemStack FLETCHING_TABLE = BlockTypes.FLETCHING_TABLE.createItem(); - public static final ItemStack FLOWER = BlockTypes.FLOWER.createItem(); - public static final ItemStack FLOWER_POT = BlockTypes.FLOWER_POT.createItem(); - public static final ItemStack FLOWING_LAVA = BlockTypes.FLOWING_LAVA.createItem(); - public static final ItemStack FLOWING_WATER = BlockTypes.FLOWING_WATER.createItem(); - public static final ItemStack FRAME = BlockTypes.FRAME.createItem(); - public static final ItemStack FROSTED_ICE = BlockTypes.FROSTED_ICE.createItem(); - public static final ItemStack FURNACE = BlockTypes.FURNACE.createItem(); - public static final ItemStack GILDED_BLACKSTONE = BlockTypes.GILDED_BLACKSTONE.createItem(); - public static final ItemStack GLASS = BlockTypes.GLASS.createItem(); - public static final ItemStack GLASS_PANE = BlockTypes.GLASS_PANE.createItem(); - public static final ItemStack GLAZED_TERRACOTTA = BlockTypes.GLAZED_TERRACOTTA.createItem(); - public static final ItemStack GLOWING_OBSIDIAN = BlockTypes.GLOWING_OBSIDIAN.createItem(); - public static final ItemStack GLOWSTONE = BlockTypes.GLOWSTONE.createItem(); - public static final ItemStack GOLDEN_RAIL = BlockTypes.GOLDEN_RAIL.createItem(); - public static final ItemStack GOLD_BLOCK = BlockTypes.GOLD_BLOCK.createItem(); - public static final ItemStack GOLD_ORE = BlockTypes.GOLD_ORE.createItem(); - public static final ItemStack GRASS = BlockTypes.GRASS.createItem(); - public static final ItemStack GRASS_PATH = BlockTypes.GRASS_PATH.createItem(); - public static final ItemStack GRAVEL = BlockTypes.GRAVEL.createItem(); - public static final ItemStack GRINDSTONE = BlockTypes.GRINDSTONE.createItem(); - public static final ItemStack HARDENED_CLAY = BlockTypes.HARDENED_CLAY.createItem(); - public static final ItemStack HARD_GLASS = BlockTypes.HARD_GLASS.createItem(); - public static final ItemStack HARD_GLASS_PANE = BlockTypes.HARD_GLASS_PANE.createItem(); - public static final ItemStack HARD_STAINED_GLASS = BlockTypes.HARD_STAINED_GLASS.createItem(); - public static final ItemStack HARD_STAINED_GLASS_PANE = BlockTypes.HARD_STAINED_GLASS_PANE.createItem(); - public static final ItemStack HAY_BLOCK = BlockTypes.HAY_BLOCK.createItem(); - public static final ItemStack HEAVY_WEIGHTED_PRESSURE_PLATE = BlockTypes.HEAVY_WEIGHTED_PRESSURE_PLATE.createItem(); - public static final ItemStack HONEYCOMB_BLOCK = BlockTypes.HONEYCOMB_BLOCK.createItem(); - public static final ItemStack HONEY_BLOCK = BlockTypes.HONEY_BLOCK.createItem(); - public static final ItemStack HOPPER = BlockTypes.HOPPER.createItem(); - public static final ItemStack ICE = BlockTypes.ICE.createItem(); - public static final ItemStack INFO_UPDATE = BlockTypes.INFO_UPDATE.createItem(); - public static final ItemStack INFO_UPDATE2 = BlockTypes.INFO_UPDATE2.createItem(); - public static final ItemStack INVISIBLE_BEDROCK = BlockTypes.INVISIBLE_BEDROCK.createItem(); - public static final ItemStack IRON_BARS = BlockTypes.IRON_BARS.createItem(); - public static final ItemStack IRON_BLOCK = BlockTypes.IRON_BLOCK.createItem(); - public static final ItemStack IRON_DOOR = BlockTypes.IRON_DOOR.createItem(); - public static final ItemStack IRON_ORE = BlockTypes.IRON_ORE.createItem(); - public static final ItemStack IRON_TRAPDOOR = BlockTypes.IRON_TRAPDOOR.createItem(); - public static final ItemStack JIGSAW = BlockTypes.JIGSAW.createItem(); - public static final ItemStack JUKEBOX = BlockTypes.JUKEBOX.createItem(); - public static final ItemStack KELP = BlockTypes.KELP.createItem(); - public static final ItemStack LADDER = BlockTypes.LADDER.createItem(); - public static final ItemStack LANTERN = BlockTypes.LANTERN.createItem(); - public static final ItemStack LAPIS_BLOCK = BlockTypes.LAPIS_BLOCK.createItem(); - public static final ItemStack LAPIS_ORE = BlockTypes.LAPIS_ORE.createItem(); - public static final ItemStack LAVA = BlockTypes.LAVA.createItem(); - public static final ItemStack LEAVES = BlockTypes.LEAVES.createItem(); - public static final ItemStack LECTERN = BlockTypes.LECTERN.createItem(); - public static final ItemStack LEVER = BlockTypes.LEVER.createItem(); - public static final ItemStack LIGHT_BLOCK = BlockTypes.LIGHT_BLOCK.createItem(); - public static final ItemStack LIGHT_WEIGHTED_PRESSURE_PLATE = BlockTypes.LIGHT_WEIGHTED_PRESSURE_PLATE.createItem(); - public static final ItemStack LIT_PUMPKIN = BlockTypes.LIT_PUMPKIN.createItem(); - public static final ItemStack LODESTONE = BlockTypes.LODESTONE.createItem(); - public static final ItemStack LOG = BlockTypes.LOG.createItem(); - public static final ItemStack LOOM = BlockTypes.LOOM.createItem(); - public static final ItemStack MAGMA = BlockTypes.MAGMA.createItem(); - public static final ItemStack MELON_BLOCK = BlockTypes.MELON_BLOCK.createItem(); - public static final ItemStack MELON_STEM = BlockTypes.MELON_STEM.createItem(); - public static final ItemStack MOB_SPAWNER = BlockTypes.MOB_SPAWNER.createItem(); - public static final ItemStack MONSTER_EGG = BlockTypes.MONSTER_EGG.createItem(); - public static final ItemStack MOSSY_COBBLESTONE = BlockTypes.MOSSY_COBBLESTONE.createItem(); - public static final ItemStack MOVING_BLOCK = BlockTypes.MOVING_BLOCK.createItem(); - public static final ItemStack MYCELIUM = BlockTypes.MYCELIUM.createItem(); - public static final ItemStack NETHERITE_BLOCK = BlockTypes.NETHERITE_BLOCK.createItem(); - public static final ItemStack NETHERRACK = BlockTypes.NETHERRACK.createItem(); - public static final ItemStack NETHER_BRICK = BlockTypes.NETHER_BRICK.createItem(); - public static final ItemStack NETHER_BRICK_FENCE = BlockTypes.NETHER_BRICK_FENCE.createItem(); - public static final ItemStack NETHER_FUNGUS = BlockTypes.NETHER_FUNGUS.createItem(); - public static final ItemStack NETHER_GOLD_ORE = BlockTypes.NETHER_GOLD_ORE.createItem(); - public static final ItemStack NETHER_NYLIUM = BlockTypes.NETHER_NYLIUM.createItem(); - public static final ItemStack NETHER_REACTOR = BlockTypes.NETHER_REACTOR.createItem(); - public static final ItemStack NETHER_ROOTS = BlockTypes.NETHER_ROOTS.createItem(); - public static final ItemStack NETHER_SPROUTS = BlockTypes.NETHER_SPROUTS.createItem(); - public static final ItemStack NETHER_WART = BlockTypes.NETHER_WART.createItem(); - public static final ItemStack NETHER_WART_BLOCK = BlockTypes.NETHER_WART_BLOCK.createItem(); - public static final ItemStack NOTEBLOCK = BlockTypes.NOTEBLOCK.createItem(); - public static final ItemStack OBSERVER = BlockTypes.OBSERVER.createItem(); - public static final ItemStack OBSIDIAN = BlockTypes.OBSIDIAN.createItem(); - public static final ItemStack PACKED_ICE = BlockTypes.PACKED_ICE.createItem(); - public static final ItemStack PISTON = BlockTypes.PISTON.createItem(); - public static final ItemStack PISTON_ARM_COLLISION = BlockTypes.PISTON_ARM_COLLISION.createItem(); - public static final ItemStack PLANKS = BlockTypes.PLANKS.createItem(); - public static final ItemStack PODZOL = BlockTypes.PODZOL.createItem(); - public static final ItemStack POLISHED_BASALT = BlockTypes.POLISHED_BASALT.createItem(); - public static final ItemStack POLISHED_BLACKSTONE = BlockTypes.POLISHED_BLACKSTONE.createItem(); - public static final ItemStack POLISHED_BLACKSTONE_BRICKS = BlockTypes.POLISHED_BLACKSTONE_BRICKS.createItem(); - public static final ItemStack PORTAL = BlockTypes.PORTAL.createItem(); - public static final ItemStack POTATOES = BlockTypes.POTATOES.createItem(); - public static final ItemStack PRISMARINE = BlockTypes.PRISMARINE.createItem(); - public static final ItemStack PUMPKIN = BlockTypes.PUMPKIN.createItem(); - public static final ItemStack PUMPKIN_STEM = BlockTypes.PUMPKIN_STEM.createItem(); - public static final ItemStack PURPUR_BLOCK = BlockTypes.PURPUR_BLOCK.createItem(); - public static final ItemStack QUARTZ_BLOCK = BlockTypes.QUARTZ_BLOCK.createItem(); - public static final ItemStack QUARTZ_BRICKS = BlockTypes.QUARTZ_BRICKS.createItem(); - public static final ItemStack QUARTZ_ORE = BlockTypes.QUARTZ_ORE.createItem(); - public static final ItemStack RAIL = BlockTypes.RAIL.createItem(); - public static final ItemStack REDSTONE_BLOCK = BlockTypes.REDSTONE_BLOCK.createItem(); - public static final ItemStack REDSTONE_LAMP = BlockTypes.REDSTONE_LAMP.createItem(); - public static final ItemStack REDSTONE_ORE = BlockTypes.REDSTONE_ORE.createItem(); - public static final ItemStack REDSTONE_TORCH = BlockTypes.REDSTONE_TORCH.createItem(); - public static final ItemStack REDSTONE_WIRE = BlockTypes.REDSTONE_WIRE.createItem(); - public static final ItemStack RED_MUSHROOM = BlockTypes.RED_MUSHROOM.createItem(); - public static final ItemStack RED_MUSHROOM_BLOCK = BlockTypes.RED_MUSHROOM_BLOCK.createItem(); - public static final ItemStack RED_SANDSTONE = BlockTypes.RED_SANDSTONE.createItem(); - public static final ItemStack REEDS = BlockTypes.REEDS.createItem(); - public static final ItemStack REPEATER = BlockTypes.REPEATER.createItem(); - public static final ItemStack REPEATING_COMMAND_BLOCK = BlockTypes.REPEATING_COMMAND_BLOCK.createItem(); - public static final ItemStack RESERVED6 = BlockTypes.RESERVED6.createItem(); - public static final ItemStack RESPAWN_ANCHOR = BlockTypes.RESPAWN_ANCHOR.createItem(); - public static final ItemStack SAND = BlockTypes.SAND.createItem(); - public static final ItemStack SANDSTONE = BlockTypes.SANDSTONE.createItem(); - public static final ItemStack SAPLING = BlockTypes.SAPLING.createItem(); - public static final ItemStack SCAFFOLDING = BlockTypes.SCAFFOLDING.createItem(); - public static final ItemStack SEAGRASS = BlockTypes.SEAGRASS.createItem(); - public static final ItemStack SEA_LANTERN = BlockTypes.SEA_LANTERN.createItem(); - public static final ItemStack SEA_PICKLE = BlockTypes.SEA_PICKLE.createItem(); - public static final ItemStack SHROOMLIGHT = BlockTypes.SHROOMLIGHT.createItem(); - public static final ItemStack SHULKER_BOX = BlockTypes.SHULKER_BOX.createItem(); - public static final ItemStack SKULL = BlockTypes.SKULL.createItem(); - public static final ItemStack SLIME = BlockTypes.SLIME.createItem(); - public static final ItemStack SMITHING_TABLE = BlockTypes.SMITHING_TABLE.createItem(); - public static final ItemStack SMOKER = BlockTypes.SMOKER.createItem(); - public static final ItemStack SMOOTH_STONE = BlockTypes.SMOOTH_STONE.createItem(); - public static final ItemStack SNOW = BlockTypes.SNOW.createItem(); - public static final ItemStack SNOW_LAYER = BlockTypes.SNOW_LAYER.createItem(); - public static final ItemStack SOUL_FIRE = BlockTypes.SOUL_FIRE.createItem(); - public static final ItemStack SOUL_SAND = BlockTypes.SOUL_SAND.createItem(); - public static final ItemStack SOUL_SOIL = BlockTypes.SOUL_SOIL.createItem(); - public static final ItemStack SPONGE = BlockTypes.SPONGE.createItem(); - public static final ItemStack STAINED_GLASS = BlockTypes.STAINED_GLASS.createItem(); - public static final ItemStack STAINED_GLASS_PANE = BlockTypes.STAINED_GLASS_PANE.createItem(); - public static final ItemStack STAINED_HARDENED_CLAY = BlockTypes.STAINED_HARDENED_CLAY.createItem(); - public static final ItemStack STANDING_BANNER = BlockTypes.STANDING_BANNER.createItem(); - public static final ItemStack STANDING_SIGN = BlockTypes.STANDING_SIGN.createItem(); - public static final ItemStack STONE = BlockTypes.STONE.createItem(); - public static final ItemStack STONEBRICK = BlockTypes.STONEBRICK.createItem(); - public static final ItemStack STONECUTTER = BlockTypes.STONECUTTER.createItem(); - public static final ItemStack STONECUTTER_BLOCK = BlockTypes.STONECUTTER_BLOCK.createItem(); - public static final ItemStack STONE_BUTTON = BlockTypes.STONE_BUTTON.createItem(); - public static final ItemStack STONE_PRESSURE_PLATE = BlockTypes.STONE_PRESSURE_PLATE.createItem(); - public static final ItemStack STONE_SLAB = BlockTypes.STONE_SLAB.createItem(); - public static final ItemStack STONE_STAIRS = BlockTypes.STONE_STAIRS.createItem(); - public static final ItemStack STONE_WALL = BlockTypes.STONE_WALL.createItem(); - public static final ItemStack STRUCTURE_BLOCK = BlockTypes.STRUCTURE_BLOCK.createItem(); - public static final ItemStack STRUCTURE_VOID = BlockTypes.STRUCTURE_VOID.createItem(); - public static final ItemStack SWEET_BERRY_BUSH = BlockTypes.SWEET_BERRY_BUSH.createItem(); - public static final ItemStack TALL_GRASS = BlockTypes.TALL_GRASS.createItem(); - public static final ItemStack TARGET = BlockTypes.TARGET.createItem(); - public static final ItemStack TNT = BlockTypes.TNT.createItem(); - public static final ItemStack TORCH = BlockTypes.TORCH.createItem(); - public static final ItemStack TRAPPED_CHEST = BlockTypes.TRAPPED_CHEST.createItem(); - public static final ItemStack TRIPWIRE = BlockTypes.TRIPWIRE.createItem(); - public static final ItemStack TRIPWIRE_HOOK = BlockTypes.TRIPWIRE_HOOK.createItem(); - public static final ItemStack TURTLE_EGG = BlockTypes.TURTLE_EGG.createItem(); - public static final ItemStack TWISTING_VINES = BlockTypes.TWISTING_VINES.createItem(); - public static final ItemStack UNDERWATER_TORCH = BlockTypes.UNDERWATER_TORCH.createItem(); - public static final ItemStack UNDYED_SHULKER_BOX = BlockTypes.UNDYED_SHULKER_BOX.createItem(); - public static final ItemStack VINE = BlockTypes.VINE.createItem(); - public static final ItemStack WALL_BANNER = BlockTypes.WALL_BANNER.createItem(); - public static final ItemStack WALL_SIGN = BlockTypes.WALL_SIGN.createItem(); - public static final ItemStack WATER = BlockTypes.WATER.createItem(); - public static final ItemStack WATERLILY = BlockTypes.WATERLILY.createItem(); - public static final ItemStack WEB = BlockTypes.WEB.createItem(); - public static final ItemStack WEEPING_VINES = BlockTypes.WEEPING_VINES.createItem(); - public static final ItemStack WHEAT = BlockTypes.WHEAT.createItem(); - public static final ItemStack WITHER_ROSE = BlockTypes.WITHER_ROSE.createItem(); - public static final ItemStack WOOD = BlockTypes.WOOD.createItem(); - public static final ItemStack WOODEN_BUTTON = BlockTypes.WOODEN_BUTTON.createItem(); - public static final ItemStack WOODEN_DOOR = BlockTypes.WOODEN_DOOR.createItem(); - public static final ItemStack WOODEN_FENCE = BlockTypes.WOODEN_FENCE.createItem(); - public static final ItemStack WOODEN_FENCE_GATE = BlockTypes.WOODEN_FENCE_GATE.createItem(); - public static final ItemStack WOODEN_PRESSURE_PLATE = BlockTypes.WOODEN_PRESSURE_PLATE.createItem(); - public static final ItemStack WOODEN_SLAB = BlockTypes.WOODEN_SLAB.createItem(); - public static final ItemStack WOODEN_STAIRS = BlockTypes.WOODEN_STAIRS.createItem(); - public static final ItemStack WOODEN_TRAPDOOR = BlockTypes.WOODEN_TRAPDOOR.createItem(); - public static final ItemStack WOOL = BlockTypes.WOOL.createItem(); - - - //items - public static final ItemStack APPLE = ItemTypes.APPLE.createItem(); - public static final ItemStack APPLE_ENCHANTED = ItemTypes.APPLE_ENCHANTED.createItem(); - public static final ItemStack ARMOR_STAND = ItemTypes.ARMOR_STAND.createItem(); - public static final ItemStack ARROW = ItemTypes.ARROW.createItem(); - public static final ItemStack BAKED_POTATO = ItemTypes.BAKED_POTATO.createItem(); - public static final ItemStack BANNER = ItemTypes.BANNER.createItem(); - public static final ItemStack BED_ITEM = ItemTypes.BED.createItem(); - public static final ItemStack BEEF = ItemTypes.BEEF.createItem(); - public static final ItemStack BEETROOT_ITEM = ItemTypes.BEETROOT.createItem(); - public static final ItemStack BEETROOT_SEEDS = ItemTypes.BEETROOT_SEEDS.createItem(); - public static final ItemStack BEETROOT_SOUP = ItemTypes.BEETROOT_SOUP.createItem(); - public static final ItemStack BLAZE_POWDER = ItemTypes.BLAZE_POWDER.createItem(); - public static final ItemStack BLAZE_ROD = ItemTypes.BLAZE_ROD.createItem(); - public static final ItemStack BOARD = ItemTypes.BOARD.createItem(); - public static final ItemStack BOAT = ItemTypes.BOAT.createItem(); - public static final ItemStack BONE = ItemTypes.BONE.createItem(); - public static final ItemStack BOOK = ItemTypes.BOOK.createItem(); - public static final ItemStack BOW = ItemTypes.BOW.createItem(); - public static final ItemStack BOWL = ItemTypes.BOWL.createItem(); - public static final ItemStack BREAD = ItemTypes.BREAD.createItem(); - public static final ItemStack BREWING_STAND_ITEM = ItemTypes.BREWING_STAND.createItem(); - public static final ItemStack BRICK = ItemTypes.BRICK.createItem(); - public static final ItemStack BUCKET = ItemTypes.BUCKET.createItem(); - public static final ItemStack CAKE_ITEM = ItemTypes.CAKE.createItem(); - public static final ItemStack CAMERA_ITEM = ItemTypes.CAMERA.createItem(); - public static final ItemStack CAMPFIRE_ITEM = ItemTypes.CAMPFIRE.createItem(); - public static final ItemStack CARROT = ItemTypes.CARROT.createItem(); - public static final ItemStack CARROT_ON_A_STICK = ItemTypes.CARROT_ON_A_STICK.createItem(); - public static final ItemStack CAULDRON_ITEM = ItemTypes.CAULDRON.createItem(); - public static final ItemStack CHAINMAIL_BOOTS = ItemTypes.CHAINMAIL_BOOTS.createItem(); - public static final ItemStack CHAINMAIL_CHESTPLATE = ItemTypes.CHAINMAIL_CHESTPLATE.createItem(); - public static final ItemStack CHAINMAIL_HELMET = ItemTypes.CHAINMAIL_HELMET.createItem(); - public static final ItemStack CHAINMAIL_LEGGINGS = ItemTypes.CHAINMAIL_LEGGINGS.createItem(); - public static final ItemStack CHEST_MINECART = ItemTypes.CHEST_MINECART.createItem(); - public static final ItemStack CHICKEN = ItemTypes.CHICKEN.createItem(); - public static final ItemStack CHORUS_FRUIT = ItemTypes.CHORUS_FRUIT.createItem(); - public static final ItemStack CHORUS_FRUIT_POPPED = ItemTypes.CHORUS_FRUIT_POPPED.createItem(); - public static final ItemStack CLAY_BALL = ItemTypes.CLAY_BALL.createItem(); - public static final ItemStack CLOCK = ItemTypes.CLOCK.createItem(); - public static final ItemStack CLOWNFISH = ItemTypes.CLOWNFISH.createItem(); - public static final ItemStack COAL = ItemTypes.COAL.createItem(); - public static final ItemStack COMMAND_BLOCK_MINECART = ItemTypes.COMMAND_BLOCK_MINECART.createItem(); - public static final ItemStack COMPARATOR_ITEM = ItemTypes.COMPARATOR.createItem(); - public static final ItemStack COMPASS = ItemTypes.COMPASS.createItem(); - public static final ItemStack COOKED_BEEF = ItemTypes.COOKED_BEEF.createItem(); - public static final ItemStack COOKED_CHICKEN = ItemTypes.COOKED_CHICKEN.createItem(); - public static final ItemStack COOKED_FISH = ItemTypes.COOKED_FISH.createItem(); - public static final ItemStack COOKED_PORKCHOP = ItemTypes.COOKED_PORKCHOP.createItem(); - public static final ItemStack COOKED_RABBIT = ItemTypes.COOKED_RABBIT.createItem(); - public static final ItemStack COOKED_SALMON = ItemTypes.COOKED_SALMON.createItem(); - public static final ItemStack COOKIE = ItemTypes.COOKIE.createItem(); - public static final ItemStack CROSSBOW = ItemTypes.CROSSBOW.createItem(); - public static final ItemStack DIAMOND = ItemTypes.DIAMOND.createItem(); - public static final ItemStack DIAMOND_AXE = ItemTypes.DIAMOND_AXE.createItem(); - public static final ItemStack DIAMOND_BOOTS = ItemTypes.DIAMOND_BOOTS.createItem(); - public static final ItemStack DIAMOND_CHESTPLATE = ItemTypes.DIAMOND_CHESTPLATE.createItem(); - public static final ItemStack DIAMOND_HELMET = ItemTypes.DIAMOND_HELMET.createItem(); - public static final ItemStack DIAMOND_HOE = ItemTypes.DIAMOND_HOE.createItem(); - public static final ItemStack DIAMOND_LEGGINGS = ItemTypes.DIAMOND_LEGGINGS.createItem(); - public static final ItemStack DIAMOND_PICKAXE = ItemTypes.DIAMOND_PICKAXE.createItem(); - public static final ItemStack DIAMOND_SHOVEL = ItemTypes.DIAMOND_SHOVEL.createItem(); - public static final ItemStack DIAMOND_SWORD = ItemTypes.DIAMOND_SWORD.createItem(); - public static final ItemStack DRAGON_BREATH = ItemTypes.DRAGON_BREATH.createItem(); - public static final ItemStack DRIED_KELP = ItemTypes.DRIED_KELP.createItem(); - public static final ItemStack DYE = ItemTypes.DYE.createItem(); - public static final ItemStack EGG = ItemTypes.EGG.createItem(); - public static final ItemStack ELYTRA = ItemTypes.ELYTRA.createItem(); - public static final ItemStack EMERALD = ItemTypes.EMERALD.createItem(); - public static final ItemStack EMPTY_MAP = ItemTypes.EMPTY_MAP.createItem(); - public static final ItemStack ENCHANTED_BOOK = ItemTypes.ENCHANTED_BOOK.createItem(); - public static final ItemStack ENDER_EYE = ItemTypes.ENDER_EYE.createItem(); - public static final ItemStack ENDER_PEARL = ItemTypes.ENDER_PEARL.createItem(); - public static final ItemStack END_CRYSTAL = ItemTypes.END_CRYSTAL.createItem(); - public static final ItemStack EXPERIENCE_BOTTLE = ItemTypes.EXPERIENCE_BOTTLE.createItem(); - public static final ItemStack FEATHER = ItemTypes.FEATHER.createItem(); - public static final ItemStack FERMENTED_SPIDER_EYE = ItemTypes.FERMENTED_SPIDER_EYE.createItem(); - public static final ItemStack FIREBALL = ItemTypes.FIREBALL.createItem(); - public static final ItemStack FIREWORKS = ItemTypes.FIREWORKS.createItem(); - public static final ItemStack FIREWORKS_CHARGE = ItemTypes.FIREWORKS_CHARGE.createItem(); - public static final ItemStack FISH = ItemTypes.FISH.createItem(); - public static final ItemStack FISHING_ROD = ItemTypes.FISHING_ROD.createItem(); - public static final ItemStack FLINT = ItemTypes.FLINT.createItem(); - public static final ItemStack FLINT_AND_STEEL = ItemTypes.FLINT_AND_STEEL.createItem(); - public static final ItemStack FLOWER_POT_ITEM = ItemTypes.FLOWER_POT.createItem(); - public static final ItemStack FRAME_ITEM = ItemTypes.FRAME.createItem(); - public static final ItemStack GHAST_TEAR = ItemTypes.GHAST_TEAR.createItem(); - public static final ItemStack GLASS_BOTTLE = ItemTypes.GLASS_BOTTLE.createItem(); - public static final ItemStack GLOWSTONE_DUST = ItemTypes.GLOWSTONE_DUST.createItem(); - public static final ItemStack GOLDEN_APPLE = ItemTypes.GOLDEN_APPLE.createItem(); - public static final ItemStack GOLDEN_AXE = ItemTypes.GOLDEN_AXE.createItem(); - public static final ItemStack GOLDEN_BOOTS = ItemTypes.GOLDEN_BOOTS.createItem(); - public static final ItemStack GOLDEN_CARROT = ItemTypes.GOLDEN_CARROT.createItem(); - public static final ItemStack GOLDEN_CHESTPLATE = ItemTypes.GOLDEN_CHESTPLATE.createItem(); - public static final ItemStack GOLDEN_HELMET = ItemTypes.GOLDEN_HELMET.createItem(); - public static final ItemStack GOLDEN_HOE = ItemTypes.GOLDEN_HOE.createItem(); - public static final ItemStack GOLDEN_LEGGINGS = ItemTypes.GOLDEN_LEGGINGS.createItem(); - public static final ItemStack GOLDEN_PICKAXE = ItemTypes.GOLDEN_PICKAXE.createItem(); - public static final ItemStack GOLDEN_SHOVEL = ItemTypes.GOLDEN_SHOVEL.createItem(); - public static final ItemStack GOLDEN_SWORD = ItemTypes.GOLDEN_SWORD.createItem(); - public static final ItemStack GOLD_INGOT = ItemTypes.GOLD_INGOT.createItem(); - public static final ItemStack GOLD_NUGGET = ItemTypes.GOLD_NUGGET.createItem(); - public static final ItemStack GUNPOWDER = ItemTypes.GUNPOWDER.createItem(); - public static final ItemStack HEART_OF_THE_SEA = ItemTypes.HEART_OF_THE_SEA.createItem(); - public static final ItemStack HONEYCOMB = ItemTypes.HONEYCOMB.createItem(); - public static final ItemStack HONEY_BOTTLE = ItemTypes.HONEY_BOTTLE.createItem(); - public static final ItemStack HOPPER_ITEM = ItemTypes.HOPPER.createItem(); - public static final ItemStack HOPPER_MINECART = ItemTypes.HOPPER_MINECART.createItem(); - public static final ItemStack HORSE_ARMOR_DIAMOND = ItemTypes.HORSE_ARMOR_DIAMOND.createItem(); - public static final ItemStack HORSE_ARMOR_GOLD = ItemTypes.HORSE_ARMOR_GOLD.createItem(); - public static final ItemStack HORSE_ARMOR_IRON = ItemTypes.HORSE_ARMOR_IRON.createItem(); - public static final ItemStack HORSE_ARMOR_LEATHER = ItemTypes.HORSE_ARMOR_LEATHER.createItem(); - public static final ItemStack IRON_AXE = ItemTypes.IRON_AXE.createItem(); - public static final ItemStack IRON_BOOTS = ItemTypes.IRON_BOOTS.createItem(); - public static final ItemStack IRON_CHESTPLATE = ItemTypes.IRON_CHESTPLATE.createItem(); - public static final ItemStack IRON_DOOR_ITEM = ItemTypes.IRON_DOOR.createItem(); - public static final ItemStack IRON_HELMET = ItemTypes.IRON_HELMET.createItem(); - public static final ItemStack IRON_HOE = ItemTypes.IRON_HOE.createItem(); - public static final ItemStack IRON_INGOT = ItemTypes.IRON_INGOT.createItem(); - public static final ItemStack IRON_LEGGINGS = ItemTypes.IRON_LEGGINGS.createItem(); - public static final ItemStack IRON_NUGGET = ItemTypes.IRON_NUGGET.createItem(); - public static final ItemStack IRON_PICKAXE = ItemTypes.IRON_PICKAXE.createItem(); - public static final ItemStack IRON_SHOVEL = ItemTypes.IRON_SHOVEL.createItem(); - public static final ItemStack IRON_SWORD = ItemTypes.IRON_SWORD.createItem(); - public static final ItemStack KELP_ITEM = ItemTypes.KELP.createItem(); - public static final ItemStack LEAD = ItemTypes.LEAD.createItem(); - public static final ItemStack LEATHER = ItemTypes.LEATHER.createItem(); - public static final ItemStack LEATHER_BOOTS = ItemTypes.LEATHER_BOOTS.createItem(); - public static final ItemStack LEATHER_CHESTPLATE = ItemTypes.LEATHER_CHESTPLATE.createItem(); - public static final ItemStack LEATHER_HELMET = ItemTypes.LEATHER_HELMET.createItem(); - public static final ItemStack LEATHER_LEGGINGS = ItemTypes.LEATHER_LEGGINGS.createItem(); - public static final ItemStack LINGERING_POTION = ItemTypes.LINGERING_POTION.createItem(); - public static final ItemStack MAGMA_CREAM = ItemTypes.MAGMA_CREAM.createItem(); - public static final ItemStack MAP = ItemTypes.MAP.createItem(); - public static final ItemStack MELON = ItemTypes.MELON.createItem(); - public static final ItemStack MELON_SEEDS = ItemTypes.MELON_SEEDS.createItem(); - public static final ItemStack MINECART = ItemTypes.MINECART.createItem(); - public static final ItemStack MUSHROOM_STEW = ItemTypes.MUSHROOM_STEW.createItem(); - public static final ItemStack MUTTON_COOKED = ItemTypes.MUTTON_COOKED.createItem(); - public static final ItemStack MUTTON_RAW = ItemTypes.MUTTON_RAW.createItem(); - public static final ItemStack NAME_TAG = ItemTypes.NAME_TAG.createItem(); - public static final ItemStack NAUTILUS_SHELL = ItemTypes.NAUTILUS_SHELL.createItem(); - public static final ItemStack NETHERBRICK = ItemTypes.NETHERBRICK.createItem(); - public static final ItemStack NETHERITE_AXE = ItemTypes.NETHERITE_AXE.createItem(); - public static final ItemStack NETHERITE_BOOTS = ItemTypes.NETHERITE_BOOTS.createItem(); - public static final ItemStack NETHERITE_CHESTPLATE = ItemTypes.NETHERITE_CHESTPLATE.createItem(); - public static final ItemStack NETHERITE_HELMET = ItemTypes.NETHERITE_HELMET.createItem(); - public static final ItemStack NETHERITE_HOE = ItemTypes.NETHERITE_HOE.createItem(); - public static final ItemStack NETHERITE_LEGGINGS = ItemTypes.NETHERITE_LEGGINGS.createItem(); - public static final ItemStack NETHERITE_PICKAXE = ItemTypes.NETHERITE_PICKAXE.createItem(); - public static final ItemStack NETHERITE_SHOVEL = ItemTypes.NETHERITE_SHOVEL.createItem(); - public static final ItemStack NETHERITE_SWORD = ItemTypes.NETHERITE_SWORD.createItem(); - public static final ItemStack NETHER_STAR = ItemTypes.NETHER_STAR.createItem(); - public static final ItemStack NETHER_WART_ITEM = ItemTypes.NETHER_WART.createItem(); - public static final ItemStack PAINTING = ItemTypes.PAINTING.createItem(); - public static final ItemStack PAPER = ItemTypes.PAPER.createItem(); - public static final ItemStack PHANTOM_MEMBRANE = ItemTypes.PHANTOM_MEMBRANE.createItem(); - public static final ItemStack POISONOUS_POTATO = ItemTypes.POISONOUS_POTATO.createItem(); - public static final ItemStack PORKCHOP = ItemTypes.PORKCHOP.createItem(); - public static final ItemStack PORTFOLIO = ItemTypes.PORTFOLIO.createItem(); - public static final ItemStack POTATO = ItemTypes.POTATO.createItem(); - public static final ItemStack POTION = ItemTypes.POTION.createItem(); - public static final ItemStack PRISMARINE_CRYSTALS = ItemTypes.PRISMARINE_CRYSTALS.createItem(); - public static final ItemStack PRISMARINE_SHARD = ItemTypes.PRISMARINE_SHARD.createItem(); - public static final ItemStack PUFFERFISH = ItemTypes.PUFFERFISH.createItem(); - public static final ItemStack PUMPKIN_PIE = ItemTypes.PUMPKIN_PIE.createItem(); - public static final ItemStack PUMPKIN_SEEDS = ItemTypes.PUMPKIN_SEEDS.createItem(); - public static final ItemStack QUARTZ = ItemTypes.QUARTZ.createItem(); - public static final ItemStack RABBIT = ItemTypes.RABBIT.createItem(); - public static final ItemStack RABBIT_FOOT = ItemTypes.RABBIT_FOOT.createItem(); - public static final ItemStack RABBIT_HIDE = ItemTypes.RABBIT_HIDE.createItem(); - public static final ItemStack RABBIT_STEW = ItemTypes.RABBIT_STEW.createItem(); - public static final ItemStack RECORD = ItemTypes.RECORD.createItem(); - public static final ItemStack REDSTONE = ItemTypes.REDSTONE.createItem(); - public static final ItemStack REEDS_ITEM = ItemTypes.REEDS.createItem(); - public static final ItemStack REPEATER_ITEM = ItemTypes.REPEATER.createItem(); - public static final ItemStack ROTTEN_FLESH = ItemTypes.ROTTEN_FLESH.createItem(); - public static final ItemStack SADDLE = ItemTypes.SADDLE.createItem(); - public static final ItemStack SALMON = ItemTypes.SALMON.createItem(); - public static final ItemStack SHEARS = ItemTypes.SHEARS.createItem(); - public static final ItemStack SHIELD = ItemTypes.SHIELD.createItem(); - public static final ItemStack SHULKER_SHELL = ItemTypes.SHULKER_SHELL.createItem(); - public static final ItemStack SIGN = ItemTypes.SIGN.createItem(); - public static final ItemStack SKULL_ITEM = ItemTypes.SKULL.createItem(); - public static final ItemStack SLIME_BALL = ItemTypes.SLIME_BALL.createItem(); - public static final ItemStack SNOWBALL = ItemTypes.SNOWBALL.createItem(); - //public static final ItemStack SPAWN_EGG = ItemTypes.SPAWN_EGG.createItem(); - public static final ItemStack SPECKLED_MELON = ItemTypes.SPECKLED_MELON.createItem(); - public static final ItemStack SPIDER_EYE = ItemTypes.SPIDER_EYE.createItem(); - public static final ItemStack SPLASH_POTION = ItemTypes.SPLASH_POTION.createItem(); - public static final ItemStack STICK = ItemTypes.STICK.createItem(); - public static final ItemStack STONE_AXE = ItemTypes.STONE_AXE.createItem(); - public static final ItemStack STONE_HOE = ItemTypes.STONE_HOE.createItem(); - public static final ItemStack STONE_PICKAXE = ItemTypes.STONE_PICKAXE.createItem(); - public static final ItemStack STONE_SHOVEL = ItemTypes.STONE_SHOVEL.createItem(); - public static final ItemStack STONE_SWORD = ItemTypes.STONE_SWORD.createItem(); - public static final ItemStack STRING = ItemTypes.STRING.createItem(); - public static final ItemStack SUGAR = ItemTypes.SUGAR.createItem(); - public static final ItemStack SWEET_BERRIES = ItemTypes.SWEET_BERRIES.createItem(); - public static final ItemStack TNT_MINECART = ItemTypes.TNT_MINECART.createItem(); - public static final ItemStack TOTEM = ItemTypes.TOTEM.createItem(); - public static final ItemStack TRIDENT = ItemTypes.TRIDENT.createItem(); - public static final ItemStack TURTLE_HELMET = ItemTypes.TURTLE_HELMET.createItem(); - public static final ItemStack TURTLE_SHELL_PIECE = ItemTypes.TURTLE_SHELL_PIECE.createItem(); - public static final ItemStack WHEAT_ITEM = ItemTypes.WHEAT.createItem(); - public static final ItemStack WHEAT_SEEDS = ItemTypes.WHEAT_SEEDS.createItem(); - public static final ItemStack WOODEN_AXE = ItemTypes.WOODEN_AXE.createItem(); - public static final ItemStack WOODEN_DOOR_ITEM = ItemTypes.WOODEN_DOOR.createItem(); - public static final ItemStack WOODEN_HOE = ItemTypes.WOODEN_HOE.createItem(); - public static final ItemStack WOODEN_PICKAXE = ItemTypes.WOODEN_PICKAXE.createItem(); - public static final ItemStack WOODEN_SHOVEL = ItemTypes.WOODEN_SHOVEL.createItem(); - public static final ItemStack WOODEN_SWORD = ItemTypes.WOODEN_SWORD.createItem(); - public static final ItemStack WRITABLE_BOOK = ItemTypes.WRITABLE_BOOK.createItem(); - public static final ItemStack WRITTEN_BOOK = ItemTypes.WRITTEN_BOOK.createItem(); -*/ -} diff --git a/src/main/java/org/cloudburstmc/api/item/ItemType.java b/src/main/java/org/cloudburstmc/api/item/ItemType.java index 13239b4..d8fef51 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemType.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemType.java @@ -2,60 +2,47 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.block.BlockType; +import org.cloudburstmc.api.block.trait.BlockTrait; import org.cloudburstmc.api.util.Identifier; -public sealed interface ItemType permits BlockType, ItemTypes.IntItem { - Identifier getId(); +import java.util.Arrays; +import java.util.Collections; +import java.util.LinkedHashSet; - boolean isBlock(); +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; - boolean isPlaceable(); +public sealed class ItemType permits BlockType { - @Nullable - BlockType getBlock(); - - @Nullable - Class getMetadataClass(); - - int getMaximumStackSize(); - - default ItemStack createItem() { - return createItem(1); - } - - ItemStack createItem(int amount, Object... metadata); + private final Identifier id; + private final Class metadataClass; - default int getAttackDamage() { - return 2; + protected ItemType(Identifier id, Class metadataClass) { + this.id = id; + this.metadataClass = metadataClass; } - default int getArmorPoints() { - return 0; + public final Identifier getId() { + return id; } - default int getToughness() { - return 0; + @Nullable + public final Class getMetadataClass() { + return metadataClass; } - default int getDurability() { - return 0; + @Override + public String toString() { + return "ItemType{id=" + id + ')'; } - default short getFuelTime() { - return 0; + public static ItemType of(Identifier id) { + return of(id, null); } - default BlockType getBlockType() { - return null; - } + public static ItemType of(Identifier id, Class metadataClass) { + checkNotNull(id, "id"); - default boolean isStackable() { - return getMaximumStackSize() > 1; + return new ItemType(id, metadataClass); } - - @Nullable - ToolType getToolType(); - - @Nullable - TierType getTierType(); } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemTypes.java b/src/main/java/org/cloudburstmc/api/item/ItemTypes.java index 7d26efa..c51955c 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemTypes.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemTypes.java @@ -1,5 +1,6 @@ package org.cloudburstmc.api.item; +import lombok.experimental.UtilityClass; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.block.BlockTypes; @@ -17,507 +18,242 @@ import static org.cloudburstmc.api.item.TierTypes.*; import static org.cloudburstmc.api.item.ToolTypes.*; +@UtilityClass public class ItemTypes { - private static final Map BY_ID = new IdentityHashMap<>(); - private static final Map BLOCKS_BY_ID = new IdentityHashMap<>(); - - public static final ItemType IRON_SHOVEL = IntItem.builder().id(ItemIds.IRON_SHOVEL).maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(IRON).attackDamage(4).build(); - public static final ItemType IRON_PICKAXE = IntItem.builder().id(ItemIds.IRON_PICKAXE).maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(IRON).attackDamage(4).build(); - public static final ItemType IRON_AXE = IntItem.builder().id(ItemIds.IRON_AXE).maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(IRON).attackDamage(6).build(); - public static final ItemType FLINT_AND_STEEL = IntItem.builder().id(ItemIds.FLINT_AND_STEEL).maxStackSize(1).build(); - public static final ItemType APPLE = IntItem.builder().id(ItemIds.APPLE).maxStackSize(64).build(); - public static final ItemType BOW = IntItem.builder().id(ItemIds.BOW).maxStackSize(1).fuelTime((short) 200).build(); - public static final ItemType ARROW = IntItem.builder().id(ItemIds.ARROW).maxStackSize(64).build(); - public static final ItemType COAL = IntItem.builder().id(ItemIds.COAL).maxStackSize(64).data(Coal.class).fuelTime((short) 1600).build(); - public static final ItemType DIAMOND = IntItem.builder().id(ItemIds.DIAMOND).maxStackSize(64).build(); - public static final ItemType IRON_INGOT = IntItem.builder().id(ItemIds.IRON_INGOT).maxStackSize(64).build(); - public static final ItemType GOLD_INGOT = IntItem.builder().id(ItemIds.GOLD_INGOT).maxStackSize(64).build(); - public static final ItemType IRON_SWORD = IntItem.builder().id(ItemIds.IRON_SWORD).maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(IRON).attackDamage(7).build(); - public static final ItemType WOODEN_SWORD = IntItem.builder().id(ItemIds.WOODEN_SWORD).maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(WOOD).attackDamage(5).fuelTime((short) 200).build(); - public static final ItemType WOODEN_SHOVEL = IntItem.builder().id(ItemIds.WOODEN_SHOVEL).maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(WOOD).attackDamage(2).fuelTime((short) 200).build(); - public static final ItemType WOODEN_PICKAXE = IntItem.builder().id(ItemIds.WOODEN_PICKAXE).maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(WOOD).attackDamage(2).fuelTime((short) 200).build(); - public static final ItemType WOODEN_AXE = IntItem.builder().id(ItemIds.WOODEN_AXE).maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(WOOD).attackDamage(4).fuelTime((short) 200).build(); - public static final ItemType STONE_SWORD = IntItem.builder().id(ItemIds.STONE_SWORD).maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(STONE).attackDamage(6).build(); - public static final ItemType STONE_SHOVEL = IntItem.builder().id(ItemIds.STONE_SHOVEL).maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(STONE).attackDamage(3).build(); - public static final ItemType STONE_PICKAXE = IntItem.builder().id(ItemIds.STONE_PICKAXE).maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(STONE).attackDamage(3).build(); - public static final ItemType STONE_AXE = IntItem.builder().id(ItemIds.STONE_AXE).maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(STONE).attackDamage(5).build(); - public static final ItemType DIAMOND_SWORD = IntItem.builder().id(ItemIds.DIAMOND_SWORD).maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(TierTypes.DIAMOND).attackDamage(8).build(); - public static final ItemType DIAMOND_SHOVEL = IntItem.builder().id(ItemIds.DIAMOND_SHOVEL).maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(TierTypes.DIAMOND).attackDamage(5).build(); - public static final ItemType DIAMOND_PICKAXE = IntItem.builder().id(ItemIds.DIAMOND_PICKAXE).maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(TierTypes.DIAMOND).attackDamage(5).build(); - public static final ItemType DIAMOND_AXE = IntItem.builder().id(ItemIds.DIAMOND_AXE).maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(TierTypes.DIAMOND).attackDamage(7).build(); - public static final ItemType STICK = IntItem.builder().id(ItemIds.STICK).maxStackSize(64).fuelTime((short) 100).build(); - public static final ItemType BOWL = IntItem.builder().id(ItemIds.BOWL).maxStackSize(64).fuelTime((short) 200).build(); - public static final ItemType MUSHROOM_STEW = IntItem.builder().id(ItemIds.MUSHROOM_STEW).maxStackSize(1).build(); - public static final ItemType GOLDEN_SWORD = IntItem.builder().id(ItemIds.GOLDEN_SWORD).maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(GOLD).attackDamage(5).build(); - public static final ItemType GOLDEN_SHOVEL = IntItem.builder().id(ItemIds.GOLDEN_SHOVEL).maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(GOLD).attackDamage(2).build(); - public static final ItemType GOLDEN_PICKAXE = IntItem.builder().id(ItemIds.GOLDEN_PICKAXE).maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(GOLD).attackDamage(2).build(); - public static final ItemType GOLDEN_AXE = IntItem.builder().id(ItemIds.GOLDEN_AXE).maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(GOLD).attackDamage(4).build(); - public static final ItemType STRING = IntItem.builder().id(ItemIds.STRING).maxStackSize(64).blockType(BlockTypes.TRIPWIRE).build(); - public static final ItemType FEATHER = IntItem.builder().id(ItemIds.FEATHER).maxStackSize(64).build(); - public static final ItemType GUNPOWDER = IntItem.builder().id(ItemIds.GUNPOWDER).maxStackSize(64).build(); - public static final ItemType WOODEN_HOE = IntItem.builder().id(ItemIds.WOODEN_HOE).maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(WOOD).attackDamage(2).fuelTime((short) 200).build(); - public static final ItemType STONE_HOE = IntItem.builder().id(ItemIds.STONE_HOE).maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(STONE).attackDamage(3).build(); - public static final ItemType IRON_HOE = IntItem.builder().id(ItemIds.IRON_HOE).maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(IRON).attackDamage(4).build(); - public static final ItemType DIAMOND_HOE = IntItem.builder().id(ItemIds.DIAMOND_HOE).maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(TierTypes.DIAMOND).attackDamage(5).build(); - public static final ItemType GOLDEN_HOE = IntItem.builder().id(ItemIds.GOLDEN_HOE).maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(GOLD).attackDamage(2).build(); - public static final ItemType WHEAT_SEEDS = IntItem.builder().id(ItemIds.WHEAT_SEEDS).maxStackSize(64).blockType(BlockTypes.WHEAT).build(); - public static final ItemType WHEAT = IntItem.builder().id(ItemIds.WHEAT).maxStackSize(64).build(); - public static final ItemType BREAD = IntItem.builder().id(ItemIds.BREAD).maxStackSize(64).build(); - public static final ItemType LEATHER_HELMET = IntItem.builder().id(ItemIds.LEATHER_HELMET).maxStackSize(1).tierType(TierTypes.LEATHER).build(); //TODO: color meta - public static final ItemType LEATHER_CHESTPLATE = IntItem.builder().id(ItemIds.LEATHER_CHESTPLATE).maxStackSize(1).tierType(TierTypes.LEATHER).build(); //TODO: color meta - public static final ItemType LEATHER_LEGGINGS = IntItem.builder().id(ItemIds.LEATHER_LEGGINGS).maxStackSize(1).tierType(TierTypes.LEATHER).build(); //TODO: color meta - public static final ItemType LEATHER_BOOTS = IntItem.builder().id(ItemIds.LEATHER_BOOTS).maxStackSize(1).tierType(TierTypes.LEATHER).build(); //TODO: color meta - public static final ItemType CHAINMAIL_HELMET = IntItem.builder().id(ItemIds.CHAINMAIL_HELMET).maxStackSize(1).tierType(CHAINMAIL).build(); - public static final ItemType CHAINMAIL_CHESTPLATE = IntItem.builder().id(ItemIds.CHAINMAIL_CHESTPLATE).maxStackSize(1).tierType(CHAINMAIL).build(); - public static final ItemType CHAINMAIL_LEGGINGS = IntItem.builder().id(ItemIds.CHAINMAIL_LEGGINGS).maxStackSize(1).tierType(CHAINMAIL).build(); - public static final ItemType CHAINMAIL_BOOTS = IntItem.builder().id(ItemIds.CHAINMAIL_BOOTS).maxStackSize(1).tierType(CHAINMAIL).build(); - public static final ItemType IRON_HELMET = IntItem.builder().id(ItemIds.IRON_HELMET).maxStackSize(1).tierType(IRON).build(); - public static final ItemType IRON_CHESTPLATE = IntItem.builder().id(ItemIds.IRON_CHESTPLATE).maxStackSize(1).tierType(IRON).build(); - public static final ItemType IRON_LEGGINGS = IntItem.builder().id(ItemIds.IRON_LEGGINGS).maxStackSize(1).tierType(IRON).build(); - public static final ItemType IRON_BOOTS = IntItem.builder().id(ItemIds.IRON_BOOTS).maxStackSize(1).tierType(IRON).build(); - public static final ItemType DIAMOND_HELMET = IntItem.builder().id(ItemIds.DIAMOND_HELMET).maxStackSize(1).tierType(TierTypes.DIAMOND).build(); - public static final ItemType DIAMOND_CHESTPLATE = IntItem.builder().id(ItemIds.DIAMOND_CHESTPLATE).maxStackSize(1).tierType(TierTypes.DIAMOND).build(); - public static final ItemType DIAMOND_LEGGINGS = IntItem.builder().id(ItemIds.DIAMOND_LEGGINGS).maxStackSize(1).tierType(TierTypes.DIAMOND).build(); - public static final ItemType DIAMOND_BOOTS = IntItem.builder().id(ItemIds.DIAMOND_BOOTS).maxStackSize(1).tierType(TierTypes.DIAMOND).build(); - public static final ItemType GOLDEN_HELMET = IntItem.builder().id(ItemIds.GOLDEN_HELMET).maxStackSize(1).tierType(GOLD).build(); - public static final ItemType GOLDEN_CHESTPLATE = IntItem.builder().id(ItemIds.GOLDEN_CHESTPLATE).maxStackSize(1).tierType(GOLD).build(); - public static final ItemType GOLDEN_LEGGINGS = IntItem.builder().id(ItemIds.GOLDEN_LEGGINGS).maxStackSize(1).tierType(GOLD).build(); - public static final ItemType GOLDEN_BOOTS = IntItem.builder().id(ItemIds.GOLDEN_BOOTS).maxStackSize(1).tierType(GOLD).build(); - public static final ItemType FLINT = IntItem.builder().id(ItemIds.FLINT).maxStackSize(64).build(); - public static final ItemType PORKCHOP = IntItem.builder().id(ItemIds.PORKCHOP).maxStackSize(64).build(); - public static final ItemType COOKED_PORKCHOP = IntItem.builder().id(ItemIds.COOKED_PORKCHOP).maxStackSize(64).build(); - public static final ItemType PAINTING = IntItem.builder().id(ItemIds.PAINTING).maxStackSize(64).build(); - public static final ItemType GOLDEN_APPLE = IntItem.builder().id(ItemIds.GOLDEN_APPLE).maxStackSize(64).build(); - public static final ItemType SIGN = IntItem.builder().id(ItemIds.SIGN).maxStackSize(16).blockType(BlockTypes.STANDING_SIGN).data(TreeSpecies.class).build(); - public static final ItemType WOODEN_DOOR = IntItem.builder().id(ItemIds.WOODEN_DOOR).maxStackSize(64).blockType(BlockTypes.WOODEN_DOOR).data(TreeSpecies.class).build(); - public static final ItemType BUCKET = IntItem.builder().id(ItemIds.BUCKET).data(Bucket.class).maxStackSize(16).build(); - public static final ItemType MINECART = IntItem.builder().id(ItemIds.MINECART).maxStackSize(1).build(); - public static final ItemType SADDLE = IntItem.builder().id(ItemIds.SADDLE).maxStackSize(1).build(); - public static final ItemType IRON_DOOR = IntItem.builder().id(ItemIds.IRON_DOOR).maxStackSize(64).blockType(BlockTypes.IRON_DOOR).build(); - public static final ItemType REDSTONE = IntItem.builder().id(ItemIds.REDSTONE).maxStackSize(64).blockType(BlockTypes.REDSTONE_WIRE).build(); - public static final ItemType SNOWBALL = IntItem.builder().id(ItemIds.SNOWBALL).maxStackSize(16).build(); - public static final ItemType BOAT = IntItem.builder().id(ItemIds.BOAT).maxStackSize(1).fuelTime((short) 1200).build(); - public static final ItemType LEATHER = IntItem.builder().id(ItemIds.LEATHER).maxStackSize(64).build(); - public static final ItemType KELP = IntItem.builder().id(ItemIds.KELP).maxStackSize(64).blockType(BlockTypes.KELP).build(); - public static final ItemType BRICK = IntItem.builder().id(ItemIds.BRICK).maxStackSize(64).build(); - public static final ItemType CLAY_BALL = IntItem.builder().id(ItemIds.CLAY_BALL).maxStackSize(64).build(); - public static final ItemType REEDS = IntItem.builder().id(ItemIds.SUGAR_CANE).maxStackSize(64).blockType(BlockTypes.REEDS).build(); - public static final ItemType PAPER = IntItem.builder().id(ItemIds.PAPER).maxStackSize(64).build(); - public static final ItemType BOOK = IntItem.builder().id(ItemIds.BOOK).maxStackSize(64).build(); - public static final ItemType SLIME_BALL = IntItem.builder().id(ItemIds.SLIME_BALL).maxStackSize(64).build(); - public static final ItemType CHEST_MINECART = IntItem.builder().id(ItemIds.CHEST_MINECART).maxStackSize(1).build(); - public static final ItemType EGG = IntItem.builder().id(ItemIds.EGG).maxStackSize(16).build(); - public static final ItemType COMPASS = IntItem.builder().id(ItemIds.COMPASS).maxStackSize(64).build(); - public static final ItemType FISHING_ROD = IntItem.builder().id(ItemIds.FISHING_ROD).maxStackSize(1).fuelTime((short) 300).build(); - public static final ItemType CLOCK = IntItem.builder().id(ItemIds.CLOCK).maxStackSize(64).build(); - public static final ItemType GLOWSTONE_DUST = IntItem.builder().id(ItemIds.GLOWSTONE_DUST).maxStackSize(64).build(); - public static final ItemType FISH = IntItem.builder().id(ItemIds.COD).maxStackSize(64).build(); - public static final ItemType COOKED_FISH = IntItem.builder().id(ItemIds.COOKED_COD).maxStackSize(64).build(); - public static final ItemType DYE = IntItem.builder().id(ItemIds.INK_SAC).maxStackSize(64).data(DyeColor.class).build(); - public static final ItemType BONE = IntItem.builder().id(ItemIds.BONE).maxStackSize(64).build(); - public static final ItemType SUGAR = IntItem.builder().id(ItemIds.SUGAR).maxStackSize(64).build(); - public static final ItemType CAKE = IntItem.builder().id(ItemIds.CAKE).maxStackSize(1).build(); - public static final ItemType BED = IntItem.builder().id(ItemIds.BED).maxStackSize(1).data(DyeColor.class).build(); - public static final ItemType REPEATER = IntItem.builder().id(ItemIds.REPEATER).maxStackSize(64).blockType(BlockTypes.REPEATER).build(); - public static final ItemType COOKIE = IntItem.builder().id(ItemIds.COOKIE).maxStackSize(64).build(); - public static final ItemType MAP = IntItem.builder().id(ItemIds.MAP).maxStackSize(64).build(); - public static final ItemType SHEARS = IntItem.builder().id(ItemIds.SHEARS).maxStackSize(1).data(Damageable.class).toolType(ToolTypes.SHEARS).build(); - public static final ItemType MELON = IntItem.builder().id(ItemIds.MELON).maxStackSize(64).build(); - public static final ItemType PUMPKIN_SEEDS = IntItem.builder().id(ItemIds.PUMPKIN_SEEDS).maxStackSize(64).blockType(BlockTypes.PUMPKIN_STEM).build(); - public static final ItemType MELON_SEEDS = IntItem.builder().id(ItemIds.MELON_SEEDS).maxStackSize(64).blockType(BlockTypes.MELON_STEM).build(); - public static final ItemType BEEF = IntItem.builder().id(ItemIds.BEEF).maxStackSize(64).build(); - public static final ItemType COOKED_BEEF = IntItem.builder().id(ItemIds.COOKED_BEEF).maxStackSize(64).build(); - public static final ItemType CHICKEN = IntItem.builder().id(ItemIds.CHICKEN).maxStackSize(64).build(); - public static final ItemType COOKED_CHICKEN = IntItem.builder().id(ItemIds.COOKED_CHICKEN).maxStackSize(64).build(); - public static final ItemType ROTTEN_FLESH = IntItem.builder().id(ItemIds.ROTTEN_FLESH).maxStackSize(64).build(); - public static final ItemType ENDER_PEARL = IntItem.builder().id(ItemIds.ENDER_PEARL).maxStackSize(64).build(); - public static final ItemType BLAZE_ROD = IntItem.builder().id(ItemIds.BLAZE_ROD).maxStackSize(64).fuelTime((short) 2400).build(); - public static final ItemType GHAST_TEAR = IntItem.builder().id(ItemIds.GHAST_TEAR).maxStackSize(64).build(); - public static final ItemType GOLD_NUGGET = IntItem.builder().id(ItemIds.GOLD_NUGGET).maxStackSize(64).build(); - public static final ItemType NETHER_WART = IntItem.builder().id(ItemIds.NETHER_WART).maxStackSize(64).blockType(BlockTypes.NETHER_WART).build(); - public static final ItemType POTION = IntItem.builder().id(ItemIds.POTION).maxStackSize(1).build(); - public static final ItemType GLASS_BOTTLE = IntItem.builder().id(ItemIds.GLASS_BOTTLE).maxStackSize(64).build(); - public static final ItemType SPIDER_EYE = IntItem.builder().id(ItemIds.SPIDER_EYE).maxStackSize(64).build(); - public static final ItemType FERMENTED_SPIDER_EYE = IntItem.builder().id(ItemIds.FERMENTED_SPIDER_EYE).maxStackSize(64).build(); - public static final ItemType BLAZE_POWDER = IntItem.builder().id(ItemIds.BLAZE_POWDER).maxStackSize(64).build(); - public static final ItemType MAGMA_CREAM = IntItem.builder().id(ItemIds.MAGMA_CREAM).maxStackSize(64).build(); - public static final ItemType BREWING_STAND = IntItem.builder().id(ItemIds.BREWING_STAND).maxStackSize(64).blockType(BlockTypes.BREWING_STAND).build(); - public static final ItemType CAULDRON = IntItem.builder().id(ItemIds.CAULDRON).maxStackSize(64).blockType(BlockTypes.CAULDRON).build(); - public static final ItemType ENDER_EYE = IntItem.builder().id(ItemIds.ENDER_EYE).maxStackSize(64).build(); - public static final ItemType SPECKLED_MELON = IntItem.builder().id(ItemIds.SPECKLED_MELON).maxStackSize(64).build(); - public static final ItemType SPAWN_EGG = IntItem.builder().id(ItemIds.SPAWN_EGG).maxStackSize(64).build(); - public static final ItemType EXPERIENCE_BOTTLE = IntItem.builder().id(ItemIds.EXPERIENCE_BOTTLE).maxStackSize(64).build(); - public static final ItemType FIREBALL = IntItem.builder().id(ItemIds.FIRE_CHARGE).maxStackSize(64).build(); - public static final ItemType WRITABLE_BOOK = IntItem.builder().id(ItemIds.WRITABLE_BOOK).maxStackSize(1).build(); - public static final ItemType WRITTEN_BOOK = IntItem.builder().id(ItemIds.WRITTEN_BOOK).maxStackSize(16).build(); - public static final ItemType EMERALD = IntItem.builder().id(ItemIds.EMERALD).maxStackSize(64).build(); - public static final ItemType FRAME = IntItem.builder().id(ItemIds.FRAME).maxStackSize(64).blockType(BlockTypes.FRAME).build(); - public static final ItemType FLOWER_POT = IntItem.builder().id(ItemIds.FLOWER_POT).maxStackSize(64).blockType(BlockTypes.FLOWER_POT).build(); - public static final ItemType CARROT = IntItem.builder().id(ItemIds.CARROT).maxStackSize(64).build(); - public static final ItemType POTATO = IntItem.builder().id(ItemIds.POTATO).maxStackSize(64).build(); - public static final ItemType BAKED_POTATO = IntItem.builder().id(ItemIds.BAKED_POTATO).maxStackSize(64).build(); - public static final ItemType POISONOUS_POTATO = IntItem.builder().id(ItemIds.POISONOUS_POTATO).maxStackSize(64).build(); - public static final ItemType EMPTY_MAP = IntItem.builder().id(ItemIds.EMPTY_MAP).maxStackSize(64).build(); - public static final ItemType GOLDEN_CARROT = IntItem.builder().id(ItemIds.GOLDEN_CARROT).maxStackSize(64).build(); - public static final ItemType SKULL = IntItem.builder().id(ItemIds.SKULL).maxStackSize(64).build(); //TODO: skull type - public static final ItemType CARROT_ON_A_STICK = IntItem.builder().id(ItemIds.CARROT_ON_A_STICK).maxStackSize(1).build(); - public static final ItemType NETHER_STAR = IntItem.builder().id(ItemIds.NETHER_STAR).maxStackSize(64).build(); - public static final ItemType PUMPKIN_PIE = IntItem.builder().id(ItemIds.PUMPKIN_PIE).maxStackSize(64).build(); - public static final ItemType FIREWORKS = IntItem.builder().id(ItemIds.FIREWORK_ROCKET).maxStackSize(64).build(); - public static final ItemType FIREWORKS_CHARGE = IntItem.builder().id(ItemIds.FIREWORKS_CHARGE).maxStackSize(64).build(); - public static final ItemType ENCHANTED_BOOK = IntItem.builder().id(ItemIds.ENCHANTED_BOOK).maxStackSize(1).build(); - public static final ItemType COMPARATOR = IntItem.builder().id(ItemIds.COMPARATOR).maxStackSize(64).blockType(BlockTypes.COMPARATOR).build(); - public static final ItemType NETHERBRICK = IntItem.builder().id(ItemIds.NETHERBRICK).maxStackSize(64).build(); - public static final ItemType QUARTZ = IntItem.builder().id(ItemIds.QUARTZ).maxStackSize(64).build(); - public static final ItemType TNT_MINECART = IntItem.builder().id(ItemIds.TNT_MINECART).maxStackSize(1).build(); - public static final ItemType HOPPER_MINECART = IntItem.builder().id(ItemIds.HOPPER_MINECART).maxStackSize(1).build(); - public static final ItemType PRISMARINE_SHARD = IntItem.builder().id(ItemIds.PRISMARINE_SHARD).maxStackSize(64).build(); - public static final ItemType HOPPER = IntItem.builder().id(ItemIds.HOPPER).maxStackSize(64).blockType(BlockTypes.HOPPER).build(); - public static final ItemType RABBIT = IntItem.builder().id(ItemIds.RABBIT).maxStackSize(64).build(); - public static final ItemType COOKED_RABBIT = IntItem.builder().id(ItemIds.COOKED_RABBIT).maxStackSize(64).build(); - public static final ItemType RABBIT_STEW = IntItem.builder().id(ItemIds.RABBIT_STEW).maxStackSize(64).build(); - public static final ItemType RABBIT_FOOT = IntItem.builder().id(ItemIds.RABBIT_FOOT).maxStackSize(64).build(); - public static final ItemType RABBIT_HIDE = IntItem.builder().id(ItemIds.RABBIT_HIDE).maxStackSize(64).build(); - public static final ItemType HORSE_ARMOR_LEATHER = IntItem.builder().id(ItemIds.HORSE_ARMOR_LEATHER).maxStackSize(1).build(); - public static final ItemType HORSE_ARMOR_IRON = IntItem.builder().id(ItemIds.HORSE_ARMOR_IRON).maxStackSize(1).build(); - public static final ItemType HORSE_ARMOR_GOLD = IntItem.builder().id(ItemIds.HORSE_ARMOR_GOLD).maxStackSize(1).build(); - public static final ItemType HORSE_ARMOR_DIAMOND = IntItem.builder().id(ItemIds.HORSE_ARMOR_DIAMOND).maxStackSize(1).build(); - public static final ItemType LEAD = IntItem.builder().id(ItemIds.LEAD).maxStackSize(64).build(); - public static final ItemType NAME_TAG = IntItem.builder().id(ItemIds.NAME_TAG).maxStackSize(64).build(); - public static final ItemType PRISMARINE_CRYSTALS = IntItem.builder().id(ItemIds.PRISMARINE_CRYSTALS).maxStackSize(64).build(); - public static final ItemType MUTTON_RAW = IntItem.builder().id(ItemIds.MUTTON_RAW).maxStackSize(64).build(); - public static final ItemType MUTTON_COOKED = IntItem.builder().id(ItemIds.MUTTON_COOKED).maxStackSize(64).build(); - public static final ItemType ARMOR_STAND = IntItem.builder().id(ItemIds.ARMOR_STAND).maxStackSize(64).build(); - public static final ItemType END_CRYSTAL = IntItem.builder().id(ItemIds.END_CRYSTAL).maxStackSize(64).build(); - public static final ItemType CHORUS_FRUIT = IntItem.builder().id(ItemIds.CHORUS_FRUIT).maxStackSize(64).build(); - public static final ItemType CHORUS_FRUIT_POPPED = IntItem.builder().id(ItemIds.CHORUS_FRUIT_POPPED).maxStackSize(64).build(); - public static final ItemType DRAGON_BREATH = IntItem.builder().id(ItemIds.DRAGON_BREATH).maxStackSize(64).build(); - public static final ItemType SPLASH_POTION = IntItem.builder().id(ItemIds.SPLASH_POTION).maxStackSize(1).build(); - public static final ItemType LINGERING_POTION = IntItem.builder().id(ItemIds.LINGERING_POTION).maxStackSize(1).build(); - public static final ItemType COMMAND_BLOCK_MINECART = IntItem.builder().id(ItemIds.COMMAND_BLOCK_MINECART).maxStackSize(1).build(); - public static final ItemType ELYTRA = IntItem.builder().id(ItemIds.ELYTRA).maxStackSize(1).build(); - public static final ItemType SHULKER_SHELL = IntItem.builder().id(ItemIds.SHULKER_SHELL).maxStackSize(64).build(); - public static final ItemType BANNER = IntItem.builder().id(ItemIds.BANNER).maxStackSize(16).fuelTime((short) 300).build(); - public static final ItemType BANNER_PATTERN = IntItem.builder().id(ItemIds.BANNER_PATTERN).maxStackSize(1).build(); - public static final ItemType TOTEM = IntItem.builder().id(ItemIds.TOTEM).maxStackSize(1).build(); - public static final ItemType IRON_NUGGET = IntItem.builder().id(ItemIds.IRON_NUGGET).maxStackSize(64).build(); - public static final ItemType BOARD = IntItem.builder().id(ItemIds.BOARD).maxStackSize(16).build(); - public static final ItemType PORTFOLIO = IntItem.builder().id(ItemIds.PORTFOLIO).maxStackSize(64).build(); - public static final ItemType TRIDENT = IntItem.builder().id(ItemIds.TRIDENT).maxStackSize(64).build(); - public static final ItemType BEETROOT = IntItem.builder().id(ItemIds.BEETROOT).maxStackSize(54).blockType(BlockTypes.BEETROOT).build(); - public static final ItemType BEETROOT_SEEDS = IntItem.builder().id(ItemIds.BEETROOT_SEEDS).maxStackSize(64).build(); - public static final ItemType BEETROOT_SOUP = IntItem.builder().id(ItemIds.BEETROOT_SOUP).maxStackSize(1).build(); - public static final ItemType SALMON = IntItem.builder().id(ItemIds.SALMON).maxStackSize(64).build(); - public static final ItemType CLOWNFISH = IntItem.builder().id(ItemIds.TROPICAL_FISH).maxStackSize(64).build(); - public static final ItemType PUFFERFISH = IntItem.builder().id(ItemIds.PUFFERFISH).maxStackSize(64).build(); - public static final ItemType COOKED_SALMON = IntItem.builder().id(ItemIds.COOKED_SALMON).maxStackSize(64).build(); - public static final ItemType NAUTILUS_SHELL = IntItem.builder().id(ItemIds.NAUTILUS_SHELL).maxStackSize(64).build(); - public static final ItemType DRIED_KELP = IntItem.builder().id(ItemIds.DRIED_KELP).maxStackSize(64).build(); - public static final ItemType APPLE_ENCHANTED = IntItem.builder().id(ItemIds.APPLE_ENCHANTED).maxStackSize(64).build(); - public static final ItemType HEART_OF_THE_SEA = IntItem.builder().id(ItemIds.HEART_OF_THE_SEA).maxStackSize(64).build(); - public static final ItemType TURTLE_SHELL_PIECE = IntItem.builder().id(ItemIds.TURTLE_SHELL_PIECE).maxStackSize(64).build(); - public static final ItemType TURTLE_HELMET = IntItem.builder().id(ItemIds.TURTLE_HELMET).maxStackSize(1).build(); - public static final ItemType PHANTOM_MEMBRANE = IntItem.builder().id(ItemIds.PHANTOM_MEMBRANE).maxStackSize(64).build(); - public static final ItemType CROSSBOW = IntItem.builder().id(ItemIds.CROSSBOW).maxStackSize(1).build(); - public static final ItemType SWEET_BERRIES = IntItem.builder().id(ItemIds.SWEET_BERRIES).maxStackSize(64).build(); - public static final ItemType CAMERA = IntItem.builder().id(ItemIds.CAMERA).maxStackSize(64).build(); - public static final ItemType RECORD = IntItem.builder().id(ItemIds.RECORD_13).maxStackSize(1).build(); - - public static final ItemType SUSPICIOUS_STEW = IntItem.builder().id(ItemIds.SUSPICIOUS_STEW).build(); - public static final ItemType LODESTONE_COMPASS = IntItem.builder().id(ItemIds.LODESTONE_COMPASS).build(); - public static final ItemType WARPED_FUNGUS_ON_A_STICK = IntItem.builder().id(ItemIds.WARPED_FUNGUS_ON_STICK).build(); - - - public static final ItemType SHIELD = IntItem.builder().id(ItemIds.SHIELD).maxStackSize(1).data(Damageable.class).build(); - public static final ItemType CAMPFIRE = IntItem.builder().id(ItemIds.CAMPFIRE).maxStackSize(1).blockType(BlockTypes.CAMPFIRE).build(); - public static final ItemType HONEYCOMB = IntItem.builder().id(ItemIds.HONEYCOMB).maxStackSize(64).build(); - public static final ItemType HONEY_BOTTLE = IntItem.builder().id(ItemIds.HONEY_BOTTLE).maxStackSize(16).build(); - public static final ItemType NETHERITE_INGOT = IntItem.builder().id(ItemIds.NETHERITE_INGOT).maxStackSize(64).build(); - public static final ItemType NETHERITE_SCRAP = IntItem.builder().id(ItemIds.NETHERITE_SCRAP).build(); - public static final ItemType NETHERITE_SWORD = IntItem.builder().id(ItemIds.NETHERITE_SWORD).maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(NETHERITE).attackDamage(9).build(); - public static final ItemType NETHERITE_SHOVEL = IntItem.builder().id(ItemIds.NETHERITE_SHOVEL).maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(NETHERITE).attackDamage(6).build(); - public static final ItemType NETHERITE_PICKAXE = IntItem.builder().id(ItemIds.NETHERITE_PICKAXE).maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(NETHERITE).attackDamage(6).build(); - public static final ItemType NETHERITE_AXE = IntItem.builder().id(ItemIds.NETHERITE_AXE).maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(NETHERITE).attackDamage(8).build(); - public static final ItemType NETHERITE_HOE = IntItem.builder().id(ItemIds.NETHERITE_HOE).maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(NETHERITE).attackDamage(6).build(); - public static final ItemType NETHERITE_HELMET = IntItem.builder().id(ItemIds.NETHERITE_HELMET).maxStackSize(1).data(Damageable.class).tierType(NETHERITE).build(); - public static final ItemType NETHERITE_CHESTPLATE = IntItem.builder().id(ItemIds.NETHERITE_CHESTPLATE).maxStackSize(1).data(Damageable.class).tierType(NETHERITE).build(); - public static final ItemType NETHERITE_LEGGINGS = IntItem.builder().id(ItemIds.NETHERITE_LEGGINGS).maxStackSize(1).data(Damageable.class).tierType(NETHERITE).build(); - public static final ItemType NETHERITE_BOOTS = IntItem.builder().id(ItemIds.NETHERITE_BOOTS).maxStackSize(1).data(Damageable.class).tierType(NETHERITE).build(); - public static final ItemType CONCRETE_POWDER = IntItem.builder().id(ItemIds.CONCRETE_POWDER).maxStackSize(64).data(DyeColor.class).blockType(BlockTypes.CONCRETE_POWDER).build(); - public static final ItemType UNKNOWN = IntItem.builder().id(Identifiers.UNKNOWN).build(); - - public static final ItemType AMETHYST_SHARD = IntItem.builder().id(ItemIds.AMETHYST_SHARD).build(); - public static final ItemType GLOW_BERRIES = IntItem.builder().id(ItemIds.GLOW_BERRIES).build(); - public static final ItemType GLOW_INK_SAC = IntItem.builder().id(ItemIds.GLOW_INK_SAC).build(); - public static final ItemType GOAT_HORN = IntItem.builder().id(ItemIds.GOAT_HORN).build(); - public static final ItemType GLOW_FRAME = IntItem.builder().id(ItemIds.GLOW_FRAME).build(); - public static final ItemType RAW_COPPER = IntItem.builder().id(ItemIds.RAW_COPPER).build(); - public static final ItemType RAW_GOLD = IntItem.builder().id(ItemIds.RAW_GOLD).build(); - public static final ItemType RAW_IRON = IntItem.builder().id(ItemIds.RAW_IRON).build(); - public static final ItemType SPYGLASS = IntItem.builder().id(ItemIds.SPYGLASS).build(); - public static final ItemType COPPER_INGOT = IntItem.builder().id(ItemIds.COPPER_INGOT).build(); - - public static final class IntItem implements ItemType { - private final Identifier id; - private final int maxStackSize; - private final int attackDamage; - private final int armorPoints; - private final int toughness; - private final int durability; - private final short fuelTime; - private final int enchantAbility; - private final BlockType blockType; - private final Class data; - private final ToolType toolType; - private final TierType tierType; - - private IntItem( - Identifier id, - int maxStackSize, - int attackDamage, - int armorPoints, - int toughness, - int durability, - short fuelTime, - int enchantAbility, - Class data, - BlockType blockType, - ToolType toolType, - TierType tierType - ) { - this.id = id; - this.maxStackSize = Math.max(1, maxStackSize); - this.attackDamage = attackDamage; - this.armorPoints = armorPoints; - this.toughness = toughness; - this.fuelTime = fuelTime; - this.enchantAbility = enchantAbility; - this.data = data; - this.blockType = blockType; - this.toolType = toolType; - this.tierType = tierType; - - if (durability >= 0) { - this.durability = durability; - } else { - if (tierType != null) { - this.durability = tierType.getDurability(); - } else { - this.durability = 0; - } - } - - BY_ID.put(id, this); - } - - @Override - public ItemStack createItem(int amount, Object... metadata) { - //return CloudItemRegistry.get().getItem(this, amount, metadata); - return null; //TODO SB - How to reference ItemRegistry statically? - } - - @Override - public Identifier getId() { - return id; - } - - @Override - public boolean isBlock() { - return false; - } - - @Override - public int getMaximumStackSize() { - return maxStackSize; - } - - @Override - public int getAttackDamage() { - return attackDamage; - } - - @Override - public int getArmorPoints() { - return armorPoints; - } - - @Override - public int getToughness() { - return toughness; - } - - @Override - public int getDurability() { - return durability; - } - - @Override - public short getFuelTime() { - return fuelTime; - } - - public BlockType getBlockType() { - return blockType; - } - - @Nullable - @Override - public Class getMetadataClass() { - return data; - } - - @Override - @Nullable - public ToolType getToolType() { - return toolType; - } - - @Override - @Nullable - public TierType getTierType() { - return tierType; - } - - @Override - public boolean isPlaceable() { - return blockType != null; - } - - @Override - @Nullable - public BlockType getBlock() { - return null; - } - - @Override - public String toString() { - return "ItemType(" + id + ")"; - } - - @Override - public int hashCode() { - return id.hashCode(); - } - - private static Builder builder() { - return new Builder(); - } - - private static class Builder { - private Identifier id; - private int maxStackSize; - private int attackDamage = 2; - private int armorPoints; - private int toughness; - private int durability = -1; - private short fuelTime; - private int enchantAbility; - private BlockType blockType; - private Class data; - private ToolType toolType; - private TierType tierType; - - private Builder id(Identifier id) { - this.id = id; - return this; - } - - private Builder maxStackSize(int maxStackSize) { - this.maxStackSize = maxStackSize; - return this; - } - - private Builder attackDamage(int damage) { - this.attackDamage = damage; - return this; - } - - private Builder armorPoints(int points) { - this.armorPoints = points; - return this; - } - - private Builder toughness(int toughness) { - this.toughness = toughness; - return this; - } - - private Builder durability(int durability) { - this.durability = durability; - return this; - } - - private Builder fuelTime(short duration) { - this.fuelTime = duration; - return this; - } - - private Builder enchantAbility(int enchantAbility) { - this.enchantAbility = enchantAbility; - return this; - } - - private Builder blockType(BlockType type) { - this.blockType = type; - return this; - } - - private Builder data(Class data) { - this.data = data; - return this; - } - - private Builder toolType(ToolType toolType) { - this.data(Damageable.class).toolType = toolType; - return this; - } - - private Builder tierType(TierType tierType) { - this.tierType = tierType; - return this; - } - - public IntItem build() { - return new IntItem( - id, - maxStackSize, - attackDamage, - armorPoints, - toughness, - durability, - fuelTime, - enchantAbility, - data, - blockType, - toolType, - tierType - ); - } - } - } - - public static ItemType byId(Identifier id) { - return byId(id, false); - } - - public static ItemType byId(Identifier id, boolean itemsOnly) { - ItemType type = BY_ID.get(id); - if (type == null) { - if (itemsOnly) { - throw new IllegalArgumentException("ID " + id + " is not valid."); - } else { - return BLOCKS_BY_ID.get(id); - } - } - return type; - } - - public static void addType(Identifier id, BlockType type) { - BLOCKS_BY_ID.putIfAbsent(id, type); - } - - public static void addType(Identifier id, ItemType type) { - BY_ID.putIfAbsent(id, type); - } + public static final ItemType IRON_SHOVEL = ItemType.of(ItemIds.IRON_SHOVEL); //.maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(IRON).attackDamage(4).build(); + public static final ItemType IRON_PICKAXE = ItemType.of(ItemIds.IRON_PICKAXE); //.maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(IRON).attackDamage(4).build(); + public static final ItemType IRON_AXE = ItemType.of(ItemIds.IRON_AXE); //.maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(IRON).attackDamage(6).build(); + public static final ItemType FLINT_AND_STEEL = ItemType.of(ItemIds.FLINT_AND_STEEL); //.maxStackSize(1).build(); + public static final ItemType APPLE = ItemType.of(ItemIds.APPLE); //.maxStackSize(64).build(); + public static final ItemType BOW = ItemType.of(ItemIds.BOW); //.maxStackSize(1).fuelTime((short) 200).build(); + public static final ItemType ARROW = ItemType.of(ItemIds.ARROW); //.maxStackSize(64).build(); + public static final ItemType COAL = ItemType.of(ItemIds.COAL); //.maxStackSize(64).data(Coal.class).fuelTime((short) 1600).build(); + public static final ItemType DIAMOND = ItemType.of(ItemIds.DIAMOND); //.maxStackSize(64).build(); + public static final ItemType IRON_INGOT = ItemType.of(ItemIds.IRON_INGOT); //.maxStackSize(64).build(); + public static final ItemType GOLD_INGOT = ItemType.of(ItemIds.GOLD_INGOT); //.maxStackSize(64).build(); + public static final ItemType IRON_SWORD = ItemType.of(ItemIds.IRON_SWORD); //.maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(IRON).attackDamage(7).build(); + public static final ItemType WOODEN_SWORD = ItemType.of(ItemIds.WOODEN_SWORD); //.maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(WOOD).attackDamage(5).fuelTime((short) 200).build(); + public static final ItemType WOODEN_SHOVEL = ItemType.of(ItemIds.WOODEN_SHOVEL); //.maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(WOOD).attackDamage(2).fuelTime((short) 200).build(); + public static final ItemType WOODEN_PICKAXE = ItemType.of(ItemIds.WOODEN_PICKAXE); //.maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(WOOD).attackDamage(2).fuelTime((short) 200).build(); + public static final ItemType WOODEN_AXE = ItemType.of(ItemIds.WOODEN_AXE); //.maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(WOOD).attackDamage(4).fuelTime((short) 200).build(); + public static final ItemType STONE_SWORD = ItemType.of(ItemIds.STONE_SWORD); //.maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(STONE).attackDamage(6).build(); + public static final ItemType STONE_SHOVEL = ItemType.of(ItemIds.STONE_SHOVEL); //.maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(STONE).attackDamage(3).build(); + public static final ItemType STONE_PICKAXE = ItemType.of(ItemIds.STONE_PICKAXE); //.maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(STONE).attackDamage(3).build(); + public static final ItemType STONE_AXE = ItemType.of(ItemIds.STONE_AXE); //.maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(STONE).attackDamage(5).build(); + public static final ItemType DIAMOND_SWORD = ItemType.of(ItemIds.DIAMOND_SWORD); //.maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(TierTypes.DIAMOND).attackDamage(8).build(); + public static final ItemType DIAMOND_SHOVEL = ItemType.of(ItemIds.DIAMOND_SHOVEL); //.maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(TierTypes.DIAMOND).attackDamage(5).build(); + public static final ItemType DIAMOND_PICKAXE = ItemType.of(ItemIds.DIAMOND_PICKAXE); //.maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(TierTypes.DIAMOND).attackDamage(5).build(); + public static final ItemType DIAMOND_AXE = ItemType.of(ItemIds.DIAMOND_AXE); //.maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(TierTypes.DIAMOND).attackDamage(7).build(); + public static final ItemType STICK = ItemType.of(ItemIds.STICK); //.maxStackSize(64).fuelTime((short) 100).build(); + public static final ItemType BOWL = ItemType.of(ItemIds.BOWL); //.maxStackSize(64).fuelTime((short) 200).build(); + public static final ItemType MUSHROOM_STEW = ItemType.of(ItemIds.MUSHROOM_STEW); //.maxStackSize(1).build(); + public static final ItemType GOLDEN_SWORD = ItemType.of(ItemIds.GOLDEN_SWORD); //.maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(GOLD).attackDamage(5).build(); + public static final ItemType GOLDEN_SHOVEL = ItemType.of(ItemIds.GOLDEN_SHOVEL); //.maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(GOLD).attackDamage(2).build(); + public static final ItemType GOLDEN_PICKAXE = ItemType.of(ItemIds.GOLDEN_PICKAXE); //.maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(GOLD).attackDamage(2).build(); + public static final ItemType GOLDEN_AXE = ItemType.of(ItemIds.GOLDEN_AXE); //.maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(GOLD).attackDamage(4).build(); + public static final ItemType STRING = ItemType.of(ItemIds.STRING); //.maxStackSize(64).blockType(BlockTypes.TRIPWIRE).build(); + public static final ItemType FEATHER = ItemType.of(ItemIds.FEATHER); //.maxStackSize(64).build(); + public static final ItemType GUNPOWDER = ItemType.of(ItemIds.GUNPOWDER); //.maxStackSize(64).build(); + public static final ItemType WOODEN_HOE = ItemType.of(ItemIds.WOODEN_HOE); //.maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(WOOD).attackDamage(2).fuelTime((short) 200).build(); + public static final ItemType STONE_HOE = ItemType.of(ItemIds.STONE_HOE); //.maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(STONE).attackDamage(3).build(); + public static final ItemType IRON_HOE = ItemType.of(ItemIds.IRON_HOE); //.maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(IRON).attackDamage(4).build(); + public static final ItemType DIAMOND_HOE = ItemType.of(ItemIds.DIAMOND_HOE); //.maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(TierTypes.DIAMOND).attackDamage(5).build(); + public static final ItemType GOLDEN_HOE = ItemType.of(ItemIds.GOLDEN_HOE); //.maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(GOLD).attackDamage(2).build(); + public static final ItemType WHEAT_SEEDS = ItemType.of(ItemIds.WHEAT_SEEDS); //.maxStackSize(64).blockType(BlockTypes.WHEAT).build(); + public static final ItemType WHEAT = ItemType.of(ItemIds.WHEAT); //.maxStackSize(64).build(); + public static final ItemType BREAD = ItemType.of(ItemIds.BREAD); //.maxStackSize(64).build(); + public static final ItemType LEATHER_HELMET = ItemType.of(ItemIds.LEATHER_HELMET); //.maxStackSize(1).tierType(TierTypes.LEATHER).build(); //TODO: color meta + public static final ItemType LEATHER_CHESTPLATE = ItemType.of(ItemIds.LEATHER_CHESTPLATE); //.maxStackSize(1).tierType(TierTypes.LEATHER).build(); //TODO: color meta + public static final ItemType LEATHER_LEGGINGS = ItemType.of(ItemIds.LEATHER_LEGGINGS); //.maxStackSize(1).tierType(TierTypes.LEATHER).build(); //TODO: color meta + public static final ItemType LEATHER_BOOTS = ItemType.of(ItemIds.LEATHER_BOOTS); //.maxStackSize(1).tierType(TierTypes.LEATHER).build(); //TODO: color meta + public static final ItemType CHAINMAIL_HELMET = ItemType.of(ItemIds.CHAINMAIL_HELMET); //.maxStackSize(1).tierType(CHAINMAIL).build(); + public static final ItemType CHAINMAIL_CHESTPLATE = ItemType.of(ItemIds.CHAINMAIL_CHESTPLATE); //.maxStackSize(1).tierType(CHAINMAIL).build(); + public static final ItemType CHAINMAIL_LEGGINGS = ItemType.of(ItemIds.CHAINMAIL_LEGGINGS); //.maxStackSize(1).tierType(CHAINMAIL).build(); + public static final ItemType CHAINMAIL_BOOTS = ItemType.of(ItemIds.CHAINMAIL_BOOTS); //.maxStackSize(1).tierType(CHAINMAIL).build(); + public static final ItemType IRON_HELMET = ItemType.of(ItemIds.IRON_HELMET); //.maxStackSize(1).tierType(IRON).build(); + public static final ItemType IRON_CHESTPLATE = ItemType.of(ItemIds.IRON_CHESTPLATE); //.maxStackSize(1).tierType(IRON).build(); + public static final ItemType IRON_LEGGINGS = ItemType.of(ItemIds.IRON_LEGGINGS); //.maxStackSize(1).tierType(IRON).build(); + public static final ItemType IRON_BOOTS = ItemType.of(ItemIds.IRON_BOOTS); //.maxStackSize(1).tierType(IRON).build(); + public static final ItemType DIAMOND_HELMET = ItemType.of(ItemIds.DIAMOND_HELMET); //.maxStackSize(1).tierType(TierTypes.DIAMOND).build(); + public static final ItemType DIAMOND_CHESTPLATE = ItemType.of(ItemIds.DIAMOND_CHESTPLATE); //.maxStackSize(1).tierType(TierTypes.DIAMOND).build(); + public static final ItemType DIAMOND_LEGGINGS = ItemType.of(ItemIds.DIAMOND_LEGGINGS); //.maxStackSize(1).tierType(TierTypes.DIAMOND).build(); + public static final ItemType DIAMOND_BOOTS = ItemType.of(ItemIds.DIAMOND_BOOTS); //.maxStackSize(1).tierType(TierTypes.DIAMOND).build(); + public static final ItemType GOLDEN_HELMET = ItemType.of(ItemIds.GOLDEN_HELMET); //.maxStackSize(1).tierType(GOLD).build(); + public static final ItemType GOLDEN_CHESTPLATE = ItemType.of(ItemIds.GOLDEN_CHESTPLATE); //.maxStackSize(1).tierType(GOLD).build(); + public static final ItemType GOLDEN_LEGGINGS = ItemType.of(ItemIds.GOLDEN_LEGGINGS); //.maxStackSize(1).tierType(GOLD).build(); + public static final ItemType GOLDEN_BOOTS = ItemType.of(ItemIds.GOLDEN_BOOTS); //.maxStackSize(1).tierType(GOLD).build(); + public static final ItemType FLINT = ItemType.of(ItemIds.FLINT); //.maxStackSize(64).build(); + public static final ItemType PORKCHOP = ItemType.of(ItemIds.PORKCHOP); //.maxStackSize(64).build(); + public static final ItemType COOKED_PORKCHOP = ItemType.of(ItemIds.COOKED_PORKCHOP); //.maxStackSize(64).build(); + public static final ItemType PAINTING = ItemType.of(ItemIds.PAINTING); //.maxStackSize(64).build(); + public static final ItemType GOLDEN_APPLE = ItemType.of(ItemIds.GOLDEN_APPLE); //.maxStackSize(64).build(); + public static final ItemType SIGN = ItemType.of(ItemIds.SIGN); //.maxStackSize(16).blockType(BlockTypes.STANDING_SIGN).data(TreeSpecies.class).build(); + public static final ItemType WOODEN_DOOR = ItemType.of(ItemIds.WOODEN_DOOR); //.maxStackSize(64).blockType(BlockTypes.WOODEN_DOOR).data(TreeSpecies.class).build(); + public static final ItemType BUCKET = ItemType.of(ItemIds.BUCKET); //.data(Bucket.class).maxStackSize(16).build(); + public static final ItemType MINECART = ItemType.of(ItemIds.MINECART); //.maxStackSize(1).build(); + public static final ItemType SADDLE = ItemType.of(ItemIds.SADDLE); //.maxStackSize(1).build(); + public static final ItemType IRON_DOOR = ItemType.of(ItemIds.IRON_DOOR); //.maxStackSize(64).blockType(BlockTypes.IRON_DOOR).build(); + public static final ItemType REDSTONE = ItemType.of(ItemIds.REDSTONE); //.maxStackSize(64).blockType(BlockTypes.REDSTONE_WIRE).build(); + public static final ItemType SNOWBALL = ItemType.of(ItemIds.SNOWBALL); //.maxStackSize(16).build(); + public static final ItemType BOAT = ItemType.of(ItemIds.BOAT); //.maxStackSize(1).fuelTime((short) 1200).build(); + public static final ItemType LEATHER = ItemType.of(ItemIds.LEATHER); //.maxStackSize(64).build(); + public static final ItemType KELP = ItemType.of(ItemIds.KELP); //.maxStackSize(64).blockType(BlockTypes.KELP).build(); + public static final ItemType BRICK = ItemType.of(ItemIds.BRICK); //.maxStackSize(64).build(); + public static final ItemType CLAY_BALL = ItemType.of(ItemIds.CLAY_BALL); //.maxStackSize(64).build(); + public static final ItemType REEDS = ItemType.of(ItemIds.SUGAR_CANE); //.maxStackSize(64).blockType(BlockTypes.REEDS).build(); + public static final ItemType PAPER = ItemType.of(ItemIds.PAPER); //.maxStackSize(64).build(); + public static final ItemType BOOK = ItemType.of(ItemIds.BOOK); //.maxStackSize(64).build(); + public static final ItemType SLIME_BALL = ItemType.of(ItemIds.SLIME_BALL); //.maxStackSize(64).build(); + public static final ItemType CHEST_MINECART = ItemType.of(ItemIds.CHEST_MINECART); //.maxStackSize(1).build(); + public static final ItemType EGG = ItemType.of(ItemIds.EGG); //.maxStackSize(16).build(); + public static final ItemType COMPASS = ItemType.of(ItemIds.COMPASS); //.maxStackSize(64).build(); + public static final ItemType FISHING_ROD = ItemType.of(ItemIds.FISHING_ROD); //.maxStackSize(1).fuelTime((short) 300).build(); + public static final ItemType CLOCK = ItemType.of(ItemIds.CLOCK); //.maxStackSize(64).build(); + public static final ItemType GLOWSTONE_DUST = ItemType.of(ItemIds.GLOWSTONE_DUST); //.maxStackSize(64).build(); + public static final ItemType FISH = ItemType.of(ItemIds.COD); //.maxStackSize(64).build(); + public static final ItemType COOKED_FISH = ItemType.of(ItemIds.COOKED_COD); //.maxStackSize(64).build(); + public static final ItemType DYE = ItemType.of(ItemIds.INK_SAC); //.maxStackSize(64).data(DyeColor.class).build(); + public static final ItemType BONE = ItemType.of(ItemIds.BONE); //.maxStackSize(64).build(); + public static final ItemType SUGAR = ItemType.of(ItemIds.SUGAR); //.maxStackSize(64).build(); + public static final ItemType CAKE = ItemType.of(ItemIds.CAKE); //.maxStackSize(1).build(); + public static final ItemType BED = ItemType.of(ItemIds.BED); //.maxStackSize(1).data(DyeColor.class).build(); + public static final ItemType REPEATER = ItemType.of(ItemIds.REPEATER); //.maxStackSize(64).blockType(BlockTypes.REPEATER).build(); + public static final ItemType COOKIE = ItemType.of(ItemIds.COOKIE); //.maxStackSize(64).build(); + public static final ItemType MAP = ItemType.of(ItemIds.MAP); //.maxStackSize(64).build(); + public static final ItemType SHEARS = ItemType.of(ItemIds.SHEARS); //.maxStackSize(1).data(Damageable.class).toolType(ToolTypes.SHEARS).build(); + public static final ItemType MELON = ItemType.of(ItemIds.MELON); //.maxStackSize(64).build(); + public static final ItemType PUMPKIN_SEEDS = ItemType.of(ItemIds.PUMPKIN_SEEDS); //.maxStackSize(64).blockType(BlockTypes.PUMPKIN_STEM).build(); + public static final ItemType MELON_SEEDS = ItemType.of(ItemIds.MELON_SEEDS); //.maxStackSize(64).blockType(BlockTypes.MELON_STEM).build(); + public static final ItemType BEEF = ItemType.of(ItemIds.BEEF); //.maxStackSize(64).build(); + public static final ItemType COOKED_BEEF = ItemType.of(ItemIds.COOKED_BEEF); //.maxStackSize(64).build(); + public static final ItemType CHICKEN = ItemType.of(ItemIds.CHICKEN); //.maxStackSize(64).build(); + public static final ItemType COOKED_CHICKEN = ItemType.of(ItemIds.COOKED_CHICKEN); //.maxStackSize(64).build(); + public static final ItemType ROTTEN_FLESH = ItemType.of(ItemIds.ROTTEN_FLESH); //.maxStackSize(64).build(); + public static final ItemType ENDER_PEARL = ItemType.of(ItemIds.ENDER_PEARL); //.maxStackSize(64).build(); + public static final ItemType BLAZE_ROD = ItemType.of(ItemIds.BLAZE_ROD); //.maxStackSize(64).fuelTime((short) 2400).build(); + public static final ItemType GHAST_TEAR = ItemType.of(ItemIds.GHAST_TEAR); //.maxStackSize(64).build(); + public static final ItemType GOLD_NUGGET = ItemType.of(ItemIds.GOLD_NUGGET); //.maxStackSize(64).build(); + public static final ItemType NETHER_WART = ItemType.of(ItemIds.NETHER_WART); //.maxStackSize(64).blockType(BlockTypes.NETHER_WART).build(); + public static final ItemType POTION = ItemType.of(ItemIds.POTION); //.maxStackSize(1).build(); + public static final ItemType GLASS_BOTTLE = ItemType.of(ItemIds.GLASS_BOTTLE); //.maxStackSize(64).build(); + public static final ItemType SPIDER_EYE = ItemType.of(ItemIds.SPIDER_EYE); //.maxStackSize(64).build(); + public static final ItemType FERMENTED_SPIDER_EYE = ItemType.of(ItemIds.FERMENTED_SPIDER_EYE); //.maxStackSize(64).build(); + public static final ItemType BLAZE_POWDER = ItemType.of(ItemIds.BLAZE_POWDER); //.maxStackSize(64).build(); + public static final ItemType MAGMA_CREAM = ItemType.of(ItemIds.MAGMA_CREAM); //.maxStackSize(64).build(); + public static final ItemType BREWING_STAND = ItemType.of(ItemIds.BREWING_STAND); //.maxStackSize(64).blockType(BlockTypes.BREWING_STAND).build(); + public static final ItemType CAULDRON = ItemType.of(ItemIds.CAULDRON); //.maxStackSize(64).blockType(BlockTypes.CAULDRON).build(); + public static final ItemType ENDER_EYE = ItemType.of(ItemIds.ENDER_EYE); //.maxStackSize(64).build(); + public static final ItemType SPECKLED_MELON = ItemType.of(ItemIds.SPECKLED_MELON); //.maxStackSize(64).build(); + public static final ItemType SPAWN_EGG = ItemType.of(ItemIds.SPAWN_EGG); //.maxStackSize(64).build(); + public static final ItemType EXPERIENCE_BOTTLE = ItemType.of(ItemIds.EXPERIENCE_BOTTLE); //.maxStackSize(64).build(); + public static final ItemType FIREBALL = ItemType.of(ItemIds.FIRE_CHARGE); //.maxStackSize(64).build(); + public static final ItemType WRITABLE_BOOK = ItemType.of(ItemIds.WRITABLE_BOOK); //.maxStackSize(1).build(); + public static final ItemType WRITTEN_BOOK = ItemType.of(ItemIds.WRITTEN_BOOK); //.maxStackSize(16).build(); + public static final ItemType EMERALD = ItemType.of(ItemIds.EMERALD); //.maxStackSize(64).build(); + public static final ItemType FRAME = ItemType.of(ItemIds.FRAME); //.maxStackSize(64).blockType(BlockTypes.FRAME).build(); + public static final ItemType FLOWER_POT = ItemType.of(ItemIds.FLOWER_POT); //.maxStackSize(64).blockType(BlockTypes.FLOWER_POT).build(); + public static final ItemType CARROT = ItemType.of(ItemIds.CARROT); //.maxStackSize(64).build(); + public static final ItemType POTATO = ItemType.of(ItemIds.POTATO); //.maxStackSize(64).build(); + public static final ItemType BAKED_POTATO = ItemType.of(ItemIds.BAKED_POTATO); //.maxStackSize(64).build(); + public static final ItemType POISONOUS_POTATO = ItemType.of(ItemIds.POISONOUS_POTATO); //.maxStackSize(64).build(); + public static final ItemType EMPTY_MAP = ItemType.of(ItemIds.EMPTY_MAP); //.maxStackSize(64).build(); + public static final ItemType GOLDEN_CARROT = ItemType.of(ItemIds.GOLDEN_CARROT); //.maxStackSize(64).build(); + public static final ItemType SKULL = ItemType.of(ItemIds.SKULL); //.maxStackSize(64).build(); //TODO: skull type + public static final ItemType CARROT_ON_A_STICK = ItemType.of(ItemIds.CARROT_ON_A_STICK); //.maxStackSize(1).build(); + public static final ItemType NETHER_STAR = ItemType.of(ItemIds.NETHER_STAR); //.maxStackSize(64).build(); + public static final ItemType PUMPKIN_PIE = ItemType.of(ItemIds.PUMPKIN_PIE); //.maxStackSize(64).build(); + public static final ItemType FIREWORKS = ItemType.of(ItemIds.FIREWORK_ROCKET); //.maxStackSize(64).build(); + public static final ItemType FIREWORKS_CHARGE = ItemType.of(ItemIds.FIREWORKS_CHARGE); //.maxStackSize(64).build(); + public static final ItemType ENCHANTED_BOOK = ItemType.of(ItemIds.ENCHANTED_BOOK); //.maxStackSize(1).build(); + public static final ItemType COMPARATOR = ItemType.of(ItemIds.COMPARATOR); //.maxStackSize(64).blockType(BlockTypes.COMPARATOR).build(); + public static final ItemType NETHERBRICK = ItemType.of(ItemIds.NETHERBRICK); //.maxStackSize(64).build(); + public static final ItemType QUARTZ = ItemType.of(ItemIds.QUARTZ); //.maxStackSize(64).build(); + public static final ItemType TNT_MINECART = ItemType.of(ItemIds.TNT_MINECART); //.maxStackSize(1).build(); + public static final ItemType HOPPER_MINECART = ItemType.of(ItemIds.HOPPER_MINECART); //.maxStackSize(1).build(); + public static final ItemType PRISMARINE_SHARD = ItemType.of(ItemIds.PRISMARINE_SHARD); //.maxStackSize(64).build(); + public static final ItemType HOPPER = ItemType.of(ItemIds.HOPPER); //.maxStackSize(64).blockType(BlockTypes.HOPPER).build(); + public static final ItemType RABBIT = ItemType.of(ItemIds.RABBIT); //.maxStackSize(64).build(); + public static final ItemType COOKED_RABBIT = ItemType.of(ItemIds.COOKED_RABBIT); //.maxStackSize(64).build(); + public static final ItemType RABBIT_STEW = ItemType.of(ItemIds.RABBIT_STEW); //.maxStackSize(64).build(); + public static final ItemType RABBIT_FOOT = ItemType.of(ItemIds.RABBIT_FOOT); //.maxStackSize(64).build(); + public static final ItemType RABBIT_HIDE = ItemType.of(ItemIds.RABBIT_HIDE); //.maxStackSize(64).build(); + public static final ItemType HORSE_ARMOR_LEATHER = ItemType.of(ItemIds.HORSE_ARMOR_LEATHER); //.maxStackSize(1).build(); + public static final ItemType HORSE_ARMOR_IRON = ItemType.of(ItemIds.HORSE_ARMOR_IRON); //.maxStackSize(1).build(); + public static final ItemType HORSE_ARMOR_GOLD = ItemType.of(ItemIds.HORSE_ARMOR_GOLD); //.maxStackSize(1).build(); + public static final ItemType HORSE_ARMOR_DIAMOND = ItemType.of(ItemIds.HORSE_ARMOR_DIAMOND); //.maxStackSize(1).build(); + public static final ItemType LEAD = ItemType.of(ItemIds.LEAD); //.maxStackSize(64).build(); + public static final ItemType NAME_TAG = ItemType.of(ItemIds.NAME_TAG); //.maxStackSize(64).build(); + public static final ItemType PRISMARINE_CRYSTALS = ItemType.of(ItemIds.PRISMARINE_CRYSTALS); //.maxStackSize(64).build(); + public static final ItemType MUTTON_RAW = ItemType.of(ItemIds.MUTTON_RAW); //.maxStackSize(64).build(); + public static final ItemType MUTTON_COOKED = ItemType.of(ItemIds.MUTTON_COOKED); //.maxStackSize(64).build(); + public static final ItemType ARMOR_STAND = ItemType.of(ItemIds.ARMOR_STAND); //.maxStackSize(64).build(); + public static final ItemType END_CRYSTAL = ItemType.of(ItemIds.END_CRYSTAL); //.maxStackSize(64).build(); + public static final ItemType CHORUS_FRUIT = ItemType.of(ItemIds.CHORUS_FRUIT); //.maxStackSize(64).build(); + public static final ItemType CHORUS_FRUIT_POPPED = ItemType.of(ItemIds.CHORUS_FRUIT_POPPED); //.maxStackSize(64).build(); + public static final ItemType DRAGON_BREATH = ItemType.of(ItemIds.DRAGON_BREATH); //.maxStackSize(64).build(); + public static final ItemType SPLASH_POTION = ItemType.of(ItemIds.SPLASH_POTION); //.maxStackSize(1).build(); + public static final ItemType LINGERING_POTION = ItemType.of(ItemIds.LINGERING_POTION); //.maxStackSize(1).build(); + public static final ItemType COMMAND_BLOCK_MINECART = ItemType.of(ItemIds.COMMAND_BLOCK_MINECART); //.maxStackSize(1).build(); + public static final ItemType ELYTRA = ItemType.of(ItemIds.ELYTRA); //.maxStackSize(1).build(); + public static final ItemType SHULKER_SHELL = ItemType.of(ItemIds.SHULKER_SHELL); //.maxStackSize(64).build(); + public static final ItemType BANNER = ItemType.of(ItemIds.BANNER); //.maxStackSize(16).fuelTime((short) 300).build(); + public static final ItemType BANNER_PATTERN = ItemType.of(ItemIds.BANNER_PATTERN); //.maxStackSize(1).build(); + public static final ItemType TOTEM = ItemType.of(ItemIds.TOTEM); //.maxStackSize(1).build(); + public static final ItemType IRON_NUGGET = ItemType.of(ItemIds.IRON_NUGGET); //.maxStackSize(64).build(); + public static final ItemType BOARD = ItemType.of(ItemIds.BOARD); //.maxStackSize(16).build(); + public static final ItemType PORTFOLIO = ItemType.of(ItemIds.PORTFOLIO); //.maxStackSize(64).build(); + public static final ItemType TRIDENT = ItemType.of(ItemIds.TRIDENT); //.maxStackSize(64).build(); + public static final ItemType BEETROOT = ItemType.of(ItemIds.BEETROOT); //.maxStackSize(54).blockType(BlockTypes.BEETROOT).build(); + public static final ItemType BEETROOT_SEEDS = ItemType.of(ItemIds.BEETROOT_SEEDS); //.maxStackSize(64).build(); + public static final ItemType BEETROOT_SOUP = ItemType.of(ItemIds.BEETROOT_SOUP); //.maxStackSize(1).build(); + public static final ItemType SALMON = ItemType.of(ItemIds.SALMON); //.maxStackSize(64).build(); + public static final ItemType CLOWNFISH = ItemType.of(ItemIds.TROPICAL_FISH); //.maxStackSize(64).build(); + public static final ItemType PUFFERFISH = ItemType.of(ItemIds.PUFFERFISH); //.maxStackSize(64).build(); + public static final ItemType COOKED_SALMON = ItemType.of(ItemIds.COOKED_SALMON); //.maxStackSize(64).build(); + public static final ItemType NAUTILUS_SHELL = ItemType.of(ItemIds.NAUTILUS_SHELL); //.maxStackSize(64).build(); + public static final ItemType DRIED_KELP = ItemType.of(ItemIds.DRIED_KELP); //.maxStackSize(64).build(); + public static final ItemType APPLE_ENCHANTED = ItemType.of(ItemIds.APPLE_ENCHANTED); //.maxStackSize(64).build(); + public static final ItemType HEART_OF_THE_SEA = ItemType.of(ItemIds.HEART_OF_THE_SEA); //.maxStackSize(64).build(); + public static final ItemType TURTLE_SHELL_PIECE = ItemType.of(ItemIds.TURTLE_SHELL_PIECE); //.maxStackSize(64).build(); + public static final ItemType TURTLE_HELMET = ItemType.of(ItemIds.TURTLE_HELMET); //.maxStackSize(1).build(); + public static final ItemType PHANTOM_MEMBRANE = ItemType.of(ItemIds.PHANTOM_MEMBRANE); //.maxStackSize(64).build(); + public static final ItemType CROSSBOW = ItemType.of(ItemIds.CROSSBOW); //.maxStackSize(1).build(); + public static final ItemType SWEET_BERRIES = ItemType.of(ItemIds.SWEET_BERRIES); //.maxStackSize(64).build(); + public static final ItemType CAMERA = ItemType.of(ItemIds.CAMERA); //.maxStackSize(64).build(); + public static final ItemType RECORD = ItemType.of(ItemIds.RECORD_13); //.maxStackSize(1).build(); + + public static final ItemType SUSPICIOUS_STEW = ItemType.of(ItemIds.SUSPICIOUS_STEW); //.build(); + public static final ItemType LODESTONE_COMPASS = ItemType.of(ItemIds.LODESTONE_COMPASS); //.build(); + public static final ItemType WARPED_FUNGUS_ON_A_STICK = ItemType.of(ItemIds.WARPED_FUNGUS_ON_STICK); //.build(); + + + public static final ItemType SHIELD = ItemType.of(ItemIds.SHIELD); //.maxStackSize(1).data(Damageable.class).build(); + public static final ItemType CAMPFIRE = ItemType.of(ItemIds.CAMPFIRE); //.maxStackSize(1).blockType(BlockTypes.CAMPFIRE).build(); + public static final ItemType HONEYCOMB = ItemType.of(ItemIds.HONEYCOMB); //.maxStackSize(64).build(); + public static final ItemType HONEY_BOTTLE = ItemType.of(ItemIds.HONEY_BOTTLE); //.maxStackSize(16).build(); + public static final ItemType NETHERITE_INGOT = ItemType.of(ItemIds.NETHERITE_INGOT); //.maxStackSize(64).build(); + public static final ItemType NETHERITE_SCRAP = ItemType.of(ItemIds.NETHERITE_SCRAP); //.build(); + public static final ItemType NETHERITE_SWORD = ItemType.of(ItemIds.NETHERITE_SWORD); //.maxStackSize(1).data(Damageable.class).toolType(SWORD).tierType(NETHERITE).attackDamage(9).build(); + public static final ItemType NETHERITE_SHOVEL = ItemType.of(ItemIds.NETHERITE_SHOVEL); //.maxStackSize(1).data(Damageable.class).toolType(SHOVEL).tierType(NETHERITE).attackDamage(6).build(); + public static final ItemType NETHERITE_PICKAXE = ItemType.of(ItemIds.NETHERITE_PICKAXE); //.maxStackSize(1).data(Damageable.class).toolType(PICKAXE).tierType(NETHERITE).attackDamage(6).build(); + public static final ItemType NETHERITE_AXE = ItemType.of(ItemIds.NETHERITE_AXE); //.maxStackSize(1).data(Damageable.class).toolType(AXE).tierType(NETHERITE).attackDamage(8).build(); + public static final ItemType NETHERITE_HOE = ItemType.of(ItemIds.NETHERITE_HOE); //.maxStackSize(1).data(Damageable.class).toolType(HOE).tierType(NETHERITE).attackDamage(6).build(); + public static final ItemType NETHERITE_HELMET = ItemType.of(ItemIds.NETHERITE_HELMET); //.maxStackSize(1).data(Damageable.class).tierType(NETHERITE).build(); + public static final ItemType NETHERITE_CHESTPLATE = ItemType.of(ItemIds.NETHERITE_CHESTPLATE); //.maxStackSize(1).data(Damageable.class).tierType(NETHERITE).build(); + public static final ItemType NETHERITE_LEGGINGS = ItemType.of(ItemIds.NETHERITE_LEGGINGS); //.maxStackSize(1).data(Damageable.class).tierType(NETHERITE).build(); + public static final ItemType NETHERITE_BOOTS = ItemType.of(ItemIds.NETHERITE_BOOTS); //.maxStackSize(1).data(Damageable.class).tierType(NETHERITE).build(); + public static final ItemType CONCRETE_POWDER = ItemType.of(ItemIds.CONCRETE_POWDER); //.maxStackSize(64).data(DyeColor.class).blockType(BlockTypes.CONCRETE_POWDER).build(); + public static final ItemType UNKNOWN = ItemType.of(Identifiers.UNKNOWN); + + public static final ItemType AMETHYST_SHARD = ItemType.of(ItemIds.AMETHYST_SHARD); //.build(); + public static final ItemType GLOW_BERRIES = ItemType.of(ItemIds.GLOW_BERRIES); //.build(); + public static final ItemType GLOW_INK_SAC = ItemType.of(ItemIds.GLOW_INK_SAC); //.build(); + public static final ItemType GOAT_HORN = ItemType.of(ItemIds.GOAT_HORN); //.build(); + public static final ItemType GLOW_FRAME = ItemType.of(ItemIds.GLOW_FRAME); //.build(); + public static final ItemType RAW_COPPER = ItemType.of(ItemIds.RAW_COPPER); //.build(); + public static final ItemType RAW_GOLD = ItemType.of(ItemIds.RAW_GOLD); //.build(); + public static final ItemType RAW_IRON = ItemType.of(ItemIds.RAW_IRON); //.build(); + public static final ItemType SPYGLASS = ItemType.of(ItemIds.SPYGLASS); //.build(); + public static final ItemType COPPER_INGOT = ItemType.of(ItemIds.COPPER_INGOT); //.build(); } diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/ItemBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/ItemBehavior.java index 23a1763..10fb3a9 100644 --- a/src/main/java/org/cloudburstmc/api/item/behavior/ItemBehavior.java +++ b/src/main/java/org/cloudburstmc/api/item/behavior/ItemBehavior.java @@ -1,10 +1,13 @@ package org.cloudburstmc.api.item.behavior; import com.nukkitx.math.vector.Vector3f; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.block.Block; import org.cloudburstmc.api.block.BlockState; +import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.entity.Entity; import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.item.ItemType; import org.cloudburstmc.api.item.TierType; import org.cloudburstmc.api.item.ToolType; import org.cloudburstmc.api.level.Level; @@ -61,6 +64,10 @@ public interface ItemBehavior { boolean isBoots(); + ToolType getToolType(ItemType type); + + TierType getTierType(ItemType type); + int getEnchantAbility(ItemStack item); int getAttackDamage(ItemStack item); From 94496d806df8737c2ab2d6f3baabe12013b015df Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sun, 17 Oct 2021 13:39:06 +0100 Subject: [PATCH 02/42] Add more block behaviours --- src/main/java/module-info.java | 1 + .../api/block/BlockBehaviorKeys.java | 14 ---- .../api/block/BlockBehaviors.java | 84 +++++++++++++++++++ .../block/behavior/BlockStateBehavior.java | 9 -- .../behavior/FloatBlockStateBehavior.java | 9 -- .../cloudburstmc/api/item/ItemBehaviors.java | 8 ++ .../util/function/ObjObjFloatConsumer.java | 7 ++ .../api/util/function/ToFloatBiFunction.java | 7 ++ .../api/util/function/ToFloatFunction.java | 7 ++ .../api/util/function/TriConsumer.java | 9 ++ .../api/util/function/TriPredicate.java | 7 ++ 11 files changed, 130 insertions(+), 32 deletions(-) delete mode 100644 src/main/java/org/cloudburstmc/api/block/BlockBehaviorKeys.java create mode 100644 src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java delete mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/BlockStateBehavior.java delete mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockStateBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java create mode 100644 src/main/java/org/cloudburstmc/api/util/function/ObjObjFloatConsumer.java create mode 100644 src/main/java/org/cloudburstmc/api/util/function/ToFloatBiFunction.java create mode 100644 src/main/java/org/cloudburstmc/api/util/function/ToFloatFunction.java create mode 100644 src/main/java/org/cloudburstmc/api/util/function/TriConsumer.java create mode 100644 src/main/java/org/cloudburstmc/api/util/function/TriPredicate.java diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index f2c9c31..972ccbc 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -59,4 +59,5 @@ exports org.cloudburstmc.api.registry; exports org.cloudburstmc.api.util; exports org.cloudburstmc.api.util.data; + exports org.cloudburstmc.api.util.function; } \ No newline at end of file diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviorKeys.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviorKeys.java deleted file mode 100644 index 5514490..0000000 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviorKeys.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.cloudburstmc.api.block; - -import org.cloudburstmc.api.block.behavior.BlockStateBehavior; -import org.cloudburstmc.api.data.DataKey; -import org.cloudburstmc.api.data.SimpleDataKey; -import org.cloudburstmc.api.util.AxisAlignedBB; -import org.cloudburstmc.api.util.Identifier; - -public class BlockBehaviorKeys { - - public static final SimpleDataKey> GET_DESCRIPTION_ID = DataKey.simple(Identifier.fromString("get_description_id"), BlockStateBehavior.class); - - public static final SimpleDataKey> GET_BOUNDING_BOX = DataKey.simple(Identifier.fromString("get_bounding_box"), BlockStateBehavior.class); -} 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..a74e420 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -0,0 +1,84 @@ +package org.cloudburstmc.api.block; + +import org.cloudburstmc.api.blockentity.BlockEntityType; +import org.cloudburstmc.api.data.DataKey; +import org.cloudburstmc.api.data.SimpleDataKey; +import org.cloudburstmc.api.entity.Entity; +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.player.Player; +import org.cloudburstmc.api.util.AxisAlignedBB; +import org.cloudburstmc.api.util.Direction; +import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.api.util.function.*; + +import java.util.Optional; +import java.util.function.*; +import java.util.random.RandomGenerator; + +public final class BlockBehaviors { + + private BlockBehaviors() { + } + + public static final SimpleDataKey> GET_DESCRIPTION_ID = DataKey.simple(Identifier.fromString("get_description_id"), Function.class); + + public static final SimpleDataKey> GET_BOUNDING_BOX = DataKey.simple(Identifier.fromString("get_bounding_box"), Function.class); + + public static final SimpleDataKey> CAN_BE_SILK_TOUCHED = DataKey.simple(Identifier.fromString("can_be_silk_touched"), Predicate.class); + + public static final SimpleDataKey> CAN_BE_USED_IN_COMMANDS = DataKey.simple(Identifier.fromString("can_be_used_in_commands"), Predicate.class); + + public static final SimpleDataKey> CAN_CONTAIN_LIQUID = DataKey.simple(Identifier.fromString("can_contain_liquid"), Predicate.class); + + public static final SimpleDataKey> CAN_SPAWN_ON = DataKey.simple(Identifier.fromString("can_spawn_on"), Predicate.class); + + public static final SimpleDataKey> GET_FRICTION = DataKey.simple(Identifier.fromString("get_friction"), ToFloatFunction.class); + + public static final SimpleDataKey> GET_HARDNESS = DataKey.simple(Identifier.fromString("get_hardness"), ToFloatFunction.class); + + public static final SimpleDataKey> GET_BURN_ODDS = DataKey.simple(Identifier.fromString("get_burn_odds"), ToIntFunction.class); + + public static final SimpleDataKey> GET_FLAME_ODDS = DataKey.simple(Identifier.fromString("get_flame_odds"), ToIntFunction.class); + + public static final SimpleDataKey> GET_GRAVITY = DataKey.simple(Identifier.fromString("get_gravity"), ToFloatFunction.class); + + public static final SimpleDataKey> GET_THICKNESS = DataKey.simple(Identifier.fromString("get_thickness"), ToFloatFunction.class); + + public static final SimpleDataKey> GET_DESTROY_SPEED = DataKey.simple(Identifier.fromString("get_destroy_speed"), ToFloatFunction.class); + + public static final SimpleDataKey> GET_EXPERIENCE_DROP = DataKey.simple(Identifier.fromString("get_experience_drop"), ToIntBiFunction.class); + + public static final SimpleDataKey> GET_EXPLOSION_RESISTANCE = DataKey.simple(Identifier.fromString("get_explosion_resistance"), ToFloatBiFunction.class); + + public static final SimpleDataKey> GET_SILK_TOUCH_ITEM_STACK = DataKey.simple(Identifier.fromString("get_silk_touch_item_stack"), Function.class); + + public static final SimpleDataKey> GET_STRIPPED_BLOCK = DataKey.simple(Identifier.fromString("get_stripped_block"), Function.class); + + public static final SimpleDataKey>> GET_BLOCK_ENTITY = DataKey.simple(Identifier.fromString("get_block_entity"), Optional.class); + + public static final SimpleDataKey> MAY_PICK = DataKey.simple(Identifier.fromString("may_pick"), Predicate.class); + + public static final SimpleDataKey> MAY_PLACE = DataKey.simple(Identifier.fromString("may_place"), BiPredicate.class); + + public static final SimpleDataKey> MAY_PLACE_ON = DataKey.simple(Identifier.fromString("may_place_on"), Predicate.class); + + public static final SimpleDataKey> ON_DESTROY = DataKey.simple(Identifier.fromString("on_destroy"), BiConsumer.class); + + public static final SimpleDataKey> ON_NEIGHBOUR_CHANGED = DataKey.simple(Identifier.fromString("on_neighbour_changed"), BiConsumer.class); + + public static final SimpleDataKey> ON_FALL_ON = DataKey.simple(Identifier.fromString("on_fall_on"), ObjObjFloatConsumer.class); + + public static final SimpleDataKey> ON_LIGHTNING_HIT = DataKey.simple(Identifier.fromString("on_lightning_hit"), Consumer.class); + + public static final SimpleDataKey> ON_PLACE = DataKey.simple(Identifier.fromString("on_place"), Consumer.class); + + public static final SimpleDataKey> ON_PROJECTILE_HIT = DataKey.simple(Identifier.fromString("on_projectile_hit"), BiConsumer.class); + + public static final SimpleDataKey> ON_REDSTONE_UPDATE = DataKey.simple(Identifier.fromString("on_redstone_update"), ObjIntConsumer.class); + + public static final SimpleDataKey> ON_REMOVE = DataKey.simple(Identifier.fromString("on_remove"), Consumer.class); + + public static final SimpleDataKey> ON_RANDOM_TICK = DataKey.simple(Identifier.fromString("on_random_tick"), BiConsumer.class); + + public static final SimpleDataKey> USE = DataKey.simple(Identifier.fromString("use"), TriPredicate.class); +} diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/BlockStateBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/BlockStateBehavior.java deleted file mode 100644 index 971f5b9..0000000 --- a/src/main/java/org/cloudburstmc/api/block/behavior/BlockStateBehavior.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.cloudburstmc.api.block.behavior; - -import org.cloudburstmc.api.block.BlockState; - -@FunctionalInterface -public interface BlockStateBehavior { - - T evaluate(BlockState value); -} diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockStateBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockStateBehavior.java deleted file mode 100644 index fbe06b0..0000000 --- a/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockStateBehavior.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.cloudburstmc.api.block.behavior; - -import org.cloudburstmc.api.block.BlockState; - -@FunctionalInterface -public interface FloatBlockStateBehavior { - - float evaluate(BlockState state); -} diff --git a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java new file mode 100644 index 0000000..9c7e350 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java @@ -0,0 +1,8 @@ +package org.cloudburstmc.api.item; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public class ItemBehaviors { + +} diff --git a/src/main/java/org/cloudburstmc/api/util/function/ObjObjFloatConsumer.java b/src/main/java/org/cloudburstmc/api/util/function/ObjObjFloatConsumer.java new file mode 100644 index 0000000..2193c7f --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/function/ObjObjFloatConsumer.java @@ -0,0 +1,7 @@ +package org.cloudburstmc.api.util.function; + +@FunctionalInterface +public interface ObjObjFloatConsumer { + + void accept(T t, U u, float value); +} diff --git a/src/main/java/org/cloudburstmc/api/util/function/ToFloatBiFunction.java b/src/main/java/org/cloudburstmc/api/util/function/ToFloatBiFunction.java new file mode 100644 index 0000000..3b1b0b9 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/function/ToFloatBiFunction.java @@ -0,0 +1,7 @@ +package org.cloudburstmc.api.util.function; + +@FunctionalInterface +public interface ToFloatBiFunction { + + float apply(T t, U u); +} diff --git a/src/main/java/org/cloudburstmc/api/util/function/ToFloatFunction.java b/src/main/java/org/cloudburstmc/api/util/function/ToFloatFunction.java new file mode 100644 index 0000000..d504537 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/function/ToFloatFunction.java @@ -0,0 +1,7 @@ +package org.cloudburstmc.api.util.function; + +@FunctionalInterface +public interface ToFloatFunction { + + float apply(T t); +} diff --git a/src/main/java/org/cloudburstmc/api/util/function/TriConsumer.java b/src/main/java/org/cloudburstmc/api/util/function/TriConsumer.java new file mode 100644 index 0000000..d106435 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/function/TriConsumer.java @@ -0,0 +1,9 @@ +package org.cloudburstmc.api.util.function; + +import java.util.function.ObjDoubleConsumer; + +@FunctionalInterface +public interface TriConsumer { + + void accept(T t, U u, V v); +} diff --git a/src/main/java/org/cloudburstmc/api/util/function/TriPredicate.java b/src/main/java/org/cloudburstmc/api/util/function/TriPredicate.java new file mode 100644 index 0000000..7dad371 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/function/TriPredicate.java @@ -0,0 +1,7 @@ +package org.cloudburstmc.api.util.function; + +@FunctionalInterface +public interface TriPredicate { + + boolean test(T t, U u, V v); +} From d97a36d837f360a1f6b41bcb35d4bd05b944ee75 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 23 Oct 2021 16:38:16 +0100 Subject: [PATCH 03/42] Figure out the base implementation for behaviours Each behaviour key needs to have access to the Behavior class so it can call other behaviours or call its parent. Ended up removing all the generic functions in util.function since the amount of generic parameters did not look nice. --- src/main/java/module-info.java | 2 +- .../api/block/BlockBehaviors.java | 74 ++-- .../cloudburstmc/api/block/BlockState.java | 10 +- .../api/block/behavior/AABBBlockBehavior.java | 15 + .../api/block/behavior/BlockBehavior.java | 408 ------------------ .../block/behavior/BooleanBlockBehavior.java | 14 + .../block/behavior/ComplexBlockBehavior.java | 14 + .../behavior/DescriptionBlockBehavior.java | 14 + .../block/behavior/EntityBlockBehavior.java | 15 + .../api/block/behavior/ExpBlockBehavior.java | 16 + .../block/behavior/FallOnBlockBehavior.java | 15 + .../block/behavior/FloatBlockBehavior.java | 14 + .../api/block/behavior/IntBlockBehavior.java | 14 + .../block/behavior/MayPlaceBlockBehavior.java | 15 + .../block/behavior/NeighborBlockBehavior.java | 14 + .../block/behavior/RedstoneBlockBehavior.java | 14 + .../api/block/behavior/TickBlockBehavior.java | 16 + .../api/block/behavior/UseBlockBehavior.java | 16 + .../api/block/material/MaterialTypes.java | 6 +- .../cloudburstmc/api/data/BehaviorKey.java | 47 ++ .../org/cloudburstmc/api/data/DataKey.java | 10 +- .../api/registry/BehaviorRegistry.java | 13 + .../api/registry/BlockRegistry.java | 11 +- .../api/util/behavior/Behavior.java | 25 ++ .../api/util/behavior/BehaviorCollection.java | 35 ++ .../util/function/ObjObjFloatConsumer.java | 7 - .../api/util/function/ToFloatBiFunction.java | 7 - .../api/util/function/ToFloatFunction.java | 7 - .../api/util/function/TriConsumer.java | 9 - .../api/util/function/TriPredicate.java | 7 - 30 files changed, 388 insertions(+), 496 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/AABBBlockBehavior.java delete mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/BlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/ComplexBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/DescriptionBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/EntityBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/ExpBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/FallOnBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/IntBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/MayPlaceBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/NeighborBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/TickBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/UseBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/data/BehaviorKey.java create mode 100644 src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java create mode 100644 src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java create mode 100644 src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java delete mode 100644 src/main/java/org/cloudburstmc/api/util/function/ObjObjFloatConsumer.java delete mode 100644 src/main/java/org/cloudburstmc/api/util/function/ToFloatBiFunction.java delete mode 100644 src/main/java/org/cloudburstmc/api/util/function/ToFloatFunction.java delete mode 100644 src/main/java/org/cloudburstmc/api/util/function/TriConsumer.java delete mode 100644 src/main/java/org/cloudburstmc/api/util/function/TriPredicate.java diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 972ccbc..2fe44b5 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -58,6 +58,6 @@ 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; - exports org.cloudburstmc.api.util.function; } \ No newline at end of file diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index a74e420..bb17a52 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -1,84 +1,80 @@ package org.cloudburstmc.api.block; +import org.cloudburstmc.api.block.behavior.*; import org.cloudburstmc.api.blockentity.BlockEntityType; +import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.data.DataKey; -import org.cloudburstmc.api.data.SimpleDataKey; -import org.cloudburstmc.api.entity.Entity; import org.cloudburstmc.api.item.ItemStack; -import org.cloudburstmc.api.player.Player; -import org.cloudburstmc.api.util.AxisAlignedBB; -import org.cloudburstmc.api.util.Direction; import org.cloudburstmc.api.util.Identifier; -import org.cloudburstmc.api.util.function.*; +import org.cloudburstmc.api.util.behavior.Behavior; import java.util.Optional; -import java.util.function.*; -import java.util.random.RandomGenerator; +import java.util.function.BiFunction; public final class BlockBehaviors { private BlockBehaviors() { } - public static final SimpleDataKey> GET_DESCRIPTION_ID = DataKey.simple(Identifier.fromString("get_description_id"), Function.class); + public static final BehaviorKey GET_DESCRIPTION_ID = DataKey.behavior(Identifier.fromString("get_description_id"), DescriptionBlockBehavior.class, DescriptionBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_BOUNDING_BOX = DataKey.simple(Identifier.fromString("get_bounding_box"), Function.class); + public static final BehaviorKey GET_BOUNDING_BOX = DataKey.behavior(Identifier.fromString("get_bounding_box"), AABBBlockBehavior.class, AABBBlockBehavior.Executor.class); - public static final SimpleDataKey> CAN_BE_SILK_TOUCHED = DataKey.simple(Identifier.fromString("can_be_silk_touched"), Predicate.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 SimpleDataKey> CAN_BE_USED_IN_COMMANDS = DataKey.simple(Identifier.fromString("can_be_used_in_commands"), Predicate.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 SimpleDataKey> CAN_CONTAIN_LIQUID = DataKey.simple(Identifier.fromString("can_contain_liquid"), Predicate.class); + public static final BehaviorKey CAN_CONTAIN_LIQUID = DataKey.behavior(Identifier.fromString("can_contain_liquid"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class); - public static final SimpleDataKey> CAN_SPAWN_ON = DataKey.simple(Identifier.fromString("can_spawn_on"), Predicate.class); + public static final BehaviorKey CAN_SPAWN_ON = DataKey.behavior(Identifier.fromString("can_spawn_on"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_FRICTION = DataKey.simple(Identifier.fromString("get_friction"), ToFloatFunction.class); + public static final BehaviorKey GET_FRICTION = DataKey.behavior(Identifier.fromString("get_friction"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_HARDNESS = DataKey.simple(Identifier.fromString("get_hardness"), ToFloatFunction.class); + public static final BehaviorKey GET_HARDNESS = DataKey.behavior(Identifier.fromString("get_hardness"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_BURN_ODDS = DataKey.simple(Identifier.fromString("get_burn_odds"), ToIntFunction.class); + public static final BehaviorKey GET_BURN_ODDS = DataKey.behavior(Identifier.fromString("get_burn_odds"), IntBlockBehavior.class, IntBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_FLAME_ODDS = DataKey.simple(Identifier.fromString("get_flame_odds"), ToIntFunction.class); + public static final BehaviorKey GET_FLAME_ODDS = DataKey.behavior(Identifier.fromString("get_flame_odds"), IntBlockBehavior.class, IntBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_GRAVITY = DataKey.simple(Identifier.fromString("get_gravity"), ToFloatFunction.class); + public static final BehaviorKey GET_GRAVITY = DataKey.behavior(Identifier.fromString("get_gravity"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_THICKNESS = DataKey.simple(Identifier.fromString("get_thickness"), ToFloatFunction.class); + public static final BehaviorKey GET_THICKNESS = DataKey.behavior(Identifier.fromString("get_thickness"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_DESTROY_SPEED = DataKey.simple(Identifier.fromString("get_destroy_speed"), ToFloatFunction.class); + public static final BehaviorKey GET_DESTROY_SPEED = DataKey.behavior(Identifier.fromString("get_destroy_speed"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_EXPERIENCE_DROP = DataKey.simple(Identifier.fromString("get_experience_drop"), ToIntBiFunction.class); + public static final BehaviorKey GET_EXPERIENCE_DROP = DataKey.behavior(Identifier.fromString("get_experience_drop"), ExpBlockBehavior.class, ExpBlockBehavior.Executor.class); - public static final SimpleDataKey> GET_EXPLOSION_RESISTANCE = DataKey.simple(Identifier.fromString("get_explosion_resistance"), ToFloatBiFunction.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 SimpleDataKey> GET_SILK_TOUCH_ITEM_STACK = DataKey.simple(Identifier.fromString("get_silk_touch_item_stack"), Function.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 SimpleDataKey> GET_STRIPPED_BLOCK = DataKey.simple(Identifier.fromString("get_stripped_block"), Function.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 SimpleDataKey>> GET_BLOCK_ENTITY = DataKey.simple(Identifier.fromString("get_block_entity"), Optional.class); + public static final BehaviorKey>, Optional>> GET_BLOCK_ENTITY = DataKey.behavior(Identifier.fromString("get_block_entity"), Optional.class, Optional.class); - public static final SimpleDataKey> MAY_PICK = DataKey.simple(Identifier.fromString("may_pick"), Predicate.class); + public static final BehaviorKey MAY_PICK = DataKey.behavior(Identifier.fromString("may_pick"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class); - public static final SimpleDataKey> MAY_PLACE = DataKey.simple(Identifier.fromString("may_place"), BiPredicate.class); + public static final BehaviorKey MAY_PLACE = DataKey.behavior(Identifier.fromString("may_place"), MayPlaceBlockBehavior.class, MayPlaceBlockBehavior.Executor.class); - public static final SimpleDataKey> MAY_PLACE_ON = DataKey.simple(Identifier.fromString("may_place_on"), Predicate.class); + public static final BehaviorKey MAY_PLACE_ON = DataKey.behavior(Identifier.fromString("may_place_on"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class); - public static final SimpleDataKey> ON_DESTROY = DataKey.simple(Identifier.fromString("on_destroy"), BiConsumer.class); + public static final BehaviorKey ON_DESTROY = DataKey.behavior(Identifier.fromString("on_destroy"), EntityBlockBehavior.class, EntityBlockBehavior.Executor.class); - public static final SimpleDataKey> ON_NEIGHBOUR_CHANGED = DataKey.simple(Identifier.fromString("on_neighbour_changed"), BiConsumer.class); + public static final BehaviorKey ON_NEIGHBOUR_CHANGED = DataKey.behavior(Identifier.fromString("on_neighbour_changed"), NeighborBlockBehavior.class, NeighborBlockBehavior.Executor.class); - public static final SimpleDataKey> ON_FALL_ON = DataKey.simple(Identifier.fromString("on_fall_on"), ObjObjFloatConsumer.class); + public static final BehaviorKey ON_FALL_ON = DataKey.behavior(Identifier.fromString("on_fall_on"), FallOnBlockBehavior.class, FallOnBlockBehavior.Executor.class); - public static final SimpleDataKey> ON_LIGHTNING_HIT = DataKey.simple(Identifier.fromString("on_lightning_hit"), Consumer.class); + public static final BehaviorKey ON_LIGHTNING_HIT = DataKey.behavior(Identifier.fromString("on_lightning_hit"), ComplexBlockBehavior.class, ComplexBlockBehavior.Executor.class); - public static final SimpleDataKey> ON_PLACE = DataKey.simple(Identifier.fromString("on_place"), Consumer.class); + public static final BehaviorKey ON_PLACE = DataKey.behavior(Identifier.fromString("on_place"), ComplexBlockBehavior.class, ComplexBlockBehavior.Executor.class); - public static final SimpleDataKey> ON_PROJECTILE_HIT = DataKey.simple(Identifier.fromString("on_projectile_hit"), BiConsumer.class); + public static final BehaviorKey ON_PROJECTILE_HIT = DataKey.behavior(Identifier.fromString("on_projectile_hit"), EntityBlockBehavior.class, EntityBlockBehavior.Executor.class); - public static final SimpleDataKey> ON_REDSTONE_UPDATE = DataKey.simple(Identifier.fromString("on_redstone_update"), ObjIntConsumer.class); + public static final BehaviorKey ON_REDSTONE_UPDATE = DataKey.behavior(Identifier.fromString("on_redstone_update"), RedstoneBlockBehavior.class, RedstoneBlockBehavior.Executor.class); - public static final SimpleDataKey> ON_REMOVE = DataKey.simple(Identifier.fromString("on_remove"), Consumer.class); + public static final BehaviorKey ON_REMOVE = DataKey.behavior(Identifier.fromString("on_remove"), ComplexBlockBehavior.class, ComplexBlockBehavior.Executor.class); - public static final SimpleDataKey> ON_RANDOM_TICK = DataKey.simple(Identifier.fromString("on_random_tick"), BiConsumer.class); + public static final BehaviorKey ON_RANDOM_TICK = DataKey.behavior(Identifier.fromString("on_random_tick"), TickBlockBehavior.class, TickBlockBehavior.Executor.class); - public static final SimpleDataKey> USE = DataKey.simple(Identifier.fromString("use"), TriPredicate.class); + public static final BehaviorKey USE = DataKey.behavior(Identifier.fromString("use"), UseBlockBehavior.class, BooleanBlockBehavior.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..020f473 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockState.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockState.java @@ -1,10 +1,10 @@ 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; +import org.cloudburstmc.api.util.behavior.Behavior; import java.util.Collections; import java.util.IdentityHashMap; @@ -18,19 +18,19 @@ public class BlockState { private final BlockType type; private final Map, Comparable> traits; private Map, BlockState[]> blockStates; - private BlockBehavior behavior; + private Behavior behavior; public BlockState(BlockType type, Map, Comparable> traits) { this(type, traits, null); } - public BlockState(BlockType type, Map, Comparable> traits, BlockBehavior behavior) { + public BlockState(BlockType type, Map, Comparable> traits, Behavior behavior) { this.type = type; this.traits = traits; this.behavior = behavior; } - public void setBehavior(BlockBehavior behavior) { + public void setBehavior(Behavior behavior) { this.behavior = behavior; } @@ -104,7 +104,7 @@ public String toString() { return builder.toString(); } - public BlockBehavior getBehavior() { + public Behavior getBehavior() { return this.behavior; } 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..5d4b8cc --- /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 5df6aa1..0000000 --- a/src/main/java/org/cloudburstmc/api/block/behavior/BlockBehavior.java +++ /dev/null @@ -1,408 +0,0 @@ -package org.cloudburstmc.api.block.behavior; - -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.api.block.*; -import org.cloudburstmc.api.enchantment.Enchantment; -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.item.behavior.ItemBehavior; -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 implements ItemBehavior { - - public boolean canHarvestWithHand(BlockState state) { //used for calculating breaking time - var type = state.getType(); - return isDiggable(type) && getToolType(type) == null && getTierType(type) == null; - } - - public boolean isBreakable(BlockState state, ItemStack item) { - return isDiggable(state.getType()); - } - - 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(); -// } - - 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(BlockType type) { - return false; - } - - public int getBurnChance() { - return 0; - } - - public int getBurnAbility() { - return 0; - } - - public float getHardness() { - return 1f; - } - - public float getFriction() { - return 0f; - } - - public float getResistance() { - return 0f; - } - - public int getMaximumStackSize() { - return 64; - } - - 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? - } - - public AxisAlignedBB getBoundingBox() { - return null; // FIXME - } - - public boolean isPowerSource() { - return false; - } - - public boolean canBeSilkTouched() { - return true; - } - - public boolean waterlogsSource() { - return false; - } - - public boolean breaksFlowing() { - return false; - } -} 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..036ca19 --- /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.BlockState; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface BooleanBlockBehavior { + + boolean test(Behavior behavior, BlockState state); + + @FunctionalInterface + interface Executor { + boolean execute(BlockState state); + } +} 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..e52c973 --- /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..3230379 --- /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/EntityBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/EntityBlockBehavior.java new file mode 100644 index 0000000..da446fe --- /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..563d1af --- /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..952412f --- /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..1ec6aad --- /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/IntBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/IntBlockBehavior.java new file mode 100644 index 0000000..b1df0f3 --- /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/MayPlaceBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/MayPlaceBlockBehavior.java new file mode 100644 index 0000000..75cfda0 --- /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..3011b70 --- /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/RedstoneBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.java new file mode 100644 index 0000000..0cdf2af --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.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 RedstoneBlockBehavior { + + int onRedstoneUpdate(Behavior behavior, Block block); + + @FunctionalInterface + interface Executor { + int 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..147d292 --- /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..a630a7c --- /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..45148cb 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().translucency(1.0f).alwaysDestroyable().blockingPrecipitation().flammable().build(); + + public static MaterialType DRIPSTONE = MaterialType.builder().translucency(1.0f).alwaysDestroyable().blockingPrecipitation().flammable().build(); + + public static MaterialType SCULK = MaterialType.builder().translucency(1.0f).alwaysDestroyable().blockingPrecipitation().flammable().build(); } 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..d98ebf6 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java @@ -0,0 +1,47 @@ +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(); + } +} diff --git a/src/main/java/org/cloudburstmc/api/data/DataKey.java b/src/main/java/org/cloudburstmc/api/data/DataKey.java index 9ca8c02..176d09a 100644 --- a/src/main/java/org/cloudburstmc/api/data/DataKey.java +++ b/src/main/java/org/cloudburstmc/api/data/DataKey.java @@ -6,7 +6,7 @@ import static com.google.common.base.Preconditions.checkNotNull; -public sealed interface DataKey permits SimpleDataKey, ListDataKey { +public sealed interface DataKey permits BehaviorKey, ListDataKey, SimpleDataKey { @SuppressWarnings("unchecked") static SimpleDataKey simple(Identifier id, Class type) { @@ -21,6 +21,14 @@ static ListDataKey list(Identifier id, Class type) { return new ListDataKey<>(id, type); } + @SuppressWarnings("unchecked") + static BehaviorKey behavior(Identifier id, Class functionType, Class returnType) { + checkNotNull(id, "id"); + checkNotNull(functionType, "functionType"); + checkNotNull(returnType, "returnType"); + return new BehaviorKey<>(id, (Class) functionType, (Class) returnType); + } + Identifier getId(); Class getType(); diff --git a/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java new file mode 100644 index 0000000..3586e39 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java @@ -0,0 +1,13 @@ +package org.cloudburstmc.api.registry; + +import org.cloudburstmc.api.data.BehaviorKey; +import org.cloudburstmc.api.util.behavior.Behavior; + +import java.util.function.Function; + +public interface BehaviorRegistry extends Registry { + + void registerItemBehavior(BehaviorKey key, T defaultBehavior, Function executorFactory); + + void registerBlockBehavior(BehaviorKey key, T defaultBehavior, Function executorFactory); +} diff --git a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java index 0593d53..976a40f 100644 --- a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java @@ -3,17 +3,20 @@ import com.google.common.collect.ImmutableList; import org.cloudburstmc.api.block.BlockState; import org.cloudburstmc.api.block.BlockType; -import org.cloudburstmc.api.block.behavior.BlockBehavior; +import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.item.ItemStack; import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.api.util.behavior.BehaviorCollection; public interface BlockRegistry extends Registry { - void register(BlockType type, BlockBehavior behavior) throws RegistryException; + BehaviorCollection register(BlockType type) throws RegistryException; - BlockBehavior getBehavior(BlockType type); + BehaviorCollection getBehaviors(BlockType type); - void overwriteBehavior(BlockType type, BlockBehavior behavior); + default T getBehavior(BlockType type, BehaviorKey key) { + return getBehaviors(type).getBehavior(key); + } boolean isBlock(Identifier id); diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java new file mode 100644 index 0000000..6b573e3 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java @@ -0,0 +1,25 @@ +package org.cloudburstmc.api.util.behavior; + +import org.checkerframework.checker.nullness.qual.NonNull; +import org.cloudburstmc.api.data.DataKey; + +public interface Behavior { + + /** + * Returns the parent function or the default if nothing is set. + * + * @param function type + * @return function + */ + @NonNull + T getSuper(); + + /** + * Get a behavior for a specified key + * + * @param key behavior key + * @param function type + * @return behavior function + */ + T getBehavior(DataKey key); +} diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java new file mode 100644 index 0000000..8113a3a --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java @@ -0,0 +1,35 @@ +package org.cloudburstmc.api.util.behavior; + +import org.cloudburstmc.api.data.BehaviorKey; + +public interface BehaviorCollection { + + /** + * Get behavior for specified key + * + * @param key behavior key + * @param function type + * @return function + */ + T getBehavior(BehaviorKey key); + + /** + * Extend existing functionality for this key + * + * @param key behavior key + * @param function function to extend + * @param function type + * @return this behavior collection + */ + BehaviorCollection extend(BehaviorKey key, T function); + + /** + * Overwrite default functionality for this key + * + * @param key behavior key + * @param function function to overwrite + * @param function type + * @return this behavior collection + */ + BehaviorCollection overwrite(BehaviorKey key, T function); +} diff --git a/src/main/java/org/cloudburstmc/api/util/function/ObjObjFloatConsumer.java b/src/main/java/org/cloudburstmc/api/util/function/ObjObjFloatConsumer.java deleted file mode 100644 index 2193c7f..0000000 --- a/src/main/java/org/cloudburstmc/api/util/function/ObjObjFloatConsumer.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.cloudburstmc.api.util.function; - -@FunctionalInterface -public interface ObjObjFloatConsumer { - - void accept(T t, U u, float value); -} diff --git a/src/main/java/org/cloudburstmc/api/util/function/ToFloatBiFunction.java b/src/main/java/org/cloudburstmc/api/util/function/ToFloatBiFunction.java deleted file mode 100644 index 3b1b0b9..0000000 --- a/src/main/java/org/cloudburstmc/api/util/function/ToFloatBiFunction.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.cloudburstmc.api.util.function; - -@FunctionalInterface -public interface ToFloatBiFunction { - - float apply(T t, U u); -} diff --git a/src/main/java/org/cloudburstmc/api/util/function/ToFloatFunction.java b/src/main/java/org/cloudburstmc/api/util/function/ToFloatFunction.java deleted file mode 100644 index d504537..0000000 --- a/src/main/java/org/cloudburstmc/api/util/function/ToFloatFunction.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.cloudburstmc.api.util.function; - -@FunctionalInterface -public interface ToFloatFunction { - - float apply(T t); -} diff --git a/src/main/java/org/cloudburstmc/api/util/function/TriConsumer.java b/src/main/java/org/cloudburstmc/api/util/function/TriConsumer.java deleted file mode 100644 index d106435..0000000 --- a/src/main/java/org/cloudburstmc/api/util/function/TriConsumer.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.cloudburstmc.api.util.function; - -import java.util.function.ObjDoubleConsumer; - -@FunctionalInterface -public interface TriConsumer { - - void accept(T t, U u, V v); -} diff --git a/src/main/java/org/cloudburstmc/api/util/function/TriPredicate.java b/src/main/java/org/cloudburstmc/api/util/function/TriPredicate.java deleted file mode 100644 index 7dad371..0000000 --- a/src/main/java/org/cloudburstmc/api/util/function/TriPredicate.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.cloudburstmc.api.util.function; - -@FunctionalInterface -public interface TriPredicate { - - boolean test(T t, U u, V v); -} From e6c6e4ac3d82de083015bacb2605b58e44c2c234 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 23 Oct 2021 16:42:16 +0100 Subject: [PATCH 04/42] Remove BlockState#getBehavior and references This was a dirty hack for the old behaviour format that can now be removed. --- .../org/cloudburstmc/api/block/BlockState.java | 15 --------------- .../api/event/block/BlockBreakEvent.java | 3 +-- 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/block/BlockState.java b/src/main/java/org/cloudburstmc/api/block/BlockState.java index 020f473..bff7834 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockState.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockState.java @@ -4,7 +4,6 @@ import org.cloudburstmc.api.block.trait.BlockTrait; import org.cloudburstmc.api.block.trait.BooleanBlockTrait; import org.cloudburstmc.api.block.trait.IntegerBlockTrait; -import org.cloudburstmc.api.util.behavior.Behavior; import java.util.Collections; import java.util.IdentityHashMap; @@ -18,20 +17,10 @@ public class BlockState { private final BlockType type; private final Map, Comparable> traits; private Map, BlockState[]> blockStates; - private Behavior behavior; public BlockState(BlockType type, Map, Comparable> traits) { - this(type, traits, null); - } - - public BlockState(BlockType type, Map, Comparable> traits, Behavior behavior) { this.type = type; this.traits = traits; - this.behavior = behavior; - } - - public void setBehavior(Behavior behavior) { - this.behavior = behavior; } public BlockType getType() { @@ -104,10 +93,6 @@ public String toString() { return builder.toString(); } - public Behavior 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/event/block/BlockBreakEvent.java b/src/main/java/org/cloudburstmc/api/event/block/BlockBreakEvent.java index e83dc5a..5067522 100644 --- a/src/main/java/org/cloudburstmc/api/event/block/BlockBreakEvent.java +++ b/src/main/java/org/cloudburstmc/api/event/block/BlockBreakEvent.java @@ -32,8 +32,7 @@ public BlockBreakEvent(Player player, Block block, ItemStack item, ItemStack[] d } public BlockBreakEvent(Player player, Block block, ItemStack item, ItemStack[] drops, boolean instaBreak, boolean fastBreak) { - this(player, block, null, item, drops, - block.getState().getBehavior().getDropExp(), instaBreak, fastBreak); + this(player, block, null, item, drops, 0, instaBreak, fastBreak); } public BlockBreakEvent(Player player, Block block, Direction face, ItemStack item, ItemStack[] drops, int dropExp, boolean instaBreak, boolean fastBreak) { From e8bd5edde993c35a6d3c84b44e3160122e0bc0f3 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 23 Oct 2021 21:00:20 +0100 Subject: [PATCH 05/42] Use executor generic parameter for Behavior --- .../java/org/cloudburstmc/api/block/BlockBehaviors.java | 5 +---- .../api/block/behavior/AABBBlockBehavior.java | 2 +- .../api/block/behavior/BooleanBlockBehavior.java | 2 +- .../api/block/behavior/ComplexBlockBehavior.java | 2 +- .../api/block/behavior/DescriptionBlockBehavior.java | 2 +- .../api/block/behavior/EntityBlockBehavior.java | 2 +- .../api/block/behavior/ExpBlockBehavior.java | 2 +- .../api/block/behavior/FallOnBlockBehavior.java | 2 +- .../api/block/behavior/FloatBlockBehavior.java | 2 +- .../api/block/behavior/IntBlockBehavior.java | 2 +- .../api/block/behavior/MayPlaceBlockBehavior.java | 2 +- .../api/block/behavior/NeighborBlockBehavior.java | 2 +- .../api/block/behavior/RedstoneBlockBehavior.java | 2 +- .../api/block/behavior/TickBlockBehavior.java | 2 +- .../api/block/behavior/UseBlockBehavior.java | 2 +- .../org/cloudburstmc/api/util/behavior/Behavior.java | 9 ++++----- 16 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index bb17a52..87d00be 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -4,12 +4,9 @@ import org.cloudburstmc.api.blockentity.BlockEntityType; import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.data.DataKey; -import org.cloudburstmc.api.item.ItemStack; import org.cloudburstmc.api.util.Identifier; -import org.cloudburstmc.api.util.behavior.Behavior; import java.util.Optional; -import java.util.function.BiFunction; public final class BlockBehaviors { @@ -46,7 +43,7 @@ private BlockBehaviors() { // 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, 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); diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/AABBBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/AABBBlockBehavior.java index 5d4b8cc..8900bbf 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/AABBBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/AABBBlockBehavior.java @@ -6,7 +6,7 @@ public interface AABBBlockBehavior { - AxisAlignedBB getBoundingBox(Behavior behavior, BlockState state); + AxisAlignedBB getBoundingBox(Behavior behavior, BlockState state); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java index 036ca19..a53f48b 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java @@ -5,7 +5,7 @@ public interface BooleanBlockBehavior { - boolean test(Behavior behavior, BlockState state); + boolean test(Behavior behavior, BlockState state); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/ComplexBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/ComplexBlockBehavior.java index e52c973..560b30a 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/ComplexBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/ComplexBlockBehavior.java @@ -5,7 +5,7 @@ public interface ComplexBlockBehavior { - void execute(Behavior behavior, Block block); + void execute(Behavior behavior, Block block); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/DescriptionBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/DescriptionBlockBehavior.java index 3230379..1b66862 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/DescriptionBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/DescriptionBlockBehavior.java @@ -5,7 +5,7 @@ public interface DescriptionBlockBehavior { - String getDescription(Behavior behavior, BlockState state); + String getDescription(Behavior behavior, BlockState state); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/EntityBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/EntityBlockBehavior.java index da446fe..f978fc9 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/EntityBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/EntityBlockBehavior.java @@ -6,7 +6,7 @@ public interface EntityBlockBehavior { - void execute(Behavior behavior, Block block, Entity entity); + void execute(Behavior behavior, Block block, Entity entity); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/ExpBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/ExpBlockBehavior.java index 563d1af..4045e21 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/ExpBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/ExpBlockBehavior.java @@ -7,7 +7,7 @@ public interface ExpBlockBehavior { - int getExperience(Behavior behavior, BlockState state, RandomGenerator random); + int getExperience(Behavior behavior, BlockState state, RandomGenerator random); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/FallOnBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/FallOnBlockBehavior.java index 952412f..02b63a9 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/FallOnBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/FallOnBlockBehavior.java @@ -6,7 +6,7 @@ public interface FallOnBlockBehavior { - void onFallOn(Behavior behavior, Block block, Entity entity); + void onFallOn(Behavior behavior, Block block, Entity entity); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockBehavior.java index 1ec6aad..c2d4d4d 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/FloatBlockBehavior.java @@ -5,7 +5,7 @@ public interface FloatBlockBehavior { - float getProperty(Behavior behavior, BlockState state); + float getProperty(Behavior behavior, BlockState state); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/IntBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/IntBlockBehavior.java index b1df0f3..eae506d 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/IntBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/IntBlockBehavior.java @@ -5,7 +5,7 @@ public interface IntBlockBehavior { - int getProperty(Behavior behavior, BlockState state); + int getProperty(Behavior behavior, BlockState state); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/MayPlaceBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/MayPlaceBlockBehavior.java index 75cfda0..ca4c42d 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/MayPlaceBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/MayPlaceBlockBehavior.java @@ -6,7 +6,7 @@ public interface MayPlaceBlockBehavior { - boolean mayPlace(Behavior behavior, Block block, Direction direction); + boolean mayPlace(Behavior behavior, Block block, Direction direction); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/NeighborBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/NeighborBlockBehavior.java index 3011b70..d2c72b7 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/NeighborBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/NeighborBlockBehavior.java @@ -5,7 +5,7 @@ public interface NeighborBlockBehavior { - void onNeighborChanged(Behavior behavior, Block block, Block neighbor); + void onNeighborChanged(Behavior behavior, Block block, Block neighbor); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.java index 0cdf2af..efc3c31 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.java @@ -5,7 +5,7 @@ public interface RedstoneBlockBehavior { - int onRedstoneUpdate(Behavior behavior, Block block); + int onRedstoneUpdate(Behavior behavior, Block block); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/TickBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/TickBlockBehavior.java index 147d292..45db9bd 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/TickBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/TickBlockBehavior.java @@ -7,7 +7,7 @@ public interface TickBlockBehavior { - void onTick(Behavior behavior, Block block, RandomGenerator random); + void onTick(Behavior behavior, Block block, RandomGenerator random); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/UseBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/UseBlockBehavior.java index a630a7c..48d72f7 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/UseBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/UseBlockBehavior.java @@ -7,7 +7,7 @@ public interface UseBlockBehavior { - boolean use(Behavior behavior, Block block, Player player, Direction direction); + boolean use(Behavior behavior, Block block, Player player, Direction direction); @FunctionalInterface interface Executor { diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java index 6b573e3..804914b 100644 --- a/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java +++ b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java @@ -3,23 +3,22 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.api.data.DataKey; -public interface Behavior { +public interface Behavior { /** * Returns the parent function or the default if nothing is set. * - * @param function type * @return function */ @NonNull - T getSuper(); + T getSuper(); /** * Get a behavior for a specified key * * @param key behavior key - * @param function type + * @param function type * @return behavior function */ - T getBehavior(DataKey key); + U getBehavior(DataKey key); } From df6bc9c322a53bf263d4b7b2960f3ebc6062d1aa Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 23 Oct 2021 21:00:47 +0100 Subject: [PATCH 06/42] Correct values for new MaterialTypes --- .../org/cloudburstmc/api/block/material/MaterialTypes.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 45148cb..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,9 +84,9 @@ public class MaterialTypes { public static MaterialType DECORATION_FLAMMABLE = MaterialType.builder().translucency(1.0f).alwaysDestroyable().blockingPrecipitation().flammable().build(); - public static MaterialType DECORATION_SOLID = MaterialType.builder().translucency(1.0f).alwaysDestroyable().blockingPrecipitation().flammable().build(); + public static MaterialType DECORATION_SOLID = MaterialType.builder().blockingPrecipitation().solid().blockingMotion().build(); - public static MaterialType DRIPSTONE = MaterialType.builder().translucency(1.0f).alwaysDestroyable().blockingPrecipitation().flammable().build(); + public static MaterialType DRIPSTONE = MaterialType.builder().blockingPrecipitation().solid().blockingMotion().build(); - public static MaterialType SCULK = MaterialType.builder().translucency(1.0f).alwaysDestroyable().blockingPrecipitation().flammable().build(); + public static MaterialType SCULK = MaterialType.builder().blockingPrecipitation().solid().blockingMotion().build(); } From 6f62f1d1dca7848f94783a5d07ddaecd9d3ec564 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sun, 24 Oct 2021 14:34:15 +0100 Subject: [PATCH 07/42] Add some more block behaviors --- .../cloudburstmc/api/block/BlockBehaviors.java | 17 ++++++++++++++++- .../api/block/behavior/PlayerBlockBehavior.java | 15 +++++++++++++++ .../block/behavior/RedstoneBlockBehavior.java | 14 -------------- .../block/behavior/ResourceBlockBehavior.java | 17 +++++++++++++++++ .../behavior/ResourceCountBlockBehavior.java | 16 ++++++++++++++++ .../api/registry/BehaviorRegistry.java | 4 ++-- .../api/util/behavior/Behavior.java | 6 +++--- 7 files changed, 69 insertions(+), 20 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/PlayerBlockBehavior.java delete mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/ResourceBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/ResourceCountBlockBehavior.java diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index 87d00be..3c27f1b 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -1,6 +1,7 @@ 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; @@ -67,11 +68,25 @@ private BlockBehaviors() { 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"), RedstoneBlockBehavior.class, RedstoneBlockBehavior.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 USE = DataKey.behavior(Identifier.fromString("use"), UseBlockBehavior.class, BooleanBlockBehavior.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 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); } 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/RedstoneBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.java deleted file mode 100644 index efc3c31..0000000 --- a/src/main/java/org/cloudburstmc/api/block/behavior/RedstoneBlockBehavior.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.cloudburstmc.api.block.behavior; - -import org.cloudburstmc.api.block.Block; -import org.cloudburstmc.api.util.behavior.Behavior; - -public interface RedstoneBlockBehavior { - - int onRedstoneUpdate(Behavior behavior, Block block); - - @FunctionalInterface - interface Executor { - int execute(Block block); - } -} 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/registry/BehaviorRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java index 3586e39..9bfbf21 100644 --- a/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java @@ -7,7 +7,7 @@ public interface BehaviorRegistry extends Registry { - void registerItemBehavior(BehaviorKey key, T defaultBehavior, Function executorFactory); + void registerItemBehavior(BehaviorKey key, T defaultBehavior, Function, R> executorFactory); - void registerBlockBehavior(BehaviorKey key, T defaultBehavior, Function executorFactory); + void registerBlockBehavior(BehaviorKey key, T defaultBehavior, Function, R> executorFactory); } diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java index 804914b..bf9c013 100644 --- a/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java +++ b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java @@ -1,7 +1,7 @@ package org.cloudburstmc.api.util.behavior; import org.checkerframework.checker.nullness.qual.NonNull; -import org.cloudburstmc.api.data.DataKey; +import org.cloudburstmc.api.data.BehaviorKey; public interface Behavior { @@ -11,7 +11,7 @@ public interface Behavior { * @return function */ @NonNull - T getSuper(); + T parent(); /** * Get a behavior for a specified key @@ -20,5 +20,5 @@ public interface Behavior { * @param function type * @return behavior function */ - U getBehavior(DataKey key); + U getBehavior(BehaviorKey key); } From c4d1a280f23fb5261d1af9ca60974043bbaf3579 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:37:18 +0100 Subject: [PATCH 08/42] Some more block behaviours --- .../cloudburstmc/api/block/BlockBehaviors.java | 18 ++++++++++++++++++ .../org/cloudburstmc/api/data/DataKey.java | 4 ++++ 2 files changed, 22 insertions(+) diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index 3c27f1b..338c5e5 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -89,4 +89,22 @@ private BlockBehaviors() { 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 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); } diff --git a/src/main/java/org/cloudburstmc/api/data/DataKey.java b/src/main/java/org/cloudburstmc/api/data/DataKey.java index 176d09a..1c84c1e 100644 --- a/src/main/java/org/cloudburstmc/api/data/DataKey.java +++ b/src/main/java/org/cloudburstmc/api/data/DataKey.java @@ -21,6 +21,10 @@ static ListDataKey list(Identifier id, Class type) { return new ListDataKey<>(id, type); } + static BehaviorKey behavior(Identifier id, Class type) { + return behavior(id, type, type); + } + @SuppressWarnings("unchecked") static BehaviorKey behavior(Identifier id, Class functionType, Class returnType) { checkNotNull(id, "id"); From 7165773cf39826e75ee2b7b8d24940a7f8056577 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 30 Oct 2021 12:38:06 +0100 Subject: [PATCH 09/42] Refactor some behaviour and block methods --- src/main/java/org/cloudburstmc/api/block/Block.java | 5 +++++ .../java/org/cloudburstmc/api/registry/BlockRegistry.java | 2 +- .../cloudburstmc/api/util/behavior/BehaviorCollection.java | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/block/Block.java b/src/main/java/org/cloudburstmc/api/block/Block.java index 3e6c5d5..a97a676 100644 --- a/src/main/java/org/cloudburstmc/api/block/Block.java +++ b/src/main/java/org/cloudburstmc/api/block/Block.java @@ -5,6 +5,7 @@ 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; 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(); } diff --git a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java index 976a40f..f2da833 100644 --- a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java @@ -15,7 +15,7 @@ public interface BlockRegistry extends Registry { BehaviorCollection getBehaviors(BlockType type); default T getBehavior(BlockType type, BehaviorKey key) { - return getBehaviors(type).getBehavior(key); + return getBehaviors(type).get(key); } boolean isBlock(Identifier id); diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java index 8113a3a..9a03348 100644 --- a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java +++ b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java @@ -11,7 +11,7 @@ public interface BehaviorCollection { * @param function type * @return function */ - T getBehavior(BehaviorKey key); + T get(BehaviorKey key); /** * Extend existing functionality for this key From bff655963b3353801d424bdf80cc60f088d90a43 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Mon, 20 Dec 2021 15:02:29 +0000 Subject: [PATCH 10/42] More refactoring of blocks and items --- .../api/block/BlockBehaviors.java | 28 +++++++- .../org/cloudburstmc/api/block/BlockType.java | 8 +-- .../block/behavior/BooleanBlockBehavior.java | 6 +- .../block/behavior/ColorBlockBehavior.java | 15 ++++ .../block/behavior/SurviveBlockBehavior.java | 14 ++++ .../org/cloudburstmc/api/item/ItemKeys.java | 9 +++ .../org/cloudburstmc/api/item/ItemStack.java | 43 ++++++++++- .../org/cloudburstmc/api/item/ItemType.java | 25 +++---- .../org/cloudburstmc/api/item/ItemTypes.java | 17 +---- .../org/cloudburstmc/api/level/Level.java | 3 + .../api/registry/BehaviorRegistry.java | 8 +-- .../api/registry/BlockRegistry.java | 2 +- .../api/registry/GameRuleRegistry.java | 2 +- .../api/registry/ItemRegistry.java | 15 +--- .../api/registry/RecipeRegistry.java | 2 +- .../cloudburstmc/api/registry/Registry.java | 6 -- .../api/registry/ResourcePackRegistry.java | 2 +- .../org/cloudburstmc/api/util/Randoms.java | 22 ++++++ .../api/util/behavior/Behavior.java | 2 +- .../api/util/behavior/BehaviorBuilder.java | 72 +++++++++++++++++++ .../api/util/behavior/BehaviorCollection.java | 7 ++ 21 files changed, 236 insertions(+), 72 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/ColorBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/SurviveBlockBehavior.java delete mode 100644 src/main/java/org/cloudburstmc/api/registry/Registry.java create mode 100644 src/main/java/org/cloudburstmc/api/util/Randoms.java create mode 100644 src/main/java/org/cloudburstmc/api/util/behavior/BehaviorBuilder.java diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index 338c5e5..ad1a6b2 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -74,6 +74,10 @@ private BlockBehaviors() { 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, BooleanBlockBehavior.Executor.class); public static final BehaviorKey ON_STAND_ON = DataKey.behavior(Identifier.fromString("on_stand_on"), EntityBlockBehavior.class, EntityBlockBehavior.Executor.class); @@ -86,7 +90,7 @@ private BlockBehaviors() { 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 GET_RESOURCE = DataKey.behavior(Identifier.fromString("get_resource"), ResourceBlockBehavior.class, ResourceBlockBehavior.Executor.class); + public static final BehaviorKey GET_RESOURCE_ITEM = DataKey.behavior(Identifier.fromString("get_resource_item"), ResourceBlockBehavior.class, ResourceBlockBehavior.Executor.class); public static final BehaviorKey GET_RESOURCE_COUNT = DataKey.behavior(Identifier.fromString("get_resource_count"), ResourceCountBlockBehavior.class, ResourceCountBlockBehavior.Executor.class); @@ -107,4 +111,26 @@ private BlockBehaviors() { 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); } diff --git a/src/main/java/org/cloudburstmc/api/block/BlockType.java b/src/main/java/org/cloudburstmc/api/block/BlockType.java index efff073..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.*; @@ -26,7 +22,7 @@ public final class BlockType extends ItemType { private final BlockState defaultState; private BlockType(Identifier id, BlockTrait[] traits) { - super(id, null); + super(id, Collections.singleton(ItemKeys.BLOCK_STATE)); this.traits = ImmutableSet.copyOf(traits); this.states = getPermutations(this, traits); diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java index a53f48b..72985be 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockBehavior.java @@ -1,14 +1,14 @@ package org.cloudburstmc.api.block.behavior; -import org.cloudburstmc.api.block.BlockState; +import org.cloudburstmc.api.block.Block; import org.cloudburstmc.api.util.behavior.Behavior; public interface BooleanBlockBehavior { - boolean test(Behavior behavior, BlockState state); + boolean test(Behavior behavior, Block block); @FunctionalInterface interface Executor { - boolean execute(BlockState state); + boolean execute(Block block); } } 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/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/item/ItemKeys.java b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java index 1873538..29d5809 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java @@ -5,7 +5,10 @@ import org.cloudburstmc.api.data.ListDataKey; import org.cloudburstmc.api.data.SimpleDataKey; import org.cloudburstmc.api.enchantment.Enchantment; +import org.cloudburstmc.api.item.data.Bucket; import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.api.util.data.DyeColor; +import org.cloudburstmc.api.util.data.FireworkData; public final class ItemKeys { @@ -13,5 +16,11 @@ public final class ItemKeys { public static final SimpleDataKey DAMAGE = DataKey.simple(Identifier.fromString("item_damage"), Integer.class); + public static final SimpleDataKey COLOR = DataKey.simple(Identifier.fromString("dye_color"), DyeColor.class); + public static final ListDataKey ENCHANTMENTS = DataKey.list(Identifier.fromString("enchantments"), Enchantment.class); + + public static final SimpleDataKey FIREWORK_DATA = DataKey.simple(Identifier.fromString("firework_data"), FireworkData.class); + + public static final SimpleDataKey BUCKET_DATA = DataKey.simple(Identifier.fromString("bucket_data"), Bucket.class); } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStack.java b/src/main/java/org/cloudburstmc/api/item/ItemStack.java index bb3517c..67b3838 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStack.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStack.java @@ -1,18 +1,22 @@ package org.cloudburstmc.api.item; import com.google.common.collect.ImmutableMap; -import com.nukkitx.math.GenericMath; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.Nullable; +import org.checkerframework.checker.index.qual.NonNegative; import org.cloudburstmc.api.block.BlockState; +import org.cloudburstmc.api.block.BlockTypes; import org.cloudburstmc.api.data.DataKey; import org.cloudburstmc.api.data.DataStore; import java.util.Collections; import java.util.Map; +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + public final class ItemStack implements DataStore, Comparable { + public static final ItemStack AIR = new ItemStack(BlockTypes.AIR, 0, Collections.emptyMap()); + private final ItemType type; private final int amount; private final ImmutableMap, ?> metadata; @@ -27,6 +31,35 @@ public static ItemStackBuilder builder() { return new ItemStackBuilder(null, 1, Collections.emptyMap()); } + public static ItemStackBuilder builder(BlockState state) { + return new ItemStackBuilder(state.getType(), 1, Collections.emptyMap()) + .data(ItemKeys.BLOCK_STATE, state); + } + + public static ItemStackBuilder builder(ItemType type) { + return new ItemStackBuilder(type, 1, Collections.emptyMap()); + } + + public static ItemStack from(BlockState state) { + return from(state, 1); + } + + public static ItemStack from(BlockState state, @NonNegative int amount) { + checkNotNull(state, "state"); + checkArgument(amount > 0, "Amount cannot be negative"); + return new ItemStack(state.getType(), amount, Map.of(ItemKeys.BLOCK_STATE, state)); + } + + public static ItemStack from(ItemType type) { + return from(type, 1); + } + + public static ItemStack from(ItemType type, @NonNegative int amount) { + checkNotNull(type, "type"); + checkArgument(amount > 0, "Amount cannot be negative"); + return new ItemStack(type, amount, Collections.emptyMap()); + } + public ItemType getType() { return type; } @@ -63,6 +96,10 @@ public T getData(DataKey key) { return (T) metadata.get(key); } + public BlockState getBlockState() { + return getData(ItemKeys.BLOCK_STATE); + } + @Override public int compareTo(ItemStack other) { if (other.getType().equals(this.getType())) { diff --git a/src/main/java/org/cloudburstmc/api/item/ItemType.java b/src/main/java/org/cloudburstmc/api/item/ItemType.java index d8fef51..a99e215 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemType.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemType.java @@ -1,34 +1,29 @@ package org.cloudburstmc.api.item; -import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.block.BlockType; -import org.cloudburstmc.api.block.trait.BlockTrait; +import org.cloudburstmc.api.data.DataKey; import org.cloudburstmc.api.util.Identifier; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashSet; +import java.util.Set; -import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; public sealed class ItemType permits BlockType { private final Identifier id; - private final Class metadataClass; + private final Set> dataKeys; - protected ItemType(Identifier id, Class metadataClass) { + protected ItemType(Identifier id, Set> dataKeys) { this.id = id; - this.metadataClass = metadataClass; + this.dataKeys = dataKeys; } public final Identifier getId() { return id; } - @Nullable - public final Class getMetadataClass() { - return metadataClass; + public Set> getDataKeys() { + return dataKeys; } @Override @@ -37,12 +32,12 @@ public String toString() { } public static ItemType of(Identifier id) { - return of(id, null); + return of(id, new DataKey[0]); } - public static ItemType of(Identifier id, Class metadataClass) { + public static ItemType of(Identifier id, DataKey... dataKeys) { checkNotNull(id, "id"); - return new ItemType(id, metadataClass); + return new ItemType(id, Set.of(dataKeys)); } } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemTypes.java b/src/main/java/org/cloudburstmc/api/item/ItemTypes.java index c51955c..e0b938a 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemTypes.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemTypes.java @@ -1,22 +1,7 @@ package org.cloudburstmc.api.item; import lombok.experimental.UtilityClass; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.cloudburstmc.api.block.BlockType; -import org.cloudburstmc.api.block.BlockTypes; -import org.cloudburstmc.api.item.data.Bucket; -import org.cloudburstmc.api.item.data.Coal; -import org.cloudburstmc.api.item.data.Damageable; -import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.Identifiers; -import org.cloudburstmc.api.util.data.DyeColor; -import org.cloudburstmc.api.util.data.TreeSpecies; - -import java.util.IdentityHashMap; -import java.util.Map; - -import static org.cloudburstmc.api.item.TierTypes.*; -import static org.cloudburstmc.api.item.ToolTypes.*; @UtilityClass public class ItemTypes { @@ -256,4 +241,6 @@ public class ItemTypes { public static final ItemType RAW_IRON = ItemType.of(ItemIds.RAW_IRON); //.build(); public static final ItemType SPYGLASS = ItemType.of(ItemIds.SPYGLASS); //.build(); public static final ItemType COPPER_INGOT = ItemType.of(ItemIds.COPPER_INGOT); //.build(); + + public static final ItemType LAPIS_LAZULI = ItemType.of(ItemIds.LAPIS_LAZULI); } diff --git a/src/main/java/org/cloudburstmc/api/level/Level.java b/src/main/java/org/cloudburstmc/api/level/Level.java index fc29168..3248f2f 100644 --- a/src/main/java/org/cloudburstmc/api/level/Level.java +++ b/src/main/java/org/cloudburstmc/api/level/Level.java @@ -210,4 +210,7 @@ default DroppedItem dropItem(Vector3f position, ItemStack item, Vector3f motion, Set getNearbyEntities(AxisAlignedBB bb, Entity entity, boolean loadChunks); + int getMinHeight(); + + int getMaxHeight(); } diff --git a/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java index 9bfbf21..fe3df9d 100644 --- a/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java @@ -3,11 +3,11 @@ import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.util.behavior.Behavior; -import java.util.function.Function; +import java.util.function.BiFunction; -public interface BehaviorRegistry extends Registry { +public interface BehaviorRegistry { - void registerItemBehavior(BehaviorKey key, T defaultBehavior, Function, R> executorFactory); + void registerBehavior(BehaviorKey key, T defaultBehavior, BiFunction, T, R> executorFactory); - void registerBlockBehavior(BehaviorKey key, T defaultBehavior, Function, R> executorFactory); + T getDefaultBehavior(BehaviorKey key); } diff --git a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java index f2da833..21fe7df 100644 --- a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java @@ -8,7 +8,7 @@ import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.behavior.BehaviorCollection; -public interface BlockRegistry extends Registry { +public interface BlockRegistry extends BehaviorRegistry { BehaviorCollection register(BlockType type) throws RegistryException; diff --git a/src/main/java/org/cloudburstmc/api/registry/GameRuleRegistry.java b/src/main/java/org/cloudburstmc/api/registry/GameRuleRegistry.java index 8b80a45..ee2af03 100644 --- a/src/main/java/org/cloudburstmc/api/registry/GameRuleRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/GameRuleRegistry.java @@ -6,7 +6,7 @@ import java.util.List; import java.util.Set; -public interface GameRuleRegistry extends Registry { +public interface GameRuleRegistry { > void register(GameRule gameRule); diff --git a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java index 40f39b6..e8bb43b 100644 --- a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java @@ -1,30 +1,17 @@ package org.cloudburstmc.api.registry; import com.google.common.collect.ImmutableList; -import org.cloudburstmc.api.block.BlockState; import org.cloudburstmc.api.item.ItemStack; import org.cloudburstmc.api.item.ItemType; import org.cloudburstmc.api.item.behavior.ItemBehavior; import org.cloudburstmc.api.util.Identifier; -public interface ItemRegistry extends Registry { +public interface ItemRegistry extends BehaviorRegistry { void register(ItemType type, ItemBehavior behavior, Identifier... identifiers) throws RegistryException; void registerCreativeItem(ItemStack item); - default ItemStack getItem(BlockState state) throws RegistryException { - return getItem(state, 1); - } - - ItemStack getItem(BlockState state, int amount) throws RegistryException; - - default ItemStack getItem(ItemType type) throws RegistryException { - return getItem(type, 1); - } - - ItemStack getItem(ItemType type, int amount, Object... metadata) throws RegistryException; - Identifier getIdentifier(int runtimeId) throws RegistryException; ImmutableList getItems(); diff --git a/src/main/java/org/cloudburstmc/api/registry/RecipeRegistry.java b/src/main/java/org/cloudburstmc/api/registry/RecipeRegistry.java index cac5e8f..9732950 100644 --- a/src/main/java/org/cloudburstmc/api/registry/RecipeRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/RecipeRegistry.java @@ -8,7 +8,7 @@ import java.util.Collection; import java.util.UUID; -public interface RecipeRegistry extends Registry { +public interface RecipeRegistry { void register(Recipe recipe) throws RegistryException; diff --git a/src/main/java/org/cloudburstmc/api/registry/Registry.java b/src/main/java/org/cloudburstmc/api/registry/Registry.java deleted file mode 100644 index 0b487df..0000000 --- a/src/main/java/org/cloudburstmc/api/registry/Registry.java +++ /dev/null @@ -1,6 +0,0 @@ -package org.cloudburstmc.api.registry; - -public interface Registry { - - void close() throws RegistryException; -} diff --git a/src/main/java/org/cloudburstmc/api/registry/ResourcePackRegistry.java b/src/main/java/org/cloudburstmc/api/registry/ResourcePackRegistry.java index 133c434..aafa48b 100644 --- a/src/main/java/org/cloudburstmc/api/registry/ResourcePackRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/ResourcePackRegistry.java @@ -1,4 +1,4 @@ package org.cloudburstmc.api.registry; -public interface ResourcePackRegistry extends Registry { +public interface ResourcePackRegistry { } diff --git a/src/main/java/org/cloudburstmc/api/util/Randoms.java b/src/main/java/org/cloudburstmc/api/util/Randoms.java new file mode 100644 index 0000000..5180580 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/Randoms.java @@ -0,0 +1,22 @@ +package org.cloudburstmc.api.util; + +import java.util.random.RandomGenerator; + +public final class Randoms { + + public static int nextInclusiveInt(RandomGenerator random, int min, int max) { + if (min < max + 1) { + min += random.nextInt(max - min + 1); + } + return min; + } + + public static boolean chance(RandomGenerator random, int likeliness, int possibilities) { + return possibilities > 0 && (likeliness >= possibilities || + nextInclusiveInt(random, 1, possibilities) >= likeliness); + } + + public static boolean chanceInOne(RandomGenerator random, int possibilities) { + return chance(random, 1, possibilities); + } +} diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java index bf9c013..948fd86 100644 --- a/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java +++ b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java @@ -20,5 +20,5 @@ public interface Behavior { * @param function type * @return behavior function */ - U getBehavior(BehaviorKey key); + U get(BehaviorKey key); } diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorBuilder.java b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorBuilder.java new file mode 100644 index 0000000..431b9aa --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorBuilder.java @@ -0,0 +1,72 @@ +package org.cloudburstmc.api.util.behavior; + +import org.cloudburstmc.api.data.BehaviorKey; + +import java.util.*; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; + +public final class BehaviorBuilder { + + private final Map, List> behaviors = new IdentityHashMap<>(); + + private BehaviorBuilder() { + } + + public static BehaviorBuilder create() { + return new BehaviorBuilder(); + } + + public static BehaviorBuilder extend(BehaviorBuilder builder) { + BehaviorBuilder extendedBuilder = new BehaviorBuilder(); + extendedBuilder.behaviors.putAll(builder.behaviors); + return extendedBuilder; + } + + public BehaviorBuilder extend(BehaviorKey key, T function) { + checkNotNull(key, "key"); + checkNotNull(function, "function"); + checkArgument(key.getType() == function.getClass(), "%s does not match expected type of %s for '%s'", + function.getClass(), key.getType(), key.getId()); + + List functions = this.behaviors.computeIfAbsent(key, behaviorKey -> { + var list = new ArrayList<>(); + list.add(null); + return list; + }); + + functions.add(function); + return this; + } + + public BehaviorBuilder overwrite(BehaviorKey key, T function) { + checkNotNull(key, "key"); + checkNotNull(function, "function"); + checkArgument(key.getType() == function.getClass(), "%s does not match expected type of %s for '%s'", + function.getClass(), key.getType(), key.getId()); + + List functions = this.behaviors.computeIfAbsent(key, behaviorKey -> new ArrayList<>()); + + functions.clear(); + functions.add(function); + return this; + } + + @SuppressWarnings("unchecked") + public void applyTo(BehaviorCollection collection) { + for (Map.Entry, List> entry : this.behaviors.entrySet()) { + ListIterator iterator = entry.getValue().listIterator(); + + Object function = iterator.next(); + if (function == null) { + collection.extend((BehaviorKey) entry.getKey(), iterator.next()); + } else { + collection.overwrite((BehaviorKey) entry.getKey(), function); + } + while (iterator.hasNext()) { + collection.extend((BehaviorKey) entry.getKey(), iterator.next()); + } + } + } +} diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java index 9a03348..6d03981 100644 --- a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java +++ b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java @@ -32,4 +32,11 @@ public interface BehaviorCollection { * @return this behavior collection */ BehaviorCollection overwrite(BehaviorKey key, T function); + + /** + * Applies all behaviors in a {@link BehaviorBuilder} to the specified collection. + * + * @param builder builder + */ + void apply(BehaviorBuilder builder); } From 8a721211f9959f81b005efdd861ce71d5dcd6dab Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 23 Apr 2022 14:55:18 +0100 Subject: [PATCH 11/42] Continue working on item behaviours --- pom.xml | 6 +-- .../api/block/BlockBehaviors.java | 4 ++ .../cloudburstmc/api/data/BehaviorKey.java | 18 +++---- .../org/cloudburstmc/api/data/DataKey.java | 6 +-- .../org/cloudburstmc/api/data/DataStore.java | 2 +- .../api/enchantment/EnchantmentBehaviors.java | 36 +++++++++++++ .../behavior/DamageBonusBehavior.java | 14 ++++++ .../behavior/DamageProtectionBehavior.java | 14 ++++++ .../behavior/PostHurtBehavior.java | 15 ++++++ .../event/inventory/FurnaceSmeltEvent.java | 2 +- .../cloudburstmc/api/item/ItemBehaviors.java | 7 +++ .../org/cloudburstmc/api/item/ItemKeys.java | 20 ++++++++ .../org/cloudburstmc/api/item/ItemStack.java | 50 ++++++++++++------- .../org/cloudburstmc/api/item/ItemTypes.java | 8 +++ .../api/registry/BehaviorRegistry.java | 15 ++++-- .../api/registry/GlobalRegistry.java | 6 +++ .../api/registry/ItemRegistry.java | 12 +++++ .../api/util/behavior/Behavior.java | 19 +++++-- .../api/util/behavior/BehaviorCollection.java | 8 +++ .../api/util/behavior/FloatBehavior.java | 11 ++++ .../api/util/behavior/IntBehavior.java | 11 ++++ 21 files changed, 243 insertions(+), 41 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/enchantment/EnchantmentBehaviors.java create mode 100644 src/main/java/org/cloudburstmc/api/enchantment/behavior/DamageBonusBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/enchantment/behavior/DamageProtectionBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/enchantment/behavior/PostHurtBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/registry/GlobalRegistry.java create mode 100644 src/main/java/org/cloudburstmc/api/util/behavior/FloatBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/util/behavior/IntBehavior.java diff --git a/pom.xml b/pom.xml index 412b015..def0048 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ UTF-8 5.7.1 - 2.12.3 + 2.13.2 3.18.1 @@ -81,7 +81,7 @@ com.fasterxml.jackson.core jackson-databind - ${jackson.version} + 2.13.2.2 com.fasterxml.jackson.dataformat @@ -103,7 +103,7 @@ com.google.guava guava - 29.0-jre + 30.0-android diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index ad1a6b2..8eb45b0 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -133,4 +133,8 @@ private BlockBehaviors() { 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 ON_ENTITY_COLLIDE = DataKey.behavior(Identifier.fromString("on_entity_collide"), EntityBlockBehavior.class, EntityBlockBehavior.Executor.class); } diff --git a/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java b/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java index d98ebf6..8cac605 100644 --- a/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java +++ b/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java @@ -4,13 +4,13 @@ import java.util.function.Function; -public final class BehaviorKey implements DataKey { +public final class BehaviorKey implements DataKey { private final Identifier id; - private final Class functionType; - private final Class executorType; + private final Class functionType; + private final Class executorType; - BehaviorKey(Identifier id, Class functionType, Class executorType) { + BehaviorKey(Identifier id, Class functionType, Class executorType) { this.id = id; this.functionType = functionType; this.executorType = executorType; @@ -22,26 +22,26 @@ public Identifier getId() { } @Override - public Class getType() { + public Class getType() { return functionType; } @Override - public Class getMutableType() { + public Class getMutableType() { return executorType; } - public Class getExecutorType() { + public Class getExecutorType() { return executorType; } @Override - public Function getImmutableFunction() { + public Function getImmutableFunction() { throw new UnsupportedOperationException(); } @Override - public Function getMutableFunction() { + public Function getMutableFunction() { throw new UnsupportedOperationException(); } } diff --git a/src/main/java/org/cloudburstmc/api/data/DataKey.java b/src/main/java/org/cloudburstmc/api/data/DataKey.java index 1c84c1e..bbff63e 100644 --- a/src/main/java/org/cloudburstmc/api/data/DataKey.java +++ b/src/main/java/org/cloudburstmc/api/data/DataKey.java @@ -21,16 +21,16 @@ static ListDataKey list(Identifier id, Class type) { return new ListDataKey<>(id, type); } - static BehaviorKey behavior(Identifier id, Class type) { + static BehaviorKey behavior(Identifier id, Class type) { return behavior(id, type, type); } @SuppressWarnings("unchecked") - static BehaviorKey behavior(Identifier id, Class functionType, Class returnType) { + static BehaviorKey behavior(Identifier id, Class functionType, Class returnType) { checkNotNull(id, "id"); checkNotNull(functionType, "functionType"); checkNotNull(returnType, "returnType"); - return new BehaviorKey<>(id, (Class) functionType, (Class) returnType); + return new BehaviorKey<>(id, (Class) functionType, (Class) returnType); } Identifier getId(); diff --git a/src/main/java/org/cloudburstmc/api/data/DataStore.java b/src/main/java/org/cloudburstmc/api/data/DataStore.java index e4c17c4..26beb82 100644 --- a/src/main/java/org/cloudburstmc/api/data/DataStore.java +++ b/src/main/java/org/cloudburstmc/api/data/DataStore.java @@ -2,5 +2,5 @@ public interface DataStore { - T getData(DataKey key); + T get(DataKey key); } diff --git a/src/main/java/org/cloudburstmc/api/enchantment/EnchantmentBehaviors.java b/src/main/java/org/cloudburstmc/api/enchantment/EnchantmentBehaviors.java new file mode 100644 index 0000000..490978f --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/enchantment/EnchantmentBehaviors.java @@ -0,0 +1,36 @@ +package org.cloudburstmc.api.enchantment; + +import org.cloudburstmc.api.data.BehaviorKey; +import org.cloudburstmc.api.data.DataKey; +import org.cloudburstmc.api.enchantment.behavior.DamageBonusBehavior; +import org.cloudburstmc.api.enchantment.behavior.DamageProtectionBehavior; +import org.cloudburstmc.api.enchantment.behavior.PostHurtBehavior; +import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.api.util.behavior.IntBehavior; + +public final class EnchantmentBehaviors { + + public static final BehaviorKey GET_DAMAGE_BONUS = + DataKey.behavior(Identifier.fromString("get_damage_bonus"), DamageBonusBehavior.class, DamageBonusBehavior.Executor.class); + + public static final BehaviorKey GET_DAMAGE_PROTECTION = + DataKey.behavior(Identifier.fromString("get_damage_protection"), DamageProtectionBehavior.class, DamageProtectionBehavior.Executor.class); + + public static final BehaviorKey DO_POST_HURT = + DataKey.behavior(Identifier.fromString("do_post_hurt"), PostHurtBehavior.class, PostHurtBehavior.Executor.class); + + public static final BehaviorKey GET_MIN_LEVEL = + DataKey.behavior(Identifier.fromString("get_min_level"), IntBehavior.class, IntBehavior.Executor.class); + + public static final BehaviorKey GET_MAX_LEVEL = + DataKey.behavior(Identifier.fromString("get_max_level"), IntBehavior.class, IntBehavior.Executor.class); + + public static final BehaviorKey GET_MIN_COST = + DataKey.behavior(Identifier.fromString("get_min_cost"), IntBehavior.class, IntBehavior.Executor.class); + + public static final BehaviorKey GET_MAX_COST = + DataKey.behavior(Identifier.fromString("get_max_cost"), IntBehavior.class, IntBehavior.Executor.class); + + public static final BehaviorKey GET_FREQUENCY = + DataKey.behavior(Identifier.fromString("get_frequency"), IntBehavior.class, IntBehavior.Executor.class); +} diff --git a/src/main/java/org/cloudburstmc/api/enchantment/behavior/DamageBonusBehavior.java b/src/main/java/org/cloudburstmc/api/enchantment/behavior/DamageBonusBehavior.java new file mode 100644 index 0000000..cd543bd --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/enchantment/behavior/DamageBonusBehavior.java @@ -0,0 +1,14 @@ +package org.cloudburstmc.api.enchantment.behavior; + +import org.cloudburstmc.api.entity.Entity; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface DamageBonusBehavior { + + float getDamageBonus(Behavior behavior, int level, Entity target); + + @FunctionalInterface + interface Executor { + float execute(int level, Entity target); + } +} diff --git a/src/main/java/org/cloudburstmc/api/enchantment/behavior/DamageProtectionBehavior.java b/src/main/java/org/cloudburstmc/api/enchantment/behavior/DamageProtectionBehavior.java new file mode 100644 index 0000000..1953190 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/enchantment/behavior/DamageProtectionBehavior.java @@ -0,0 +1,14 @@ +package org.cloudburstmc.api.enchantment.behavior; + +import org.cloudburstmc.api.event.entity.EntityDamageEvent; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface DamageProtectionBehavior { + + int getDamageProtection(Behavior behavior, int level, EntityDamageEvent event); + + @FunctionalInterface + interface Executor { + int execute(int level, EntityDamageEvent event); + } +} diff --git a/src/main/java/org/cloudburstmc/api/enchantment/behavior/PostHurtBehavior.java b/src/main/java/org/cloudburstmc/api/enchantment/behavior/PostHurtBehavior.java new file mode 100644 index 0000000..a5874d4 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/enchantment/behavior/PostHurtBehavior.java @@ -0,0 +1,15 @@ +package org.cloudburstmc.api.enchantment.behavior; + +import org.cloudburstmc.api.entity.Entity; +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface PostHurtBehavior { + + void doPostHurt(Behavior behavior, ItemStack item, Entity victim, Entity attacker, int level); + + @FunctionalInterface + interface Executor { + void execute(ItemStack item, Entity victim, Entity attacker, int level); + } +} diff --git a/src/main/java/org/cloudburstmc/api/event/inventory/FurnaceSmeltEvent.java b/src/main/java/org/cloudburstmc/api/event/inventory/FurnaceSmeltEvent.java index e820fd4..c6a4b15 100644 --- a/src/main/java/org/cloudburstmc/api/event/inventory/FurnaceSmeltEvent.java +++ b/src/main/java/org/cloudburstmc/api/event/inventory/FurnaceSmeltEvent.java @@ -17,7 +17,7 @@ public final class FurnaceSmeltEvent extends BlockEvent implements Cancellable { public FurnaceSmeltEvent(Furnace furnace, ItemStack source, ItemStack result) { super(furnace.getBlock()); - this.source = source.withAmount(1); + this.source = source.withCount(1); this.result = result; this.furnace = furnace; } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java index 9c7e350..3d96333 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java @@ -1,8 +1,15 @@ package org.cloudburstmc.api.item; import lombok.experimental.UtilityClass; +import org.cloudburstmc.api.data.BehaviorKey; +import org.cloudburstmc.api.data.DataKey; +import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.api.util.behavior.IntBehavior; @UtilityClass public class ItemBehaviors { + public static final BehaviorKey GET_MAX_STACK_SIZE = DataKey.behavior(Identifier.fromString("get_max_stack_size"), IntBehavior.class, IntBehavior.Executor.class); + + public static final BehaviorKey GET_MAX_DURABILITY = DataKey.behavior(Identifier.fromString("get_max_durability"), IntBehavior.class, IntBehavior.Executor.class); } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java index 29d5809..97803f8 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java @@ -1,21 +1,29 @@ package org.cloudburstmc.api.item; import org.cloudburstmc.api.block.BlockState; +import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.data.DataKey; import org.cloudburstmc.api.data.ListDataKey; import org.cloudburstmc.api.data.SimpleDataKey; import org.cloudburstmc.api.enchantment.Enchantment; +import org.cloudburstmc.api.entity.EntityType; import org.cloudburstmc.api.item.data.Bucket; +import org.cloudburstmc.api.item.data.Record; import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.data.DyeColor; import org.cloudburstmc.api.util.data.FireworkData; +import org.cloudburstmc.api.util.data.TreeSpecies; public final class ItemKeys { public static final SimpleDataKey BLOCK_STATE = DataKey.simple(Identifier.fromString("block_state"), BlockState.class); + public static final SimpleDataKey CUSTOM_NAME = DataKey.simple(Identifier.fromString("custom_name"), String.class); + public static final SimpleDataKey DAMAGE = DataKey.simple(Identifier.fromString("item_damage"), Integer.class); + public static final SimpleDataKey UNBREAKABLE = DataKey.simple(Identifier.fromString("unbreakable"), Boolean.class); + public static final SimpleDataKey COLOR = DataKey.simple(Identifier.fromString("dye_color"), DyeColor.class); public static final ListDataKey ENCHANTMENTS = DataKey.list(Identifier.fromString("enchantments"), Enchantment.class); @@ -23,4 +31,16 @@ public final class ItemKeys { public static final SimpleDataKey FIREWORK_DATA = DataKey.simple(Identifier.fromString("firework_data"), FireworkData.class); public static final SimpleDataKey BUCKET_DATA = DataKey.simple(Identifier.fromString("bucket_data"), Bucket.class); + + public static final ListDataKey CAN_DESTROY = DataKey.list(Identifier.fromString("can_destroy"), BlockType.class); + + public static final ListDataKey CAN_PLACE_ON = DataKey.list(Identifier.fromString("can_place_on"), BlockType.class); + + public static final SimpleDataKey SHIELD_BLOCKING_TICKS = DataKey.simple(Identifier.fromString("shield_blocking_ticks"), Long.class); + + public static final SimpleDataKey RECORD_TYPE = DataKey.simple(Identifier.fromString("record_type"), Record.class); + + public static final SimpleDataKey> SPAWN_EGG_TYPE = DataKey.simple(Identifier.fromString("spawn_egg_type"), EntityType.class); + + public static final SimpleDataKey TREE_SPECIES = DataKey.simple(Identifier.fromString("tree_species"), TreeSpecies.class); } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStack.java b/src/main/java/org/cloudburstmc/api/item/ItemStack.java index 67b3838..6ba6ea0 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStack.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStack.java @@ -2,7 +2,9 @@ import com.google.common.collect.ImmutableMap; import org.checkerframework.checker.index.qual.NonNegative; +import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.block.BlockState; +import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.block.BlockTypes; import org.cloudburstmc.api.data.DataKey; import org.cloudburstmc.api.data.DataStore; @@ -18,12 +20,12 @@ public final class ItemStack implements DataStore, Comparable { public static final ItemStack AIR = new ItemStack(BlockTypes.AIR, 0, Collections.emptyMap()); private final ItemType type; - private final int amount; + private final int count; private final ImmutableMap, ?> metadata; - ItemStack(ItemType type, int amount, Map, ?> metadata) { + ItemStack(ItemType type, int count, Map, ?> metadata) { this.type = type; - this.amount = amount; + this.count = count; this.metadata = ImmutableMap.copyOf(metadata); } @@ -64,46 +66,60 @@ public ItemType getType() { return type; } - public int getAmount() { - return amount; + public int getCount() { + return count; } public ItemStackBuilder toBuilder() { - return new ItemStackBuilder(this.type, this.amount, this.metadata); + return new ItemStackBuilder(this.type, this.count, this.metadata); } - public ItemStack reduceAmount() { - return withAmount(this.amount - 1); + public ItemStack decreaseCount() { + return withCount(-1); } - public ItemStack increaseAmount() { - return addAmount(1); + public ItemStack decreaseCount(int count) { + return withCount(-count); } - public ItemStack addAmount(int delta) { - return withAmount(this.amount + delta); + public ItemStack increaseCount() { + return addCount(1); } - public ItemStack withAmount(int amount) { - if (this.amount == amount) { + public ItemStack increaseCount(int count) { + return addCount(count); + } + + public ItemStack addCount(int delta) { + return withCount(this.count + delta); + } + + public ItemStack withCount(int amount) { + if (this.count == amount) { return this; } return toBuilder().amount(amount).build(); } @SuppressWarnings("unchecked") - public T getData(DataKey key) { + @Override + public T get(DataKey key) { return (T) metadata.get(key); } + @Nullable public BlockState getBlockState() { - return getData(ItemKeys.BLOCK_STATE); + return isBlock() ? get(ItemKeys.BLOCK_STATE) : null; + } + + public boolean isBlock() { + return type instanceof BlockType; } @Override public int compareTo(ItemStack other) { if (other.getType().equals(this.getType())) { - return this.getAmount() - other.getAmount(); + return this.getCount() - other.getCount(); } return this.getType().getId().compareTo(other.getType().getId()); } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemTypes.java b/src/main/java/org/cloudburstmc/api/item/ItemTypes.java index e0b938a..5f100b7 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemTypes.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemTypes.java @@ -14,6 +14,7 @@ public class ItemTypes { public static final ItemType BOW = ItemType.of(ItemIds.BOW); //.maxStackSize(1).fuelTime((short) 200).build(); public static final ItemType ARROW = ItemType.of(ItemIds.ARROW); //.maxStackSize(64).build(); public static final ItemType COAL = ItemType.of(ItemIds.COAL); //.maxStackSize(64).data(Coal.class).fuelTime((short) 1600).build(); + public static final ItemType CHARCOAL = ItemType.of(ItemIds.CHARCOAL); public static final ItemType DIAMOND = ItemType.of(ItemIds.DIAMOND); //.maxStackSize(64).build(); public static final ItemType IRON_INGOT = ItemType.of(ItemIds.IRON_INGOT); //.maxStackSize(64).build(); public static final ItemType GOLD_INGOT = ItemType.of(ItemIds.GOLD_INGOT); //.maxStackSize(64).build(); @@ -76,6 +77,13 @@ public class ItemTypes { public static final ItemType SIGN = ItemType.of(ItemIds.SIGN); //.maxStackSize(16).blockType(BlockTypes.STANDING_SIGN).data(TreeSpecies.class).build(); public static final ItemType WOODEN_DOOR = ItemType.of(ItemIds.WOODEN_DOOR); //.maxStackSize(64).blockType(BlockTypes.WOODEN_DOOR).data(TreeSpecies.class).build(); public static final ItemType BUCKET = ItemType.of(ItemIds.BUCKET); //.data(Bucket.class).maxStackSize(16).build(); + public static final ItemType MILK_BUCKET = ItemType.of(ItemIds.MILK_BUCKET); + public static final ItemType COD_BUCKET = ItemType.of(ItemIds.COD_BUCKET); + public static final ItemType SALMON_BUCKET = ItemType.of(ItemIds.SALMON_BUCKET); + public static final ItemType TROPICAL_FISH_BUCKET = ItemType.of(ItemIds.TROPICAL_FISH_BUCKET); + public static final ItemType PUFFERFISH_BUCKET = ItemType.of(ItemIds.PUFFERFISH_BUCKET); + public static final ItemType WATER_BUCKET = ItemType.of(ItemIds.WATER_BUCKET); + public static final ItemType LAVA_BUCKET = ItemType.of(ItemIds.LAVA_BUCKET); public static final ItemType MINECART = ItemType.of(ItemIds.MINECART); //.maxStackSize(1).build(); public static final ItemType SADDLE = ItemType.of(ItemIds.SADDLE); //.maxStackSize(1).build(); public static final ItemType IRON_DOOR = ItemType.of(ItemIds.IRON_DOOR); //.maxStackSize(64).blockType(BlockTypes.IRON_DOOR).build(); diff --git a/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java index fe3df9d..7baf2f0 100644 --- a/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java @@ -2,12 +2,21 @@ import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.util.behavior.Behavior; +import org.cloudburstmc.api.util.behavior.BehaviorCollection; import java.util.function.BiFunction; -public interface BehaviorRegistry { +public interface BehaviorRegistry { - void registerBehavior(BehaviorKey key, T defaultBehavior, BiFunction, T, R> executorFactory); + void registerBehavior(BehaviorKey key, F defaultBehavior, BiFunction, F, E> executorFactory); - T getDefaultBehavior(BehaviorKey key); + F getDefaultBehavior(BehaviorKey key); + + BehaviorCollection getBehaviors(T type); + + default E getBehavior(T type, BehaviorKey key) { + return getBehaviors(type).get(key); + } + + GlobalRegistry global(); } diff --git a/src/main/java/org/cloudburstmc/api/registry/GlobalRegistry.java b/src/main/java/org/cloudburstmc/api/registry/GlobalRegistry.java new file mode 100644 index 0000000..18b3738 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/registry/GlobalRegistry.java @@ -0,0 +1,6 @@ +package org.cloudburstmc.api.registry; + +public interface GlobalRegistry { + + BehaviorRegistry getRegistry(Class typeClass); +} diff --git a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java index e8bb43b..6ae9dab 100644 --- a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java @@ -1,10 +1,12 @@ package org.cloudburstmc.api.registry; import com.google.common.collect.ImmutableList; +import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.item.ItemStack; import org.cloudburstmc.api.item.ItemType; import org.cloudburstmc.api.item.behavior.ItemBehavior; import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.api.util.behavior.BehaviorCollection; public interface ItemRegistry extends BehaviorRegistry { @@ -12,8 +14,18 @@ public interface ItemRegistry extends BehaviorRegistry { void registerCreativeItem(ItemStack item); + BehaviorCollection getBehaviors(ItemType type); + + default T getBehavior(ItemType type, BehaviorKey key) { + return getBehaviors(type).get(key); + } + Identifier getIdentifier(int runtimeId) throws RegistryException; + ItemType getType(Identifier runtimeId, int data); + + ItemType getType(int runtimeId, int data); + ImmutableList getItems(); } diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java index 948fd86..9ec3850 100644 --- a/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java +++ b/src/main/java/org/cloudburstmc/api/util/behavior/Behavior.java @@ -2,8 +2,9 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.cloudburstmc.api.data.BehaviorKey; +import org.cloudburstmc.api.registry.BehaviorRegistry; -public interface Behavior { +public interface Behavior { /** * Returns the parent function or the default if nothing is set. @@ -11,14 +12,24 @@ public interface Behavior { * @return function */ @NonNull - T parent(); + E parent(); /** * Get a behavior for a specified key * * @param key behavior key - * @param function type + * @param function type * @return behavior function */ - U get(BehaviorKey key); + T get(BehaviorKey key); + + /** + * Retrieves a {@link BehaviorRegistry} for the given class. + * + * @param type class of registry type + * @param registry type + * @return behavior registry + * @throws IllegalArgumentException if registry type does not exist + */ + BehaviorRegistry getRegistry(Class type); } diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java index 6d03981..ae837bc 100644 --- a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java +++ b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorCollection.java @@ -1,6 +1,7 @@ package org.cloudburstmc.api.util.behavior; import org.cloudburstmc.api.data.BehaviorKey; +import org.cloudburstmc.api.registry.BehaviorRegistry; public interface BehaviorCollection { @@ -39,4 +40,11 @@ public interface BehaviorCollection { * @param builder builder */ void apply(BehaviorBuilder builder); + + /** + * Get the registry that this behavior collection belongs to. + * + * @return behavior registry + */ + BehaviorRegistry getRegistry(); } diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/FloatBehavior.java b/src/main/java/org/cloudburstmc/api/util/behavior/FloatBehavior.java new file mode 100644 index 0000000..781bf13 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/behavior/FloatBehavior.java @@ -0,0 +1,11 @@ +package org.cloudburstmc.api.util.behavior; + +public interface FloatBehavior { + + float getProperty(Behavior behavior); + + @FunctionalInterface + interface Executor { + float execute(); + } +} diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/IntBehavior.java b/src/main/java/org/cloudburstmc/api/util/behavior/IntBehavior.java new file mode 100644 index 0000000..52f7a83 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/util/behavior/IntBehavior.java @@ -0,0 +1,11 @@ +package org.cloudburstmc.api.util.behavior; + +public interface IntBehavior { + + int get(Behavior behavior); + + @FunctionalInterface + interface Executor { + int execute(); + } +} From c82026c100f2fc620c57e4986711065a9eddd171 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:03:49 +0100 Subject: [PATCH 12/42] Add Vector3i version of AxisAlignedBB#addCoord --- src/main/java/org/cloudburstmc/api/util/AxisAlignedBB.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/org/cloudburstmc/api/util/AxisAlignedBB.java b/src/main/java/org/cloudburstmc/api/util/AxisAlignedBB.java index e2c75cf..ac38d8f 100644 --- a/src/main/java/org/cloudburstmc/api/util/AxisAlignedBB.java +++ b/src/main/java/org/cloudburstmc/api/util/AxisAlignedBB.java @@ -17,6 +17,10 @@ default AxisAlignedBB setBounds(float minX, float minY, float minZ, float maxX, return this; } + default AxisAlignedBB addCoord(Vector3i v) { + return addCoord(v.getX(), v.getY(), v.getZ()); + } + default AxisAlignedBB addCoord(Vector3f v) { return addCoord(v.getX(), v.getY(), v.getZ()); } From 4b276c57650e7f3e099bf479b61b09b7f4125e11 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:04:18 +0100 Subject: [PATCH 13/42] Add CAN_DESTROY item behaviour --- src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java index 3d96333..c35cbb4 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java @@ -1,6 +1,7 @@ package org.cloudburstmc.api.item; import lombok.experimental.UtilityClass; +import org.cloudburstmc.api.block.behavior.BooleanBlockBehavior; import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.data.DataKey; import org.cloudburstmc.api.util.Identifier; @@ -12,4 +13,6 @@ public class ItemBehaviors { public static final BehaviorKey GET_MAX_STACK_SIZE = DataKey.behavior(Identifier.fromString("get_max_stack_size"), IntBehavior.class, IntBehavior.Executor.class); public static final BehaviorKey GET_MAX_DURABILITY = DataKey.behavior(Identifier.fromString("get_max_durability"), IntBehavior.class, IntBehavior.Executor.class); + + public static final BehaviorKey CAN_DESTROY = DataKey.behavior(Identifier.fromString("can_destroy"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class); } From dcb8baeb51e2319fe174c937435235d442494f76 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 23 Apr 2022 21:04:39 +0100 Subject: [PATCH 14/42] Create MapDataKey for enchantments --- .../org/cloudburstmc/api/data/DataKey.java | 9 +++- .../org/cloudburstmc/api/data/MapDataKey.java | 47 +++++++++++++++++++ .../org/cloudburstmc/api/item/ItemKeys.java | 4 +- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/data/MapDataKey.java diff --git a/src/main/java/org/cloudburstmc/api/data/DataKey.java b/src/main/java/org/cloudburstmc/api/data/DataKey.java index bbff63e..c2c7453 100644 --- a/src/main/java/org/cloudburstmc/api/data/DataKey.java +++ b/src/main/java/org/cloudburstmc/api/data/DataKey.java @@ -6,7 +6,7 @@ import static com.google.common.base.Preconditions.checkNotNull; -public sealed interface DataKey permits BehaviorKey, ListDataKey, SimpleDataKey { +public sealed interface DataKey permits BehaviorKey, ListDataKey, SimpleDataKey, MapDataKey { @SuppressWarnings("unchecked") static SimpleDataKey simple(Identifier id, Class type) { @@ -21,6 +21,13 @@ static ListDataKey list(Identifier id, Class 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); } 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..59ad463 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/data/MapDataKey.java @@ -0,0 +1,47 @@ +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, Map> { + + private final Identifier id; + private final Class keyType; + private final Class valueType; + + MapDataKey(Identifier id, Class keyType, Class valueType) { + this.id = id; + this.keyType = keyType; + this.valueType = valueType; + } + + @Override + public Identifier getId() { + return id; + } + + @Override + public Class> getType() { + return (Class) ImmutableMap.class; + } + + @Override + public Class> getMutableType() { + return (Class) Map.class; + } + + @Override + public Function, Map> getImmutableFunction() { + return ImmutableMap::copyOf; + } + + @Override + public Function, Map> getMutableFunction() { + return HashMap::new; + } +} diff --git a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java index 97803f8..61e52b0 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java @@ -4,8 +4,10 @@ import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.data.DataKey; import org.cloudburstmc.api.data.ListDataKey; +import org.cloudburstmc.api.data.MapDataKey; import org.cloudburstmc.api.data.SimpleDataKey; import org.cloudburstmc.api.enchantment.Enchantment; +import org.cloudburstmc.api.enchantment.EnchantmentType; import org.cloudburstmc.api.entity.EntityType; import org.cloudburstmc.api.item.data.Bucket; import org.cloudburstmc.api.item.data.Record; @@ -26,7 +28,7 @@ public final class ItemKeys { public static final SimpleDataKey COLOR = DataKey.simple(Identifier.fromString("dye_color"), DyeColor.class); - public static final ListDataKey ENCHANTMENTS = DataKey.list(Identifier.fromString("enchantments"), Enchantment.class); + public static final MapDataKey ENCHANTMENTS = DataKey.map(Identifier.fromString("enchantments"), EnchantmentType.class, Enchantment.class); public static final SimpleDataKey FIREWORK_DATA = DataKey.simple(Identifier.fromString("firework_data"), FireworkData.class); From 74be65b4491ff2261a019147fb57dd6c47e6baf2 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:50:02 +0100 Subject: [PATCH 15/42] Add checkerframework exclusions --- pom.xml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/pom.xml b/pom.xml index def0048..60275d9 100644 --- a/pom.xml +++ b/pom.xml @@ -104,6 +104,12 @@ com.google.guava guava 30.0-android + + + org.checkerframework + checker-compat-qual + + From d428e86836cdc47320440e44911c846d8b802533 Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Tue, 26 Apr 2022 01:17:02 +0200 Subject: [PATCH 16/42] Fixed a couple of issues and added the Filtered Light block behaviour --- .../org/cloudburstmc/api/block/Block.java | 92 ------------------- .../api/block/BlockBehaviors.java | 3 + .../org/cloudburstmc/api/item/ItemStack.java | 17 +++- .../api/registry/ItemRegistry.java | 4 +- 4 files changed, 20 insertions(+), 96 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/block/Block.java b/src/main/java/org/cloudburstmc/api/block/Block.java index a97a676..a44206f 100644 --- a/src/main/java/org/cloudburstmc/api/block/Block.java +++ b/src/main/java/org/cloudburstmc/api/block/Block.java @@ -39,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 index 8eb45b0..b096078 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -137,4 +137,7 @@ private BlockBehaviors() { public static final BehaviorKey GET_LIQUID_HEIGHT = DataKey.behavior(Identifier.fromString("get_fluid_height"), FloatBlockBehavior.class, FloatBlockBehavior.Executor.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); + } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStack.java b/src/main/java/org/cloudburstmc/api/item/ItemStack.java index 6ba6ea0..1d13cd1 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStack.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStack.java @@ -11,6 +11,7 @@ import java.util.Collections; import java.util.Map; +import java.util.Optional; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @@ -107,9 +108,21 @@ public T get(DataKey key) { return (T) metadata.get(key); } + public Optional getBlockState() { + return Optional.ofNullable(this.isBlock() ? this.get(ItemKeys.BLOCK_STATE) : null); + } + + public ImmutableMap, ?> getAllMetadata() { + return metadata; + } + @Nullable - public BlockState getBlockState() { - return isBlock() ? get(ItemKeys.BLOCK_STATE) : null; + public BlockState getEnsuringBlockState() { + if(!this.isBlock()) { + throw new NullPointerException("Current Item isn't a block so it can't have a BlockState."); + } + + return this.get(ItemKeys.BLOCK_STATE); } public boolean isBlock() { diff --git a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java index 6ae9dab..8dbac97 100644 --- a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java @@ -8,7 +8,7 @@ import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.behavior.BehaviorCollection; -public interface ItemRegistry extends BehaviorRegistry { +public interface ItemRegistry extends BehaviorRegistry { void register(ItemType type, ItemBehavior behavior, Identifier... identifiers) throws RegistryException; @@ -16,7 +16,7 @@ public interface ItemRegistry extends BehaviorRegistry { BehaviorCollection getBehaviors(ItemType type); - default T getBehavior(ItemType type, BehaviorKey key) { + default T getBehavior(ItemType type, BehaviorKey key) { return getBehaviors(type).get(key); } From 30576bc19f1922d07f1335e97b60a671f988c1ca Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Wed, 27 Apr 2022 00:01:45 +0200 Subject: [PATCH 17/42] Added ItemLore key --- src/main/java/org/cloudburstmc/api/item/ItemKeys.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java index 61e52b0..92446be 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java @@ -22,6 +22,8 @@ public final class ItemKeys { public static final SimpleDataKey CUSTOM_NAME = DataKey.simple(Identifier.fromString("custom_name"), String.class); + public static final ListDataKey CUSTOM_LORE = DataKey.list(Identifier.fromString("custom_lore"), String.class); + public static final SimpleDataKey DAMAGE = DataKey.simple(Identifier.fromString("item_damage"), Integer.class); public static final SimpleDataKey UNBREAKABLE = DataKey.simple(Identifier.fromString("unbreakable"), Boolean.class); From 8587777271db37f494c82f74ed2df259fe60ee7b Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Thu, 28 Apr 2022 14:58:32 +0200 Subject: [PATCH 18/42] Fixed the ItemRegistry generic type --- src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java index 8dbac97..6ae9dab 100644 --- a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java @@ -8,7 +8,7 @@ import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.behavior.BehaviorCollection; -public interface ItemRegistry extends BehaviorRegistry { +public interface ItemRegistry extends BehaviorRegistry { void register(ItemType type, ItemBehavior behavior, Identifier... identifiers) throws RegistryException; @@ -16,7 +16,7 @@ public interface ItemRegistry extends BehaviorRegistry { BehaviorCollection getBehaviors(ItemType type); - default T getBehavior(ItemType type, BehaviorKey key) { + default T getBehavior(ItemType type, BehaviorKey key) { return getBehaviors(type).get(key); } From 1c0f14852f458fa6526d289da0296756a6e0da8b Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Thu, 28 Apr 2022 22:49:47 +0100 Subject: [PATCH 19/42] Adding these back works for me My IDE (IntelliJ) isn't complaining about this, so we'll just go along with that. --- src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java | 3 ++- src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java index 21fe7df..e2c2f65 100644 --- a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java @@ -5,10 +5,11 @@ import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.item.ItemType; import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.behavior.BehaviorCollection; -public interface BlockRegistry extends BehaviorRegistry { +public interface BlockRegistry extends BehaviorRegistry { BehaviorCollection register(BlockType type) throws RegistryException; diff --git a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java index 6ae9dab..67a3067 100644 --- a/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/ItemRegistry.java @@ -8,7 +8,7 @@ import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.behavior.BehaviorCollection; -public interface ItemRegistry extends BehaviorRegistry { +public interface ItemRegistry extends BehaviorRegistry { void register(ItemType type, ItemBehavior behavior, Identifier... identifiers) throws RegistryException; From 3aeb7e5d259158ff3415c842c98dfad71e4668da Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Thu, 28 Apr 2022 22:50:25 +0100 Subject: [PATCH 20/42] Expand available item behaviours --- .../cloudburstmc/api/item/ItemBehaviors.java | 14 ++++++++++++++ .../item/behavior/DamageChanceBehavior.java | 13 +++++++++++++ .../item/behavior/DestroySpeedBehavior.java | 16 ++++++++++++++++ .../api/item/behavior/FloatItemBehavior.java | 15 +++++++++++++++ .../api/item/behavior/UseOnBehavior.java | 19 +++++++++++++++++++ 5 files changed, 77 insertions(+) create mode 100644 src/main/java/org/cloudburstmc/api/item/behavior/DamageChanceBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/item/behavior/DestroySpeedBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/item/behavior/FloatItemBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java diff --git a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java index c35cbb4..e2b5ca6 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java @@ -4,6 +4,10 @@ import org.cloudburstmc.api.block.behavior.BooleanBlockBehavior; import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.data.DataKey; +import org.cloudburstmc.api.item.behavior.DamageChanceBehavior; +import org.cloudburstmc.api.item.behavior.FloatItemBehavior; +import org.cloudburstmc.api.item.behavior.DestroySpeedBehavior; +import org.cloudburstmc.api.item.behavior.UseOnBehavior; import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.behavior.IntBehavior; @@ -15,4 +19,14 @@ public class ItemBehaviors { public static final BehaviorKey GET_MAX_DURABILITY = DataKey.behavior(Identifier.fromString("get_max_durability"), IntBehavior.class, IntBehavior.Executor.class); public static final BehaviorKey CAN_DESTROY = DataKey.behavior(Identifier.fromString("can_destroy"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class); + + public static final BehaviorKey GET_DESTROY_SPEED = DataKey.behavior(Identifier.fromString("get_destroy_speed"), DestroySpeedBehavior.class, DestroySpeedBehavior.Executor.class); + + public static final BehaviorKey GET_DESTROY_SPEED_BONUS = DataKey.behavior(Identifier.fromString("get_destroy_speed_bonus"), FloatItemBehavior.class, FloatItemBehavior.Executor.class); + + public static final BehaviorKey CAN_DESTROY_IN_CREATIVE = DataKey.behavior(Identifier.fromString("can_destroy_in_creative"), Boolean.class); + + public static final BehaviorKey GET_DAMAGE_CHANCE = DataKey.behavior(Identifier.fromString("get_damage_chance"), DamageChanceBehavior.class, DamageChanceBehavior.Executor.class); + + public static final BehaviorKey USE_ON = DataKey.behavior(Identifier.fromString("use_on"), UseOnBehavior.class, UseOnBehavior.Executor.class); } diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/DamageChanceBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/DamageChanceBehavior.java new file mode 100644 index 0000000..8f62814 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/behavior/DamageChanceBehavior.java @@ -0,0 +1,13 @@ +package org.cloudburstmc.api.item.behavior; + +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface DamageChanceBehavior { + + int getDamageChance(Behavior executor, int unbreaking); + + interface Executor { + + int execute(int unbreaking); + } +} diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/DestroySpeedBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/DestroySpeedBehavior.java new file mode 100644 index 0000000..7a1bae9 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/behavior/DestroySpeedBehavior.java @@ -0,0 +1,16 @@ +package org.cloudburstmc.api.item.behavior; + +import org.cloudburstmc.api.block.Block; +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface DestroySpeedBehavior { + + float getDestroySpeed(Behavior behavior, ItemStack itemStack, Block block); + + @FunctionalInterface + interface Executor { + + float execute(ItemStack itemStack, Block block); + } +} diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/FloatItemBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/FloatItemBehavior.java new file mode 100644 index 0000000..ea2a3ec --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/behavior/FloatItemBehavior.java @@ -0,0 +1,15 @@ +package org.cloudburstmc.api.item.behavior; + +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface FloatItemBehavior { + + float get(Behavior behavior, ItemStack itemStack); + + @FunctionalInterface + interface Executor { + + float execute(ItemStack itemStack); + } +} diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java new file mode 100644 index 0000000..f09173f --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java @@ -0,0 +1,19 @@ +package org.cloudburstmc.api.item.behavior; + +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.math.vector.Vector3i; +import org.cloudburstmc.api.entity.Entity; +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.util.Direction; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface UseOnBehavior { + + boolean useOn(Behavior behavior, ItemStack itemStack, Entity entity, Vector3i blockPosition, Direction face, Vector3f clickPosition); + + @FunctionalInterface + interface Executor { + + boolean execute(ItemStack itemStack, Entity entity, Vector3i blockPosition, Direction face, Vector3f clickPosition); + } +} From 883713d454f21fefbe284e76e534de58388827b5 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Thu, 28 Apr 2022 23:37:09 +0100 Subject: [PATCH 21/42] Add damage related behaviours --- .../cloudburstmc/api/block/BlockBehaviors.java | 2 ++ .../cloudburstmc/api/item/ItemBehaviors.java | 11 +++++++---- .../api/item/behavior/DamageItemBehavior.java | 15 +++++++++++++++ .../api/item/behavior/MineBlockBehavior.java | 17 +++++++++++++++++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/item/behavior/DamageItemBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/item/behavior/MineBlockBehavior.java diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index b096078..526a398 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -140,4 +140,6 @@ private BlockBehaviors() { 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); + } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java index e2b5ca6..5914b5e 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java @@ -4,10 +4,7 @@ import org.cloudburstmc.api.block.behavior.BooleanBlockBehavior; import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.data.DataKey; -import org.cloudburstmc.api.item.behavior.DamageChanceBehavior; -import org.cloudburstmc.api.item.behavior.FloatItemBehavior; -import org.cloudburstmc.api.item.behavior.DestroySpeedBehavior; -import org.cloudburstmc.api.item.behavior.UseOnBehavior; +import org.cloudburstmc.api.item.behavior.*; import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.behavior.IntBehavior; @@ -18,6 +15,10 @@ public class ItemBehaviors { public static final BehaviorKey GET_MAX_DURABILITY = DataKey.behavior(Identifier.fromString("get_max_durability"), IntBehavior.class, IntBehavior.Executor.class); + public static final BehaviorKey MINE_BLOCK = DataKey.behavior(Identifier.fromString("mine_block"), MineBlockBehavior.class, MineBlockBehavior.Executor.class); + + public static final BehaviorKey ON_DAMAGE = DataKey.behavior(Identifier.fromString("on_damage"), DamageItemBehavior.class, DamageItemBehavior.Executor.class); + public static final BehaviorKey CAN_DESTROY = DataKey.behavior(Identifier.fromString("can_destroy"), BooleanBlockBehavior.class, BooleanBlockBehavior.Executor.class); public static final BehaviorKey GET_DESTROY_SPEED = DataKey.behavior(Identifier.fromString("get_destroy_speed"), DestroySpeedBehavior.class, DestroySpeedBehavior.Executor.class); @@ -29,4 +30,6 @@ public class ItemBehaviors { public static final BehaviorKey GET_DAMAGE_CHANCE = DataKey.behavior(Identifier.fromString("get_damage_chance"), DamageChanceBehavior.class, DamageChanceBehavior.Executor.class); public static final BehaviorKey USE_ON = DataKey.behavior(Identifier.fromString("use_on"), UseOnBehavior.class, UseOnBehavior.Executor.class); + + public static final BehaviorKey GET_FUEL_DURATION = DataKey.behavior(Identifier.fromString("get_fuel_duration"), Float.class); } diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/DamageItemBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/DamageItemBehavior.java new file mode 100644 index 0000000..c3ba31e --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/behavior/DamageItemBehavior.java @@ -0,0 +1,15 @@ +package org.cloudburstmc.api.item.behavior; + +import org.cloudburstmc.api.entity.Entity; +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface DamageItemBehavior { + + ItemStack onDamage(Behavior behavior, ItemStack itemStack, int damage, Entity owner); + + interface Executor { + + ItemStack execute(ItemStack itemStack, int damage, Entity owner); + } +} diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/MineBlockBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/MineBlockBehavior.java new file mode 100644 index 0000000..9dacdf1 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/behavior/MineBlockBehavior.java @@ -0,0 +1,17 @@ +package org.cloudburstmc.api.item.behavior; + +import org.cloudburstmc.api.block.Block; +import org.cloudburstmc.api.entity.Entity; +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface MineBlockBehavior { + + ItemStack mineBlock(Behavior behavior, ItemStack itemStack, Block block, Entity owner); + + @FunctionalInterface + interface Executor { + + ItemStack mineBlock(ItemStack itemStack, Block block, Entity owner); + } +} From f48c7ff1e7d257a3d2e0f789f1be8a993f72d9e9 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Fri, 29 Apr 2022 23:41:45 +0100 Subject: [PATCH 22/42] Implement get_map_color block behavior --- .../cloudburstmc/api/block/BlockBehaviors.java | 2 ++ .../api/block/behavior/MapColorBehavior.java | 17 +++++++++++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/MapColorBehavior.java diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index 526a398..569b557 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -142,4 +142,6 @@ private BlockBehaviors() { 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); + } 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); + } +} From 8880902182d78aeb42741c04c68c3f6bffb58cb7 Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Tue, 3 May 2022 15:27:38 +0200 Subject: [PATCH 23/42] Added BOOK_DATA item key and increased the compiler error amount --- pom.xml | 6 ++++++ src/main/java/org/cloudburstmc/api/item/ItemKeys.java | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index 60275d9..f73e22f 100644 --- a/pom.xml +++ b/pom.xml @@ -147,6 +147,12 @@ 1.18.22 + + -Xmaxerrs + 1000 + -Xmaxwarns + 2000 + diff --git a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java index 92446be..9e6ff59 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java @@ -1,5 +1,6 @@ package org.cloudburstmc.api.item; +import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.cloudburstmc.api.block.BlockState; import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.data.DataKey; @@ -11,6 +12,7 @@ import org.cloudburstmc.api.entity.EntityType; import org.cloudburstmc.api.item.data.Bucket; import org.cloudburstmc.api.item.data.Record; +import org.cloudburstmc.api.item.data.WrittenBook; import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.data.DyeColor; import org.cloudburstmc.api.util.data.FireworkData; @@ -47,4 +49,6 @@ public final class ItemKeys { public static final SimpleDataKey> SPAWN_EGG_TYPE = DataKey.simple(Identifier.fromString("spawn_egg_type"), EntityType.class); public static final SimpleDataKey TREE_SPECIES = DataKey.simple(Identifier.fromString("tree_species"), TreeSpecies.class); + + public static final SimpleDataKey BOOK_DATA = DataKey.simple(Identifier.fromString("book_data"), WrittenBook.class); } From e6de19e4d6875533ac480cef43635dff996c0062 Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Tue, 3 May 2022 16:54:19 +0200 Subject: [PATCH 24/42] Added resistance behaviour, map item key and ItemStack comparables --- .../org/cloudburstmc/api/block/BlockBehaviors.java | 2 ++ .../java/org/cloudburstmc/api/item/ItemKeys.java | 3 +++ .../java/org/cloudburstmc/api/item/ItemStack.java | 12 ++++++++++++ 3 files changed, 17 insertions(+) diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index 569b557..6688125 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -136,6 +136,8 @@ private BlockBehaviors() { 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); diff --git a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java index 9e6ff59..44a88cc 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java @@ -11,6 +11,7 @@ import org.cloudburstmc.api.enchantment.EnchantmentType; import org.cloudburstmc.api.entity.EntityType; import org.cloudburstmc.api.item.data.Bucket; +import org.cloudburstmc.api.item.data.MapItem; import org.cloudburstmc.api.item.data.Record; import org.cloudburstmc.api.item.data.WrittenBook; import org.cloudburstmc.api.util.Identifier; @@ -51,4 +52,6 @@ public final class ItemKeys { public static final SimpleDataKey TREE_SPECIES = DataKey.simple(Identifier.fromString("tree_species"), TreeSpecies.class); public static final SimpleDataKey BOOK_DATA = DataKey.simple(Identifier.fromString("book_data"), WrittenBook.class); + + public static final SimpleDataKey MAP_DATA = DataKey.simple(Identifier.fromString("map_data"), MapItem.class); } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStack.java b/src/main/java/org/cloudburstmc/api/item/ItemStack.java index 1d13cd1..c4ef391 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStack.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStack.java @@ -136,4 +136,16 @@ public int compareTo(ItemStack other) { } return this.getType().getId().compareTo(other.getType().getId()); } + + public boolean isSimilar(ItemStack other) { + return this.getType().equals(other.getType()); + } + + public boolean isSimilarMetadata(ItemStack other) { + return getAllMetadata().equals(other.getAllMetadata()); + } + + public boolean isMergeable(ItemStack other) { + return isSimilar(other) && isSimilarMetadata(other); + } } From 650184591d83ce42296811009c8159a0f1ff2aee Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Wed, 4 May 2022 15:26:27 +0200 Subject: [PATCH 25/42] Added attack damage behaviour --- src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java | 4 ++++ .../org/cloudburstmc/api/util/behavior/FloatBehavior.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java index 5914b5e..80f6856 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java @@ -6,6 +6,7 @@ import org.cloudburstmc.api.data.DataKey; import org.cloudburstmc.api.item.behavior.*; import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.api.util.behavior.FloatBehavior; import org.cloudburstmc.api.util.behavior.IntBehavior; @UtilityClass @@ -32,4 +33,7 @@ public class ItemBehaviors { public static final BehaviorKey USE_ON = DataKey.behavior(Identifier.fromString("use_on"), UseOnBehavior.class, UseOnBehavior.Executor.class); public static final BehaviorKey GET_FUEL_DURATION = DataKey.behavior(Identifier.fromString("get_fuel_duration"), Float.class); + + public static final BehaviorKey GET_ATTACH_DAMAGE = DataKey.behavior(Identifier.fromString("get_attack_damage"), FloatBehavior.class, FloatBehavior.Executor.class); + } diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/FloatBehavior.java b/src/main/java/org/cloudburstmc/api/util/behavior/FloatBehavior.java index 781bf13..29c4671 100644 --- a/src/main/java/org/cloudburstmc/api/util/behavior/FloatBehavior.java +++ b/src/main/java/org/cloudburstmc/api/util/behavior/FloatBehavior.java @@ -2,7 +2,7 @@ public interface FloatBehavior { - float getProperty(Behavior behavior); + float get(Behavior behavior); @FunctionalInterface interface Executor { From 8eac70134a5b738da50229fc3b638b7ac0735da2 Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Thu, 5 May 2022 23:23:30 +0200 Subject: [PATCH 26/42] Added some more behaviours --- .../cloudburstmc/api/block/BlockBehaviors.java | 4 ++++ .../block/behavior/CanBreakBlockBehavior.java | 16 ++++++++++++++++ .../org/cloudburstmc/api/item/ItemBehaviors.java | 2 ++ .../api/item/behavior/BooleanItemBehavior.java | 15 +++++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/CanBreakBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/item/behavior/BooleanItemBehavior.java diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index 6688125..605dec6 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -146,4 +146,8 @@ private BlockBehaviors() { 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"), BooleanBlockBehavior.class, BooleanBlockBehavior.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/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/item/ItemBehaviors.java b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java index 80f6856..36f5c2a 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java @@ -36,4 +36,6 @@ public class ItemBehaviors { public static final BehaviorKey GET_ATTACH_DAMAGE = DataKey.behavior(Identifier.fromString("get_attack_damage"), FloatBehavior.class, FloatBehavior.Executor.class); + public static final BehaviorKey IS_TOOL = DataKey.behavior(Identifier.fromString("is_tool"), BooleanItemBehavior.class, BooleanItemBehavior.Executor.class); + } diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/BooleanItemBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/BooleanItemBehavior.java new file mode 100644 index 0000000..f4739f6 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/behavior/BooleanItemBehavior.java @@ -0,0 +1,15 @@ +package org.cloudburstmc.api.item.behavior; + +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface BooleanItemBehavior { + + boolean get(Behavior behavior, ItemStack itemStack); + + @FunctionalInterface + interface Executor { + + boolean execute(ItemStack itemStack); + } +} From 2d06fea88eae36e7fdc62811966b8f80062d494a Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Sat, 7 May 2022 21:42:43 +0200 Subject: [PATCH 27/42] Updating lombok dependency --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f73e22f..288048a 100644 --- a/pom.xml +++ b/pom.xml @@ -42,7 +42,7 @@ org.projectlombok lombok - 1.18.22 + 1.18.24 provided @@ -144,7 +144,7 @@ org.projectlombok lombok - 1.18.22 + 1.18.24 From 66083c47250172d94d3611d38a2c42e2e42cf072 Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Fri, 13 May 2022 20:11:56 +0200 Subject: [PATCH 28/42] Replaced lombok non-null check with Google's one --- src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java b/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java index 87ae528..d83e0bf 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java @@ -15,7 +15,7 @@ import java.util.Map; import static com.google.common.base.Preconditions.checkArgument; -import static lombok.Lombok.checkNotNull; +import static com.google.common.base.Preconditions.checkNotNull; import static org.cloudburstmc.api.item.ItemKeys.BLOCK_STATE; public final class ItemStackBuilder { From 23c2c075ca28f565edc0c87ca2f3b7542f410cfa Mon Sep 17 00:00:00 2001 From: Niek Vincent Date: Fri, 13 May 2022 20:57:32 +0200 Subject: [PATCH 29/42] Added a default blockstate to blocks that don't have one provided --- src/main/java/org/cloudburstmc/api/item/ItemStack.java | 2 +- .../java/org/cloudburstmc/api/item/ItemStackBuilder.java | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStack.java b/src/main/java/org/cloudburstmc/api/item/ItemStack.java index c4ef391..5e6f758 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStack.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStack.java @@ -18,7 +18,7 @@ public final class ItemStack implements DataStore, Comparable { - public static final ItemStack AIR = new ItemStack(BlockTypes.AIR, 0, Collections.emptyMap()); + public static final ItemStack AIR = ItemStack.builder(BlockTypes.AIR).build(); private final ItemType type; private final int count; diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java b/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java index d83e0bf..4683823 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStackBuilder.java @@ -57,8 +57,11 @@ public ItemStackBuilder data(DataKey key, M value) { public ItemStack build() { checkNotNull(this.itemType, "itemType is null"); checkArgument(this.amount > 0, "amount cannot be less than zero"); - checkArgument(!(this.itemType instanceof BlockType) || this.metadata.containsKey(BLOCK_STATE), - "ItemStack with a BlockType requires BlockState data"); + if((this.itemType instanceof BlockType) && !this.metadata.containsKey(BLOCK_STATE)) { + this.metadata.put(BLOCK_STATE, ((BlockType) this.itemType).getDefaultState()); + } +// checkArgument(!(this.itemType instanceof BlockType) || this.metadata.containsKey(BLOCK_STATE), +// "ItemStack with a BlockType requires BlockState data"); return new ItemStack(itemType, amount, metadata); } } From ead2197c8eaa95c66811fed5b41715aa546565ea Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Fri, 13 May 2022 22:29:27 +0100 Subject: [PATCH 30/42] Use isInstance for behaviour checks --- .../org/cloudburstmc/api/util/behavior/BehaviorBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorBuilder.java b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorBuilder.java index 431b9aa..9f509e6 100644 --- a/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorBuilder.java +++ b/src/main/java/org/cloudburstmc/api/util/behavior/BehaviorBuilder.java @@ -43,7 +43,7 @@ public BehaviorBuilder extend(BehaviorKey key, T function) { public BehaviorBuilder overwrite(BehaviorKey key, T function) { checkNotNull(key, "key"); checkNotNull(function, "function"); - checkArgument(key.getType() == function.getClass(), "%s does not match expected type of %s for '%s'", + checkArgument(key.getType().isInstance(function), "%s does not match expected type of %s for '%s'", function.getClass(), key.getType(), key.getId()); List functions = this.behaviors.computeIfAbsent(key, behaviorKey -> new ArrayList<>()); From 3d75bc46bfcc519e770af59f78de8d039e9d29df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedn=C3=A1=C5=99?= Date: Mon, 13 Jun 2022 18:51:09 +0900 Subject: [PATCH 31/42] Refactor block placing --- .../api/block/BlockBehaviors.java | 10 ++++-- .../behavior/BooleanBlockStateBehavior.java | 14 ++++++++ .../block/behavior/PlaceBlockBehavior.java | 32 +++++++++++++++++++ .../cloudburstmc/api/item/ItemBehaviors.java | 10 ++++++ .../item/behavior/CanBePlacedOnBehavior.java | 16 ++++++++++ .../api/item/behavior/GetItemBehavior.java | 15 +++++++++ .../api/item/behavior/UseOnBehavior.java | 4 +-- 7 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/BooleanBlockStateBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/item/behavior/CanBePlacedOnBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/item/behavior/GetItemBehavior.java diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index 605dec6..ae0e5f3 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -26,6 +26,8 @@ private BlockBehaviors() { 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); @@ -64,7 +66,7 @@ private BlockBehaviors() { 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"), 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); @@ -78,7 +80,7 @@ private BlockBehaviors() { 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, BooleanBlockBehavior.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); @@ -100,6 +102,8 @@ private BlockBehaviors() { 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); @@ -146,7 +150,7 @@ private BlockBehaviors() { 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"), BooleanBlockBehavior.class, BooleanBlockBehavior.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/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/PlaceBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java new file mode 100644 index 0000000..db94741 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java @@ -0,0 +1,32 @@ +package org.cloudburstmc.api.block.behavior; + +import com.nukkitx.math.vector.Vector3f; +import com.nukkitx.math.vector.Vector3i; +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; + +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/item/ItemBehaviors.java b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java index 36f5c2a..a0f801a 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java @@ -1,6 +1,7 @@ package org.cloudburstmc.api.item; import lombok.experimental.UtilityClass; +import org.cloudburstmc.api.block.BlockState; import org.cloudburstmc.api.block.behavior.BooleanBlockBehavior; import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.data.DataKey; @@ -9,6 +10,8 @@ import org.cloudburstmc.api.util.behavior.FloatBehavior; import org.cloudburstmc.api.util.behavior.IntBehavior; +import java.util.Optional; + @UtilityClass public class ItemBehaviors { @@ -30,6 +33,7 @@ public class ItemBehaviors { public static final BehaviorKey GET_DAMAGE_CHANCE = DataKey.behavior(Identifier.fromString("get_damage_chance"), DamageChanceBehavior.class, DamageChanceBehavior.Executor.class); + public static final BehaviorKey CAN_BE_USED = DataKey.behavior(Identifier.fromString("can_be_used"), BooleanItemBehavior.class, BooleanItemBehavior.Executor.class); public static final BehaviorKey USE_ON = DataKey.behavior(Identifier.fromString("use_on"), UseOnBehavior.class, UseOnBehavior.Executor.class); public static final BehaviorKey GET_FUEL_DURATION = DataKey.behavior(Identifier.fromString("get_fuel_duration"), Float.class); @@ -38,4 +42,10 @@ public class ItemBehaviors { public static final BehaviorKey IS_TOOL = DataKey.behavior(Identifier.fromString("is_tool"), BooleanItemBehavior.class, BooleanItemBehavior.Executor.class); + public static final BehaviorKey CAN_BE_PLACED = DataKey.behavior(Identifier.fromString("can_be_placed"), BooleanItemBehavior.class, BooleanItemBehavior.Executor.class); + + public static final BehaviorKey CAN_BE_PLACED_ON = DataKey.behavior(Identifier.fromString("can_be_placed_on"), CanBePlacedOnBehavior.class, CanBePlacedOnBehavior.Executor.class); + + public static final BehaviorKey>, GetItemBehavior.Executor>> GET_BLOCK = DataKey.behavior(Identifier.fromString("get_block"), GetItemBehavior.class, GetItemBehavior.Executor.class); + } diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/CanBePlacedOnBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/CanBePlacedOnBehavior.java new file mode 100644 index 0000000..82f6289 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/behavior/CanBePlacedOnBehavior.java @@ -0,0 +1,16 @@ +package org.cloudburstmc.api.item.behavior; + +import org.cloudburstmc.api.block.Block; +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface CanBePlacedOnBehavior { + + boolean get(Behavior behavior, ItemStack item, Block block); + + @FunctionalInterface + interface Executor { + + boolean execute(ItemStack itemStack, Block block); + } +} diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/GetItemBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/GetItemBehavior.java new file mode 100644 index 0000000..8f757de --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/item/behavior/GetItemBehavior.java @@ -0,0 +1,15 @@ +package org.cloudburstmc.api.item.behavior; + +import org.cloudburstmc.api.item.ItemStack; +import org.cloudburstmc.api.util.behavior.Behavior; + +public interface GetItemBehavior { + + T get(Behavior> behavior, ItemStack item); + + @FunctionalInterface + interface Executor { + + T execute(ItemStack itemStack); + } +} diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java index f09173f..e72f240 100644 --- a/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java +++ b/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java @@ -9,11 +9,11 @@ public interface UseOnBehavior { - boolean useOn(Behavior behavior, ItemStack itemStack, Entity entity, Vector3i blockPosition, Direction face, Vector3f clickPosition); + ItemStack useOn(Behavior behavior, ItemStack itemStack, Entity entity, Vector3i blockPosition, Direction face, Vector3f clickPosition); @FunctionalInterface interface Executor { - boolean execute(ItemStack itemStack, Entity entity, Vector3i blockPosition, Direction face, Vector3f clickPosition); + ItemStack execute(ItemStack itemStack, Entity entity, Vector3i blockPosition, Direction face, Vector3f clickPosition); } } From 0932daef4e71e9b48d2098f8b7487b77d82b1f63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedn=C3=A1=C5=99?= Date: Wed, 15 Jun 2022 21:53:15 +0900 Subject: [PATCH 32/42] Fix compilation --- .../org/cloudburstmc/api/block/BlockBehaviors.java | 2 +- .../org/cloudburstmc/api/block/BlockStates.java | 1 - .../org/cloudburstmc/api/block/BlockTypes.java | 1 - .../api/block/behavior/GenericBlockBehavior.java | 14 ++++++++++++++ .../java/org/cloudburstmc/api/item/ItemTypes.java | 11 +++-------- .../cloudburstmc/api/util/data/TreeSpecies.java | 1 - 6 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/GenericBlockBehavior.java diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index ae0e5f3..aafbeaf 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -50,7 +50,7 @@ private BlockBehaviors() { // 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>, Optional>> GET_BLOCK_ENTITY = DataKey.behavior(Identifier.fromString("get_block_entity"), Optional.class, Optional.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); 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/BlockTypes.java b/src/main/java/org/cloudburstmc/api/block/BlockTypes.java index 26c2c7c..4c0f4eb 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); 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/item/ItemTypes.java b/src/main/java/org/cloudburstmc/api/item/ItemTypes.java index 89dec36..eaf396e 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemTypes.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemTypes.java @@ -2,11 +2,6 @@ import lombok.experimental.UtilityClass; import org.cloudburstmc.api.util.Identifiers; -import org.cloudburstmc.api.util.data.DyeColor; -import org.cloudburstmc.api.util.data.TreeSpecies; - -import java.util.IdentityHashMap; -import java.util.Map; @UtilityClass public class ItemTypes { @@ -257,7 +252,7 @@ public class ItemTypes { public static final ItemType LAPIS_LAZULI = ItemType.of(ItemIds.LAPIS_LAZULI); - public static final ItemType DISC_FRAGMENT_5 = IntItem.builder().id(ItemIds.DISC_FRAGMENT_5).build(); - public static final ItemType RECOVERY_COMPASS = IntItem.builder().id(ItemIds.RECOVERY_COMPASS).build(); - public static final ItemType ECHO_CHARD = IntItem.builder().id(ItemIds.ECHO_CHARD).build(); + public static final ItemType DISC_FRAGMENT_5 = ItemType.of(ItemIds.DISC_FRAGMENT_5); + public static final ItemType RECOVERY_COMPASS = ItemType.of(ItemIds.RECOVERY_COMPASS); + public static final ItemType ECHO_CHARD = ItemType.of(ItemIds.ECHO_CHARD); } diff --git a/src/main/java/org/cloudburstmc/api/util/data/TreeSpecies.java b/src/main/java/org/cloudburstmc/api/util/data/TreeSpecies.java index aee27b5..2a686a7 100644 --- a/src/main/java/org/cloudburstmc/api/util/data/TreeSpecies.java +++ b/src/main/java/org/cloudburstmc/api/util/data/TreeSpecies.java @@ -9,6 +9,5 @@ public enum TreeSpecies { DARK_OAK, CRIMSON, WARPED, - MANGROVE, } From 5fa59a962488fbcfd9181672a825a6e6bbff4c1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedn=C3=A1=C5=99?= Date: Sat, 9 Jul 2022 11:57:47 +0200 Subject: [PATCH 33/42] Fix item serialization --- src/main/java/org/cloudburstmc/api/item/ItemKeys.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java index 44a88cc..8eac561 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java @@ -1,6 +1,5 @@ package org.cloudburstmc.api.item; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.cloudburstmc.api.block.BlockState; import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.data.DataKey; @@ -10,10 +9,8 @@ import org.cloudburstmc.api.enchantment.Enchantment; import org.cloudburstmc.api.enchantment.EnchantmentType; import org.cloudburstmc.api.entity.EntityType; -import org.cloudburstmc.api.item.data.Bucket; -import org.cloudburstmc.api.item.data.MapItem; import org.cloudburstmc.api.item.data.Record; -import org.cloudburstmc.api.item.data.WrittenBook; +import org.cloudburstmc.api.item.data.*; import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.data.DyeColor; import org.cloudburstmc.api.util.data.FireworkData; @@ -50,8 +47,10 @@ public final class ItemKeys { public static final SimpleDataKey> SPAWN_EGG_TYPE = DataKey.simple(Identifier.fromString("spawn_egg_type"), EntityType.class); public static final SimpleDataKey TREE_SPECIES = DataKey.simple(Identifier.fromString("tree_species"), TreeSpecies.class); - + public static final SimpleDataKey BOOK_DATA = DataKey.simple(Identifier.fromString("book_data"), WrittenBook.class); public static final SimpleDataKey MAP_DATA = DataKey.simple(Identifier.fromString("map_data"), MapItem.class); + + public static final SimpleDataKey BANNER_DATA = DataKey.simple(Identifier.fromString("banner_data"), BannerData.class); } From ef9192e7796cd542f01f2a2c4d19c94f9a97a32a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bedn=C3=A1=C5=99?= Date: Sat, 9 Jul 2022 11:57:47 +0200 Subject: [PATCH 34/42] Fix item serialization --- src/main/java/org/cloudburstmc/api/item/ItemKeys.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java index 44a88cc..8eac561 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemKeys.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemKeys.java @@ -1,6 +1,5 @@ package org.cloudburstmc.api.item; -import com.fasterxml.jackson.annotation.JsonTypeInfo; import org.cloudburstmc.api.block.BlockState; import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.data.DataKey; @@ -10,10 +9,8 @@ import org.cloudburstmc.api.enchantment.Enchantment; import org.cloudburstmc.api.enchantment.EnchantmentType; import org.cloudburstmc.api.entity.EntityType; -import org.cloudburstmc.api.item.data.Bucket; -import org.cloudburstmc.api.item.data.MapItem; import org.cloudburstmc.api.item.data.Record; -import org.cloudburstmc.api.item.data.WrittenBook; +import org.cloudburstmc.api.item.data.*; import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.data.DyeColor; import org.cloudburstmc.api.util.data.FireworkData; @@ -50,8 +47,10 @@ public final class ItemKeys { public static final SimpleDataKey> SPAWN_EGG_TYPE = DataKey.simple(Identifier.fromString("spawn_egg_type"), EntityType.class); public static final SimpleDataKey TREE_SPECIES = DataKey.simple(Identifier.fromString("tree_species"), TreeSpecies.class); - + public static final SimpleDataKey BOOK_DATA = DataKey.simple(Identifier.fromString("book_data"), WrittenBook.class); public static final SimpleDataKey MAP_DATA = DataKey.simple(Identifier.fromString("map_data"), MapItem.class); + + public static final SimpleDataKey BANNER_DATA = DataKey.simple(Identifier.fromString("banner_data"), BannerData.class); } From 1c4f0707459e37abe3b4180a7720dbe61cd767d2 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Fri, 12 Aug 2022 19:56:34 +0100 Subject: [PATCH 35/42] Add default values for DataKeys --- src/main/java/org/cloudburstmc/api/data/DataKey.java | 4 ++++ src/main/java/org/cloudburstmc/api/data/ListDataKey.java | 5 +++++ src/main/java/org/cloudburstmc/api/data/MapDataKey.java | 5 +++++ src/main/java/org/cloudburstmc/api/item/ItemStack.java | 4 +++- 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/cloudburstmc/api/data/DataKey.java b/src/main/java/org/cloudburstmc/api/data/DataKey.java index c2c7453..57ab9a7 100644 --- a/src/main/java/org/cloudburstmc/api/data/DataKey.java +++ b/src/main/java/org/cloudburstmc/api/data/DataKey.java @@ -49,4 +49,8 @@ static BehaviorKey behavior(Identifier id, Class functio Function getImmutableFunction(); Function getMutableFunction(); + + default T getDefaultValue() { + return null; + } } diff --git a/src/main/java/org/cloudburstmc/api/data/ListDataKey.java b/src/main/java/org/cloudburstmc/api/data/ListDataKey.java index 64dbbc0..e53e409 100644 --- a/src/main/java/org/cloudburstmc/api/data/ListDataKey.java +++ b/src/main/java/org/cloudburstmc/api/data/ListDataKey.java @@ -42,4 +42,9 @@ public Function, List> getImmutableFunction() { 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 index 59ad463..9d6e78b 100644 --- a/src/main/java/org/cloudburstmc/api/data/MapDataKey.java +++ b/src/main/java/org/cloudburstmc/api/data/MapDataKey.java @@ -44,4 +44,9 @@ public Function, Map> getImmutableFunction() { public Function, Map> getMutableFunction() { return HashMap::new; } + + @Override + public Map getDefaultValue() { + return ImmutableMap.of(); + } } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStack.java b/src/main/java/org/cloudburstmc/api/item/ItemStack.java index 5e6f758..90dce3f 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStack.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStack.java @@ -105,7 +105,9 @@ public ItemStack withCount(int amount) { @SuppressWarnings("unchecked") @Override public T get(DataKey key) { - return (T) metadata.get(key); + checkNotNull(key, "key"); + Object data = metadata.get(key); + return data == null ? key.getDefaultValue() : (T) data; } public Optional getBlockState() { From 9a99e9ff1cfc2a3f76f03fbcffff7a64af808611 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sun, 14 Aug 2022 18:00:42 +0100 Subject: [PATCH 36/42] Separate behaviour registration into contextual and not --- .../org/cloudburstmc/api/registry/BehaviorRegistry.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java index 7baf2f0..329d0d6 100644 --- a/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/BehaviorRegistry.java @@ -1,14 +1,13 @@ package org.cloudburstmc.api.registry; import org.cloudburstmc.api.data.BehaviorKey; -import org.cloudburstmc.api.util.behavior.Behavior; import org.cloudburstmc.api.util.behavior.BehaviorCollection; -import java.util.function.BiFunction; - public interface BehaviorRegistry { - void registerBehavior(BehaviorKey key, F defaultBehavior, BiFunction, F, E> executorFactory); + void registerBehavior(BehaviorKey key, F defaultBehavior); + + void registerContextBehavior(BehaviorKey key, F defaultBehavior); F getDefaultBehavior(BehaviorKey key); From 95e5931baeca6245907629db45c2258150acb269 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 20 Aug 2022 14:53:01 +0100 Subject: [PATCH 37/42] Add more behaviours --- .../block/behavior/PlaceBlockBehavior.java | 19 ++++--------------- .../cloudburstmc/api/data/BehaviorKey.java | 5 +++++ .../cloudburstmc/api/item/ItemBehaviors.java | 11 ++++++++++- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java index db94741..5ddea7a 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java @@ -9,24 +9,13 @@ public interface PlaceBlockBehavior { - boolean execute( - Behavior behavior, - BlockState blockState, - Player player, - Vector3i blockPosition, - Direction face, - Vector3f clickPosition - ); + 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 - ); + boolean execute(BlockState blockState, Player player, Vector3i blockPosition, Direction face, + Vector3f clickPosition); } } diff --git a/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java b/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java index 8cac605..d5e5851 100644 --- a/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java +++ b/src/main/java/org/cloudburstmc/api/data/BehaviorKey.java @@ -44,4 +44,9 @@ public Function getImmutableFunction() { public Function getMutableFunction() { throw new UnsupportedOperationException(); } + + @Override + public String toString() { + return id.toString(); + } } diff --git a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java index a0f801a..7b97830 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemBehaviors.java @@ -17,7 +17,8 @@ public class ItemBehaviors { public static final BehaviorKey GET_MAX_STACK_SIZE = DataKey.behavior(Identifier.fromString("get_max_stack_size"), IntBehavior.class, IntBehavior.Executor.class); - public static final BehaviorKey GET_MAX_DURABILITY = DataKey.behavior(Identifier.fromString("get_max_durability"), IntBehavior.class, IntBehavior.Executor.class); + public static final BehaviorKey IS_DAMAGEABLE = DataKey.behavior(Identifier.fromString("is_damageable"), Boolean.class); + public static final BehaviorKey GET_MAX_DAMAGE = DataKey.behavior(Identifier.fromString("get_max_damage"), IntBehavior.class, IntBehavior.Executor.class); public static final BehaviorKey MINE_BLOCK = DataKey.behavior(Identifier.fromString("mine_block"), MineBlockBehavior.class, MineBlockBehavior.Executor.class); @@ -48,4 +49,12 @@ public class ItemBehaviors { public static final BehaviorKey>, GetItemBehavior.Executor>> GET_BLOCK = DataKey.behavior(Identifier.fromString("get_block"), GetItemBehavior.class, GetItemBehavior.Executor.class); + public static final BehaviorKey ALLOW_OFFHAND = DataKey.behavior(Identifier.fromString("allow_offhand"), Boolean.class); + + public static final BehaviorKey CAN_BE_CHARGED = DataKey.behavior(Identifier.fromString("can_be_charged"), Boolean.class); + + public static final BehaviorKey CAN_BE_DEPLETED = DataKey.behavior(Identifier.fromString("can_be_depleted"), Boolean.class); + + public static final BehaviorKey GET_ATTACK_DAMAGE = DataKey.behavior(Identifier.fromString("get_attack_damage"), Integer.class); + } From cdc4112c6855a1fd7a2e6bbb4e73619188863e82 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 20 Aug 2022 18:54:16 +0100 Subject: [PATCH 38/42] Modularise block breaking --- .../cloudburstmc/api/block/BlockBehaviors.java | 10 ++++++++-- .../behavior/DropResourceBlockBehavior.java | 17 +++++++++++++++++ .../behavior/SpawnResourcesBlockBehavior.java | 18 ++++++++++++++++++ .../org/cloudburstmc/api/util/Randoms.java | 9 +++++++++ 4 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/DropResourceBlockBehavior.java create mode 100644 src/main/java/org/cloudburstmc/api/block/behavior/SpawnResourcesBlockBehavior.java diff --git a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java index aafbeaf..6dd2e3a 100644 --- a/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java +++ b/src/main/java/org/cloudburstmc/api/block/BlockBehaviors.java @@ -58,7 +58,9 @@ private BlockBehaviors() { 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"), EntityBlockBehavior.class, EntityBlockBehavior.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); @@ -92,7 +94,11 @@ private BlockBehaviors() { 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 GET_RESOURCE_ITEM = DataKey.behavior(Identifier.fromString("get_resource_item"), 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); 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/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/util/Randoms.java b/src/main/java/org/cloudburstmc/api/util/Randoms.java index 5180580..00e184a 100644 --- a/src/main/java/org/cloudburstmc/api/util/Randoms.java +++ b/src/main/java/org/cloudburstmc/api/util/Randoms.java @@ -1,5 +1,7 @@ package org.cloudburstmc.api.util; +import com.nukkitx.math.GenericMath; + import java.util.random.RandomGenerator; public final class Randoms { @@ -19,4 +21,11 @@ public static boolean chance(RandomGenerator random, int likeliness, int possibi public static boolean chanceInOne(RandomGenerator random, int possibilities) { return chance(random, 1, possibilities); } + + private static final float MIN_EXCESSIVE_IMPROBABILITY = Math.nextAfter(1f, 0f); + + public static boolean chanceFloatGreaterThan(RandomGenerator random, float improbability) { + return improbability < MIN_EXCESSIVE_IMPROBABILITY && + (improbability <= -GenericMath.FLT_EPSILON || improbability < random.nextFloat()); + } } From 0b4d88276fdfdeb6625c6fabcd790e327dd77202 Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 26 Nov 2022 19:46:35 +0000 Subject: [PATCH 39/42] Use math 2.0 library --- pom.xml | 6 +++--- src/main/java/module-info.java | 2 +- src/main/java/org/cloudburstmc/api/block/Block.java | 4 ++-- .../api/block/behavior/PlaceBlockBehavior.java | 4 ++-- .../org/cloudburstmc/api/blockentity/BlockEntity.java | 2 +- .../cloudburstmc/api/blockentity/BlockEntityFactory.java | 2 +- src/main/java/org/cloudburstmc/api/entity/Entity.java | 4 ++-- .../cloudburstmc/api/event/entity/EntityExplodeEvent.java | 2 +- .../cloudburstmc/api/event/entity/EntityMotionEvent.java | 2 +- .../cloudburstmc/api/event/level/SpawnChangeEvent.java | 2 +- .../api/event/player/PlayerInteractEntityEvent.java | 2 +- .../api/event/player/PlayerInteractEvent.java | 2 +- .../org/cloudburstmc/api/item/behavior/ItemBehavior.java | 4 +--- .../org/cloudburstmc/api/item/behavior/UseOnBehavior.java | 4 ++-- src/main/java/org/cloudburstmc/api/level/ChunkLoader.java | 2 +- .../java/org/cloudburstmc/api/level/ChunkManager.java | 8 ++++---- src/main/java/org/cloudburstmc/api/level/Level.java | 4 ++-- src/main/java/org/cloudburstmc/api/level/Location.java | 4 ++-- src/main/java/org/cloudburstmc/api/player/Player.java | 2 +- src/main/java/org/cloudburstmc/api/potion/Effect.java | 2 +- src/main/java/org/cloudburstmc/api/potion/EffectType.java | 2 +- .../java/org/cloudburstmc/api/potion/EffectTypes.java | 2 +- .../java/org/cloudburstmc/api/util/AxisAlignedBB.java | 6 +++--- src/main/java/org/cloudburstmc/api/util/Direction.java | 4 ++-- .../org/cloudburstmc/api/util/MovingObjectPosition.java | 4 ++-- src/main/java/org/cloudburstmc/api/util/Randoms.java | 2 +- .../org/cloudburstmc/api/util/SimpleAxisAlignedBB.java | 4 ++-- 27 files changed, 43 insertions(+), 45 deletions(-) diff --git a/pom.xml b/pom.xml index 288048a..a4e9bd1 100644 --- a/pom.xml +++ b/pom.xml @@ -113,9 +113,9 @@ - com.nukkitx - math - 1.1.1 + org.cloudburstmc.math + immutable + 2.0 diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 2fe44b5..71f2d03 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; diff --git a/src/main/java/org/cloudburstmc/api/block/Block.java b/src/main/java/org/cloudburstmc/api/block/Block.java index a44206f..dd9894f 100644 --- a/src/main/java/org/cloudburstmc/api/block/Block.java +++ b/src/main/java/org/cloudburstmc/api/block/Block.java @@ -1,11 +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 { diff --git a/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java b/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java index 5ddea7a..9e90d0e 100644 --- a/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java +++ b/src/main/java/org/cloudburstmc/api/block/behavior/PlaceBlockBehavior.java @@ -1,11 +1,11 @@ package org.cloudburstmc.api.block.behavior; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; 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 { 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/entity/Entity.java b/src/main/java/org/cloudburstmc/api/entity/Entity.java index 94c3b3f..0d52d72 100644 --- a/src/main/java/org/cloudburstmc/api/entity/Entity.java +++ b/src/main/java/org/cloudburstmc/api/entity/Entity.java @@ -1,7 +1,5 @@ package org.cloudburstmc.api.entity; -import com.nukkitx.math.vector.Vector2f; -import com.nukkitx.math.vector.Vector3f; import org.checkerframework.checker.index.qual.NonNegative; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.Server; @@ -20,6 +18,8 @@ import org.cloudburstmc.api.util.AxisAlignedBB; import org.cloudburstmc.api.util.Direction; import org.cloudburstmc.api.util.data.MountType; +import org.cloudburstmc.math.vector.Vector2f; +import org.cloudburstmc.math.vector.Vector3f; import java.util.List; import java.util.Map; diff --git a/src/main/java/org/cloudburstmc/api/event/entity/EntityExplodeEvent.java b/src/main/java/org/cloudburstmc/api/event/entity/EntityExplodeEvent.java index b4d959c..555e36b 100644 --- a/src/main/java/org/cloudburstmc/api/event/entity/EntityExplodeEvent.java +++ b/src/main/java/org/cloudburstmc/api/event/entity/EntityExplodeEvent.java @@ -1,9 +1,9 @@ package org.cloudburstmc.api.event.entity; -import com.nukkitx.math.vector.Vector3f; import org.cloudburstmc.api.block.Block; import org.cloudburstmc.api.entity.Entity; import org.cloudburstmc.api.event.Cancellable; +import org.cloudburstmc.math.vector.Vector3f; import java.util.List; diff --git a/src/main/java/org/cloudburstmc/api/event/entity/EntityMotionEvent.java b/src/main/java/org/cloudburstmc/api/event/entity/EntityMotionEvent.java index 1fd4a0f..0c91109 100644 --- a/src/main/java/org/cloudburstmc/api/event/entity/EntityMotionEvent.java +++ b/src/main/java/org/cloudburstmc/api/event/entity/EntityMotionEvent.java @@ -1,8 +1,8 @@ package org.cloudburstmc.api.event.entity; -import com.nukkitx.math.vector.Vector3f; import org.cloudburstmc.api.entity.Entity; import org.cloudburstmc.api.event.Cancellable; +import org.cloudburstmc.math.vector.Vector3f; /** * author: MagicDroidX diff --git a/src/main/java/org/cloudburstmc/api/event/level/SpawnChangeEvent.java b/src/main/java/org/cloudburstmc/api/event/level/SpawnChangeEvent.java index 0a188c4..3f17137 100644 --- a/src/main/java/org/cloudburstmc/api/event/level/SpawnChangeEvent.java +++ b/src/main/java/org/cloudburstmc/api/event/level/SpawnChangeEvent.java @@ -1,7 +1,7 @@ package org.cloudburstmc.api.event.level; -import com.nukkitx.math.vector.Vector3f; import org.cloudburstmc.api.level.Level; +import org.cloudburstmc.math.vector.Vector3f; /** * author: MagicDroidX diff --git a/src/main/java/org/cloudburstmc/api/event/player/PlayerInteractEntityEvent.java b/src/main/java/org/cloudburstmc/api/event/player/PlayerInteractEntityEvent.java index 6b9ad8c..6de31ed 100644 --- a/src/main/java/org/cloudburstmc/api/event/player/PlayerInteractEntityEvent.java +++ b/src/main/java/org/cloudburstmc/api/event/player/PlayerInteractEntityEvent.java @@ -1,10 +1,10 @@ package org.cloudburstmc.api.event.player; -import com.nukkitx.math.vector.Vector3f; import org.cloudburstmc.api.entity.Entity; import org.cloudburstmc.api.event.Cancellable; import org.cloudburstmc.api.item.ItemStack; import org.cloudburstmc.api.player.Player; +import org.cloudburstmc.math.vector.Vector3f; /** * Created by CreeperFace on 1. 1. 2017. diff --git a/src/main/java/org/cloudburstmc/api/event/player/PlayerInteractEvent.java b/src/main/java/org/cloudburstmc/api/event/player/PlayerInteractEvent.java index d492782..bd50315 100644 --- a/src/main/java/org/cloudburstmc/api/event/player/PlayerInteractEvent.java +++ b/src/main/java/org/cloudburstmc/api/event/player/PlayerInteractEvent.java @@ -1,11 +1,11 @@ package org.cloudburstmc.api.event.player; -import com.nukkitx.math.vector.Vector3f; import org.cloudburstmc.api.block.Block; import org.cloudburstmc.api.event.Cancellable; import org.cloudburstmc.api.item.ItemStack; import org.cloudburstmc.api.player.Player; import org.cloudburstmc.api.util.Direction; +import org.cloudburstmc.math.vector.Vector3f; /** diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/ItemBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/ItemBehavior.java index 10fb3a9..57e37fa 100644 --- a/src/main/java/org/cloudburstmc/api/item/behavior/ItemBehavior.java +++ b/src/main/java/org/cloudburstmc/api/item/behavior/ItemBehavior.java @@ -1,10 +1,7 @@ package org.cloudburstmc.api.item.behavior; -import com.nukkitx.math.vector.Vector3f; -import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.block.Block; import org.cloudburstmc.api.block.BlockState; -import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.entity.Entity; import org.cloudburstmc.api.item.ItemStack; import org.cloudburstmc.api.item.ItemType; @@ -14,6 +11,7 @@ import org.cloudburstmc.api.player.Player; import org.cloudburstmc.api.util.Direction; import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.math.vector.Vector3f; public interface ItemBehavior { boolean canBeActivated(); diff --git a/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java b/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java index e72f240..0c57790 100644 --- a/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java +++ b/src/main/java/org/cloudburstmc/api/item/behavior/UseOnBehavior.java @@ -1,11 +1,11 @@ package org.cloudburstmc.api.item.behavior; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; import org.cloudburstmc.api.entity.Entity; import org.cloudburstmc.api.item.ItemStack; 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 UseOnBehavior { diff --git a/src/main/java/org/cloudburstmc/api/level/ChunkLoader.java b/src/main/java/org/cloudburstmc/api/level/ChunkLoader.java index 1476e49..1a85e32 100644 --- a/src/main/java/org/cloudburstmc/api/level/ChunkLoader.java +++ b/src/main/java/org/cloudburstmc/api/level/ChunkLoader.java @@ -1,7 +1,7 @@ package org.cloudburstmc.api.level; -import com.nukkitx.math.vector.Vector3f; import org.cloudburstmc.api.level.chunk.Chunk; +import org.cloudburstmc.math.vector.Vector3f; /** * author: MagicDroidX diff --git a/src/main/java/org/cloudburstmc/api/level/ChunkManager.java b/src/main/java/org/cloudburstmc/api/level/ChunkManager.java index c0f4904..3333789 100644 --- a/src/main/java/org/cloudburstmc/api/level/ChunkManager.java +++ b/src/main/java/org/cloudburstmc/api/level/ChunkManager.java @@ -1,14 +1,14 @@ package org.cloudburstmc.api.level; -import com.nukkitx.math.vector.Vector2i; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; -import com.nukkitx.math.vector.Vector4i; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.block.Block; import org.cloudburstmc.api.block.BlockState; import org.cloudburstmc.api.level.chunk.Chunk; import org.cloudburstmc.api.player.Player; +import org.cloudburstmc.math.vector.Vector2i; +import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.math.vector.Vector3i; +import org.cloudburstmc.math.vector.Vector4i; import java.util.Set; import java.util.concurrent.CompletableFuture; diff --git a/src/main/java/org/cloudburstmc/api/level/Level.java b/src/main/java/org/cloudburstmc/api/level/Level.java index 3248f2f..91673b0 100644 --- a/src/main/java/org/cloudburstmc/api/level/Level.java +++ b/src/main/java/org/cloudburstmc/api/level/Level.java @@ -1,7 +1,5 @@ package org.cloudburstmc.api.level; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; import org.cloudburstmc.api.Server; import org.cloudburstmc.api.block.Block; import org.cloudburstmc.api.blockentity.BlockEntity; @@ -12,6 +10,8 @@ import org.cloudburstmc.api.player.Player; import org.cloudburstmc.api.util.AxisAlignedBB; import org.cloudburstmc.api.util.Direction; +import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.math.vector.Vector3i; import java.util.Map; import java.util.Set; diff --git a/src/main/java/org/cloudburstmc/api/level/Location.java b/src/main/java/org/cloudburstmc/api/level/Location.java index 5ed676d..7e23e80 100644 --- a/src/main/java/org/cloudburstmc/api/level/Location.java +++ b/src/main/java/org/cloudburstmc/api/level/Location.java @@ -1,10 +1,10 @@ package org.cloudburstmc.api.level; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; import lombok.EqualsAndHashCode; import org.cloudburstmc.api.block.BlockState; import org.cloudburstmc.api.level.chunk.Chunk; +import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.math.vector.Vector3i; import static com.google.common.base.Preconditions.checkNotNull; diff --git a/src/main/java/org/cloudburstmc/api/player/Player.java b/src/main/java/org/cloudburstmc/api/player/Player.java index 8101155..9ab86af 100644 --- a/src/main/java/org/cloudburstmc/api/player/Player.java +++ b/src/main/java/org/cloudburstmc/api/player/Player.java @@ -1,6 +1,5 @@ package org.cloudburstmc.api.player; -import com.nukkitx.math.vector.Vector3i; import org.cloudburstmc.api.Server; import org.cloudburstmc.api.blockentity.EnderChest; import org.cloudburstmc.api.crafting.CraftingGrid; @@ -13,6 +12,7 @@ import org.cloudburstmc.api.level.Location; import org.cloudburstmc.api.player.skin.Skin; import org.cloudburstmc.api.util.data.CardinalDirection; +import org.cloudburstmc.math.vector.Vector3i; import java.util.OptionalLong; import java.util.UUID; diff --git a/src/main/java/org/cloudburstmc/api/potion/Effect.java b/src/main/java/org/cloudburstmc/api/potion/Effect.java index d6bbd38..535e665 100644 --- a/src/main/java/org/cloudburstmc/api/potion/Effect.java +++ b/src/main/java/org/cloudburstmc/api/potion/Effect.java @@ -1,10 +1,10 @@ package org.cloudburstmc.api.potion; -import com.nukkitx.math.vector.Vector3i; import lombok.Getter; import lombok.NonNull; import org.cloudburstmc.api.entity.Entity; import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.math.vector.Vector3i; @Getter public abstract class Effect { diff --git a/src/main/java/org/cloudburstmc/api/potion/EffectType.java b/src/main/java/org/cloudburstmc/api/potion/EffectType.java index 7faae12..e426eaa 100644 --- a/src/main/java/org/cloudburstmc/api/potion/EffectType.java +++ b/src/main/java/org/cloudburstmc/api/potion/EffectType.java @@ -1,9 +1,9 @@ package org.cloudburstmc.api.potion; -import com.nukkitx.math.vector.Vector3i; import lombok.Getter; import org.checkerframework.checker.nullness.qual.Nullable; import org.cloudburstmc.api.util.Identifier; +import org.cloudburstmc.math.vector.Vector3i; import java.util.HashMap; diff --git a/src/main/java/org/cloudburstmc/api/potion/EffectTypes.java b/src/main/java/org/cloudburstmc/api/potion/EffectTypes.java index 9d4d8ca..d82d039 100644 --- a/src/main/java/org/cloudburstmc/api/potion/EffectTypes.java +++ b/src/main/java/org/cloudburstmc/api/potion/EffectTypes.java @@ -1,8 +1,8 @@ package org.cloudburstmc.api.potion; -import com.nukkitx.math.vector.Vector3i; import lombok.experimental.UtilityClass; import org.cloudburstmc.api.util.Identifiers; +import org.cloudburstmc.math.vector.Vector3i; @UtilityClass public class EffectTypes { diff --git a/src/main/java/org/cloudburstmc/api/util/AxisAlignedBB.java b/src/main/java/org/cloudburstmc/api/util/AxisAlignedBB.java index ac38d8f..154fe06 100644 --- a/src/main/java/org/cloudburstmc/api/util/AxisAlignedBB.java +++ b/src/main/java/org/cloudburstmc/api/util/AxisAlignedBB.java @@ -1,8 +1,8 @@ package org.cloudburstmc.api.util; -import com.nukkitx.math.GenericMath; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; +import org.cloudburstmc.math.GenericMath; +import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.math.vector.Vector3i; public interface AxisAlignedBB extends Cloneable { diff --git a/src/main/java/org/cloudburstmc/api/util/Direction.java b/src/main/java/org/cloudburstmc/api/util/Direction.java index 2857d1e..8a3cb1d 100644 --- a/src/main/java/org/cloudburstmc/api/util/Direction.java +++ b/src/main/java/org/cloudburstmc/api/util/Direction.java @@ -1,10 +1,10 @@ package org.cloudburstmc.api.util; import com.google.common.collect.Iterators; -import com.nukkitx.math.GenericMath; -import com.nukkitx.math.vector.Vector3i; import lombok.RequiredArgsConstructor; import org.cloudburstmc.api.util.data.CardinalDirection; +import org.cloudburstmc.math.GenericMath; +import org.cloudburstmc.math.vector.Vector3i; import java.util.Iterator; import java.util.Random; diff --git a/src/main/java/org/cloudburstmc/api/util/MovingObjectPosition.java b/src/main/java/org/cloudburstmc/api/util/MovingObjectPosition.java index 1514b32..23b1cb9 100644 --- a/src/main/java/org/cloudburstmc/api/util/MovingObjectPosition.java +++ b/src/main/java/org/cloudburstmc/api/util/MovingObjectPosition.java @@ -1,8 +1,8 @@ package org.cloudburstmc.api.util; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; import org.cloudburstmc.api.entity.Entity; +import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.math.vector.Vector3i; /** * author: MagicDroidX diff --git a/src/main/java/org/cloudburstmc/api/util/Randoms.java b/src/main/java/org/cloudburstmc/api/util/Randoms.java index 00e184a..aabf04e 100644 --- a/src/main/java/org/cloudburstmc/api/util/Randoms.java +++ b/src/main/java/org/cloudburstmc/api/util/Randoms.java @@ -1,6 +1,6 @@ package org.cloudburstmc.api.util; -import com.nukkitx.math.GenericMath; +import org.cloudburstmc.math.GenericMath; import java.util.random.RandomGenerator; diff --git a/src/main/java/org/cloudburstmc/api/util/SimpleAxisAlignedBB.java b/src/main/java/org/cloudburstmc/api/util/SimpleAxisAlignedBB.java index bd52009..7936dfd 100644 --- a/src/main/java/org/cloudburstmc/api/util/SimpleAxisAlignedBB.java +++ b/src/main/java/org/cloudburstmc/api/util/SimpleAxisAlignedBB.java @@ -1,7 +1,7 @@ package org.cloudburstmc.api.util; -import com.nukkitx.math.vector.Vector3f; -import com.nukkitx.math.vector.Vector3i; +import org.cloudburstmc.math.vector.Vector3f; +import org.cloudburstmc.math.vector.Vector3i; /** * auth||: MagicDroidX From 131e8ccbff29916d3b7c17046a4ed4b9745762be Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 17 Dec 2022 15:31:01 +0000 Subject: [PATCH 40/42] Minor changes for protocol v3 --- .../java/org/cloudburstmc/api/entity/misc/AreaEffectCloud.java | 2 +- src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/org/cloudburstmc/api/entity/misc/AreaEffectCloud.java b/src/main/java/org/cloudburstmc/api/entity/misc/AreaEffectCloud.java index b4819d4..8bacfb9 100644 --- a/src/main/java/org/cloudburstmc/api/entity/misc/AreaEffectCloud.java +++ b/src/main/java/org/cloudburstmc/api/entity/misc/AreaEffectCloud.java @@ -36,7 +36,7 @@ public interface AreaEffectCloud extends Entity { long getSpawnTime(); - void setSpawnTime(long spawnTime); + void setSpawnTime(int spawnTime); int getDuration(); diff --git a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java index e2c2f65..44c6418 100644 --- a/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java +++ b/src/main/java/org/cloudburstmc/api/registry/BlockRegistry.java @@ -5,7 +5,6 @@ import org.cloudburstmc.api.block.BlockType; import org.cloudburstmc.api.data.BehaviorKey; import org.cloudburstmc.api.item.ItemStack; -import org.cloudburstmc.api.item.ItemType; import org.cloudburstmc.api.util.Identifier; import org.cloudburstmc.api.util.behavior.BehaviorCollection; From 6d8906673dafecedc24be48d626a1450688dd27e Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Wed, 21 Dec 2022 15:34:27 +0000 Subject: [PATCH 41/42] Rename ItemStack `AIR` to `EMPTY` --- src/main/java/org/cloudburstmc/api/item/ItemStack.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/cloudburstmc/api/item/ItemStack.java b/src/main/java/org/cloudburstmc/api/item/ItemStack.java index 90dce3f..5068043 100644 --- a/src/main/java/org/cloudburstmc/api/item/ItemStack.java +++ b/src/main/java/org/cloudburstmc/api/item/ItemStack.java @@ -18,7 +18,7 @@ public final class ItemStack implements DataStore, Comparable { - public static final ItemStack AIR = ItemStack.builder(BlockTypes.AIR).build(); + public static final ItemStack EMPTY = ItemStack.builder(BlockTypes.AIR).build(); private final ItemType type; private final int count; From 6b6b724f95f340911b33900b27e4b0767728871b Mon Sep 17 00:00:00 2001 From: SupremeMortal <6178101+SupremeMortal@users.noreply.github.com> Date: Sat, 15 Apr 2023 12:16:41 +0100 Subject: [PATCH 42/42] Inventory API changes --- src/main/java/module-info.java | 3 ++- .../api/inventory/InventoryType.java | 4 +++- .../api/inventory/WorkbenchInventory.java | 4 ++++ .../inventory/screen/HudInventoryScreen.java | 8 ++++++++ .../api/inventory/screen/InventoryScreen.java | 20 +++++++++++++++++++ .../screen/PlayerInventoryScreen.java | 13 ++++++++++++ .../api/inventory/view/InventoryView.java | 4 ++++ .../org/cloudburstmc/api/player/Player.java | 15 -------------- 8 files changed, 54 insertions(+), 17 deletions(-) create mode 100644 src/main/java/org/cloudburstmc/api/inventory/WorkbenchInventory.java create mode 100644 src/main/java/org/cloudburstmc/api/inventory/screen/HudInventoryScreen.java create mode 100644 src/main/java/org/cloudburstmc/api/inventory/screen/InventoryScreen.java create mode 100644 src/main/java/org/cloudburstmc/api/inventory/screen/PlayerInventoryScreen.java create mode 100644 src/main/java/org/cloudburstmc/api/inventory/view/InventoryView.java diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 71f2d03..d61f6b5 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -60,4 +60,5 @@ 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/inventory/InventoryType.java b/src/main/java/org/cloudburstmc/api/inventory/InventoryType.java index 1f0dba5..625afac 100644 --- a/src/main/java/org/cloudburstmc/api/inventory/InventoryType.java +++ b/src/main/java/org/cloudburstmc/api/inventory/InventoryType.java @@ -8,7 +8,9 @@ public enum InventoryType { CHEST(27, "Chest"), ENDER_CHEST(27, "Ender Chest"), DOUBLE_CHEST(27 + 27, "Double Chest"), - PLAYER(41, "Player"), //36 CONTAINER, 4 ARMOR, 1 OFFHAND + PLAYER(41, "Player"), //36 CONTAINER + ARMOR(4, "Armor"), + HAND(1, "Hand"), FURNACE(3, "Furnace"), CRAFTING(5, "Crafting"), //4 CRAFTING slots, 1 RESULT WORKBENCH(10, "Crafting"), //9 CRAFTING slots, 1 RESULT diff --git a/src/main/java/org/cloudburstmc/api/inventory/WorkbenchInventory.java b/src/main/java/org/cloudburstmc/api/inventory/WorkbenchInventory.java new file mode 100644 index 0000000..7db66e2 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/inventory/WorkbenchInventory.java @@ -0,0 +1,4 @@ +package org.cloudburstmc.api.inventory; + +public interface WorkbenchInventory extends Inventory { +} diff --git a/src/main/java/org/cloudburstmc/api/inventory/screen/HudInventoryScreen.java b/src/main/java/org/cloudburstmc/api/inventory/screen/HudInventoryScreen.java new file mode 100644 index 0000000..c877efc --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/inventory/screen/HudInventoryScreen.java @@ -0,0 +1,8 @@ +package org.cloudburstmc.api.inventory.screen; + +import org.cloudburstmc.api.inventory.PlayerInventory; + +public interface HudInventoryScreen extends InventoryScreen { + + PlayerInventory getPlayerInventory(); +} diff --git a/src/main/java/org/cloudburstmc/api/inventory/screen/InventoryScreen.java b/src/main/java/org/cloudburstmc/api/inventory/screen/InventoryScreen.java new file mode 100644 index 0000000..1848ded --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/inventory/screen/InventoryScreen.java @@ -0,0 +1,20 @@ +package org.cloudburstmc.api.inventory.screen; + +import org.cloudburstmc.api.inventory.Inventory; +import org.cloudburstmc.api.item.ItemStack; + +import java.util.Collection; + +public interface InventoryScreen { + + ItemStack getItem(int slot); + + void setItem(int slot, ItemStack item); + + /** + * Retrieves the backing inventories for this screen. + * + * @return the backing inventories + */ + Collection getInventories(); +} diff --git a/src/main/java/org/cloudburstmc/api/inventory/screen/PlayerInventoryScreen.java b/src/main/java/org/cloudburstmc/api/inventory/screen/PlayerInventoryScreen.java new file mode 100644 index 0000000..31ff008 --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/inventory/screen/PlayerInventoryScreen.java @@ -0,0 +1,13 @@ +package org.cloudburstmc.api.inventory.screen; + +import org.cloudburstmc.api.inventory.PlayerInventory; +import org.cloudburstmc.api.inventory.WorkbenchInventory; + +public interface PlayerInventoryScreen { + + PlayerInventory getPlayerInventory(); + + WorkbenchInventory getWorkbenchInventory(); + + +} diff --git a/src/main/java/org/cloudburstmc/api/inventory/view/InventoryView.java b/src/main/java/org/cloudburstmc/api/inventory/view/InventoryView.java new file mode 100644 index 0000000..50c953c --- /dev/null +++ b/src/main/java/org/cloudburstmc/api/inventory/view/InventoryView.java @@ -0,0 +1,4 @@ +package org.cloudburstmc.api.inventory.view; + +public interface InventoryView { +} diff --git a/src/main/java/org/cloudburstmc/api/player/Player.java b/src/main/java/org/cloudburstmc/api/player/Player.java index 9ab86af..bc5302f 100644 --- a/src/main/java/org/cloudburstmc/api/player/Player.java +++ b/src/main/java/org/cloudburstmc/api/player/Player.java @@ -5,7 +5,6 @@ import org.cloudburstmc.api.crafting.CraftingGrid; import org.cloudburstmc.api.entity.Creature; import org.cloudburstmc.api.inventory.ContainerInventory; -import org.cloudburstmc.api.inventory.Inventory; import org.cloudburstmc.api.inventory.InventoryHolder; import org.cloudburstmc.api.inventory.PlayerInventory; import org.cloudburstmc.api.level.Level; @@ -136,20 +135,6 @@ public interface Player extends Creature, InventoryHolder { GameMode getGamemode(); - byte getWindowId(Inventory inventory); - - default byte addWindow(Inventory window) { - return addWindow(window, null, false); - } - - default byte addWindow(Inventory window, Byte forceId) { - return addWindow(window, forceId, false); - } - - byte addWindow(Inventory window, Byte forceId, boolean isPermanent); - - void removeWindow(Inventory inventory); - String getDisplayName(); String getXuid();