mirror of
https://github.com/Xiao-MoMi/craft-engine.git
synced 2025-12-24 09:29:33 +00:00
Rename arguments
This commit is contained in:
@@ -62,6 +62,10 @@ public abstract class AbstractItemManager<I> extends AbstractModelGenerator impl
|
||||
Map<String, Object> data = MiscUtils.castToMap(obj, false);
|
||||
return new TagsModifier<>(data);
|
||||
}, "tags", "tag", "nbt");
|
||||
registerDataFunction((obj) -> {
|
||||
boolean value = TypeUtils.checkType(obj, Boolean.class);
|
||||
return new UnbreakableModifier<>(value);
|
||||
}, "unbreakable");
|
||||
if (VersionHelper.isVersionNewerThan1_20_5()) {
|
||||
registerDataFunction((obj) -> {
|
||||
String name = TypeUtils.checkType(obj, String.class);
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package net.momirealms.craftengine.core.item.context;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.InteractionHand;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.Direction;
|
||||
import net.momirealms.craftengine.core.world.BlockHitResult;
|
||||
import net.momirealms.craftengine.core.world.BlockPos;
|
||||
import net.momirealms.craftengine.core.world.Vec3d;
|
||||
import net.momirealms.craftengine.core.world.World;
|
||||
|
||||
public class DirectionalPlaceContext extends BlockPlaceContext {
|
||||
private final Direction direction;
|
||||
|
||||
public DirectionalPlaceContext(World world, BlockPos pos, Direction facing, Item<?> stack, Direction side) {
|
||||
super(world, null, InteractionHand.MAIN_HAND, stack, new BlockHitResult(Vec3d.atBottomCenterOf(pos), side, pos, false));
|
||||
this.direction = facing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockPos getClickedPos() {
|
||||
return this.getHitResult().getBlockPos();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlace() {
|
||||
return this.getLevel().getBlockAt(this.getHitResult().getBlockPos()).canBeReplaced(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean replacingClickedOnBlock() {
|
||||
return this.canPlace();
|
||||
}
|
||||
|
||||
public Direction getNearestLookingDirection() {
|
||||
return Direction.DOWN;
|
||||
}
|
||||
|
||||
public Direction[] getNearestLookingDirections() {
|
||||
return switch (this.direction) {
|
||||
case UP ->
|
||||
new Direction[]{Direction.DOWN, Direction.UP, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST};
|
||||
case NORTH ->
|
||||
new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.SOUTH};
|
||||
case SOUTH ->
|
||||
new Direction[]{Direction.DOWN, Direction.SOUTH, Direction.EAST, Direction.WEST, Direction.UP, Direction.NORTH};
|
||||
case WEST ->
|
||||
new Direction[]{Direction.DOWN, Direction.WEST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.EAST};
|
||||
case EAST ->
|
||||
new Direction[]{Direction.DOWN, Direction.EAST, Direction.SOUTH, Direction.UP, Direction.NORTH, Direction.WEST};
|
||||
default ->
|
||||
new Direction[]{Direction.DOWN, Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST, Direction.UP};
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public Direction getHorizontalDirection() {
|
||||
return this.direction.axis() == Direction.Axis.Y ? Direction.NORTH : this.direction;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecondaryUseActive() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getRotation() {
|
||||
return (float) (this.direction.data2d() * 90);
|
||||
}
|
||||
}
|
||||
@@ -65,11 +65,11 @@ public class UseOnContext {
|
||||
}
|
||||
|
||||
public Direction getHorizontalDirection() {
|
||||
return this.player == null ? Direction.NORTH : this.player.getDirection();
|
||||
return this.player.getDirection();
|
||||
}
|
||||
|
||||
public boolean isSecondaryUseActive() {
|
||||
return this.player != null && this.player.isSecondaryUseActive();
|
||||
return this.player.isSecondaryUseActive();
|
||||
}
|
||||
|
||||
public float getRotation() {
|
||||
|
||||
@@ -8,14 +8,14 @@ import net.momirealms.craftengine.core.util.YamlUtils;
|
||||
import java.util.Map;
|
||||
|
||||
public class ComponentModifier<I> implements ItemModifier<I> {
|
||||
private final Map<String, Object> parameters;
|
||||
private final Map<String, Object> arguments;
|
||||
|
||||
public ComponentModifier(Map<String, Object> parameters) {
|
||||
this.parameters = parameters;
|
||||
public ComponentModifier(Map<String, Object> arguments) {
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
public ComponentModifier(Section section) {
|
||||
this.parameters = YamlUtils.sectionToMap(section);
|
||||
this.arguments = YamlUtils.sectionToMap(section);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,7 +25,7 @@ public class ComponentModifier<I> implements ItemModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, Player player) {
|
||||
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
|
||||
for (Map.Entry<String, Object> entry : arguments.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
item.setComponent(key, value);
|
||||
|
||||
@@ -4,10 +4,10 @@ import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
|
||||
public class CustomModelDataModifier<I> implements ItemModifier<I> {
|
||||
private final int parameter;
|
||||
private final int argument;
|
||||
|
||||
public CustomModelDataModifier(int parameter) {
|
||||
this.parameter = parameter;
|
||||
public CustomModelDataModifier(int argument) {
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -17,6 +17,6 @@ public class CustomModelDataModifier<I> implements ItemModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, Player player) {
|
||||
item.customModelData(parameter);
|
||||
item.customModelData(argument);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import net.momirealms.craftengine.core.plugin.minimessage.PlaceholderTag;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
|
||||
public class DisplayNameModifier<I> implements ItemModifier<I> {
|
||||
private final String parameter;
|
||||
private final String argument;
|
||||
|
||||
public DisplayNameModifier(String parameter) {
|
||||
this.parameter = parameter;
|
||||
public DisplayNameModifier(String argument) {
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -21,6 +21,6 @@ public class DisplayNameModifier<I> implements ItemModifier<I> {
|
||||
@Override
|
||||
public void apply(Item<I> item, Player player) {
|
||||
item.displayName(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(
|
||||
parameter, ImageTag.instance(), new PlaceholderTag(player))));
|
||||
argument, ImageTag.instance(), new PlaceholderTag(player))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,10 @@ import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.util.Key;
|
||||
|
||||
public class IdModifier<I> implements ItemModifier<I> {
|
||||
private final Key parameter;
|
||||
private final Key argument;
|
||||
|
||||
public IdModifier(Key parameter) {
|
||||
this.parameter = parameter;
|
||||
public IdModifier(Key argument) {
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -18,6 +18,6 @@ public class IdModifier<I> implements ItemModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, Player player) {
|
||||
item.setTag(parameter.toString(), "craftengine:id");
|
||||
item.setTag(argument.toString(), "craftengine:id");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,11 +7,12 @@ import net.momirealms.craftengine.core.plugin.minimessage.PlaceholderTag;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
|
||||
public class ItemNameModifier<I> implements ItemModifier<I> {
|
||||
private final String parameter;
|
||||
private final String argument;
|
||||
|
||||
public ItemNameModifier(String parameter) {
|
||||
this.parameter = parameter;
|
||||
public ItemNameModifier(String argument) {
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "item-name";
|
||||
@@ -20,6 +21,6 @@ public class ItemNameModifier<I> implements ItemModifier<I> {
|
||||
@Override
|
||||
public void apply(Item<I> item, Player player) {
|
||||
item.itemName(AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(
|
||||
parameter, ImageTag.instance(), new PlaceholderTag(player))));
|
||||
argument, ImageTag.instance(), new PlaceholderTag(player))));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
import java.util.List;
|
||||
|
||||
public class LoreModifier<I> implements ItemModifier<I> {
|
||||
private final List<String> parameter;
|
||||
private final List<String> argument;
|
||||
|
||||
public LoreModifier(List<String> parameter) {
|
||||
this.parameter = parameter;
|
||||
public LoreModifier(List<String> argument) {
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,7 +22,7 @@ public class LoreModifier<I> implements ItemModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, Player player) {
|
||||
item.lore(parameter.stream().map(it -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(
|
||||
item.lore(argument.stream().map(it -> AdventureHelper.componentToJson(AdventureHelper.miniMessage().deserialize(
|
||||
it, ImageTag.instance(), new PlaceholderTag(player)))).toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,10 +9,10 @@ import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class TagsModifier<I> implements ItemModifier<I> {
|
||||
private final Map<String, Object> parameters;
|
||||
private final Map<String, Object> arguments;
|
||||
|
||||
public TagsModifier(Map<String, Object> parameters) {
|
||||
this.parameters = mapToMap(parameters);
|
||||
public TagsModifier(Map<String, Object> arguments) {
|
||||
this.arguments = mapToMap(arguments);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,7 +22,7 @@ public class TagsModifier<I> implements ItemModifier<I> {
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, Player player) {
|
||||
for (Map.Entry<String, Object> entry : parameters.entrySet()) {
|
||||
for (Map.Entry<String, Object> entry : arguments.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
Object value = entry.getValue();
|
||||
item.setTag(value, key);
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package net.momirealms.craftengine.core.item.modifier;
|
||||
|
||||
import net.momirealms.craftengine.core.entity.player.Player;
|
||||
import net.momirealms.craftengine.core.item.Item;
|
||||
import net.momirealms.craftengine.core.plugin.minimessage.ImageTag;
|
||||
import net.momirealms.craftengine.core.plugin.minimessage.PlaceholderTag;
|
||||
import net.momirealms.craftengine.core.util.AdventureHelper;
|
||||
|
||||
public class UnbreakableModifier<I> implements ItemModifier<I> {
|
||||
private final boolean argument;
|
||||
|
||||
public UnbreakableModifier(boolean argument) {
|
||||
this.argument = argument;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String name() {
|
||||
return "unbreakable";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(Item<I> item, Player player) {
|
||||
item.unbreakable(argument);
|
||||
}
|
||||
}
|
||||
@@ -266,9 +266,7 @@ public class StackedContents<T> {
|
||||
|
||||
private int getConnectionIndex(int itemIndex, int ingredientIndex) {
|
||||
assert itemIndex >= 0 && itemIndex < this.itemCount;
|
||||
|
||||
assert ingredientIndex >= 0 && ingredientIndex < this.ingredientCount;
|
||||
|
||||
return this.connectionOffset() + itemIndex * this.ingredientCount + ingredientIndex;
|
||||
}
|
||||
|
||||
@@ -278,25 +276,19 @@ public class StackedContents<T> {
|
||||
|
||||
private void assign(int itemIndex, int ingredientIndex) {
|
||||
int i = this.getResidualIndex(itemIndex, ingredientIndex);
|
||||
|
||||
assert !this.data.get(i);
|
||||
|
||||
this.data.set(i);
|
||||
}
|
||||
|
||||
private void unassign(int itemIndex, int ingredientIndex) {
|
||||
int i = this.getResidualIndex(itemIndex, ingredientIndex);
|
||||
|
||||
assert this.data.get(i);
|
||||
|
||||
this.data.clear(i);
|
||||
}
|
||||
|
||||
private int getResidualIndex(int itemIndex, int ingredientIndex) {
|
||||
assert itemIndex >= 0 && itemIndex < this.itemCount;
|
||||
|
||||
assert ingredientIndex >= 0 && ingredientIndex < this.ingredientCount;
|
||||
|
||||
return this.residualOffset() + itemIndex * this.ingredientCount + ingredientIndex;
|
||||
}
|
||||
|
||||
@@ -310,7 +302,6 @@ public class StackedContents<T> {
|
||||
|
||||
private int getVisitedIngredientIndex(int index) {
|
||||
assert index >= 0 && index < this.ingredientCount;
|
||||
|
||||
return this.visitedIngredientOffset() + index;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user