9
0
mirror of https://github.com/Xiao-MoMi/craft-engine.git synced 2025-12-26 18:39:20 +00:00

Implement Strippable Block

This commit is contained in:
XiaoMoMi
2025-02-14 18:34:41 +08:00
parent 708595399b
commit 80ca2d18d9
22 changed files with 426 additions and 142 deletions

View File

@@ -97,7 +97,7 @@ public class ImmutableBlockState extends BlockStateHolder {
this.vanillaBlockState = vanillaBlockState;
}
private CompoundTag propertiesNbt() {
public CompoundTag propertiesNbt() {
CompoundTag properties = new CompoundTag();
for (Property<?> property : getProperties()) {
Comparable<?> value = get(property);

View File

@@ -5,11 +5,13 @@ import net.momirealms.craftengine.core.entity.Entity;
import net.momirealms.craftengine.core.item.Item;
import net.momirealms.craftengine.core.plugin.network.NetWorkUser;
import net.momirealms.craftengine.core.world.BlockPos;
import org.jetbrains.annotations.Nullable;
public abstract class Player extends Entity implements NetWorkUser {
public abstract boolean isSecondaryUseActive();
@Nullable
public abstract Item<?> getItemInHand(InteractionHand hand);
@Override

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.item;
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
import net.momirealms.craftengine.core.util.Key;
import java.util.List;
@@ -42,6 +43,21 @@ public class AbstractItem<W extends ItemWrapper<I>, I> implements Item<I> {
return ((ItemManager<I>) factory.plugin.itemManager()).getCustomItem(id());
}
@Override
public Optional<List<ItemBehavior>> getItemBehavior() {
return factory.plugin.itemManager().getItemBehavior(id());
}
@Override
public boolean isCustomItem() {
return factory.plugin.itemManager().getCustomItem(id()).isPresent();
}
@Override
public boolean isBlockItem() {
return factory.isBlockItem(item);
}
@Override
public Key id() {
return this.factory.id(this.item);

View File

@@ -4,6 +4,7 @@ import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
import net.momirealms.craftengine.core.item.modifier.ItemModifier;
import net.momirealms.craftengine.core.util.Key;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -23,6 +24,7 @@ public interface CustomItem<I> extends BuildableItem<I> {
Item<I> buildItem(Player player);
@NotNull
ItemBehavior behavior();
interface Builder<I> {

View File

@@ -1,5 +1,6 @@
package net.momirealms.craftengine.core.item;
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
import net.momirealms.craftengine.core.util.Key;
import java.util.List;
@@ -16,6 +17,12 @@ public interface Item<I> {
Optional<CustomItem<I>> getCustomItem();
Optional<List<ItemBehavior>> getItemBehavior();
boolean isCustomItem();
boolean isBlockItem();
Key id();
Key vanillaId();

View File

@@ -102,4 +102,6 @@ public abstract class ItemFactory<P extends Plugin, W extends ItemWrapper<I>, I>
protected abstract void maxStackSize(ItemWrapper<I> item, Integer maxStackSize);
protected abstract boolean is(ItemWrapper<I> item, Key itemTag);
protected abstract boolean isBlockItem(ItemWrapper<I> item);
}

View File

@@ -11,4 +11,10 @@ public class ItemKeys {
public static final Key FISHING_ROD = Key.of("minecraft:fishing_rod");
public static final Key ELYTRA = Key.of("minecraft:elytra");
public static final Key GOAT_HORN = Key.of("minecraft:goat_horn");
public static final Key WOODEN_AXE = Key.of("minecraft:wooden_axe");
public static final Key STONE_AXE = Key.of("minecraft:stone_axe");
public static final Key IRON_AXE = Key.of("minecraft:iron_axe");
public static final Key GOLDEN_AXE = Key.of("minecraft:golden_axe");
public static final Key DIAMOND_AXE = Key.of("minecraft:diamond_axe");
public static final Key NETHERITE_AXE = Key.of("minecraft:netherite_axe");
}

View File

@@ -1,6 +1,7 @@
package net.momirealms.craftengine.core.item;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.behavior.ItemBehavior;
import net.momirealms.craftengine.core.pack.LegacyOverridesModel;
import net.momirealms.craftengine.core.pack.LoadingSequence;
import net.momirealms.craftengine.core.pack.generator.ModelGenerator;
@@ -42,6 +43,8 @@ public interface ItemManager<T> extends Reloadable, ModelGenerator, ConfigSectio
Optional<CustomItem<T>> getCustomItem(Key key);
Optional<List<ItemBehavior>> getItemBehavior(Key key);
Optional<? extends BuildableItem<T>> getVanillaItem(Key key);
default Optional<? extends BuildableItem<T>> getBuildableItem(Key key) {

View File

@@ -4,7 +4,7 @@ import net.momirealms.craftengine.core.entity.player.InteractionHand;
import net.momirealms.craftengine.core.entity.player.InteractionResult;
import net.momirealms.craftengine.core.entity.player.Player;
import net.momirealms.craftengine.core.item.context.UseOnContext;
import net.momirealms.craftengine.core.world.CEWorld;
import net.momirealms.craftengine.core.world.World;
public abstract class ItemBehavior {
@@ -12,7 +12,7 @@ public abstract class ItemBehavior {
return InteractionResult.PASS;
}
public InteractionResult use(CEWorld context, Player player, InteractionHand hand) {
public InteractionResult use(World world, Player player, InteractionHand hand) {
return InteractionResult.PASS;
}
}