Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public Class<T> getMemoryClass() {

public static final MemoryKey<Integer> SPEAR_FLEEING_TIME = new MemoryKey<>(NamespacedKey.minecraft("spear_fleeing_time"), Integer.class);

// public static final MemoryKey<SpearAttack.SpearStatus> SPEAR_STATUS = new MemoryKey<>(NamespacedKey.minecraft("spear_status"), SpearStatus.class); // TODO - snapshot: SpearStatus API
public static final MemoryKey<SpearAttack.SpearStatus> SPEAR_STATUS = new MemoryKey<>(NamespacedKey.minecraft("spear_status"), SpearAttack.SpearStatus.class);

public static final MemoryKey<Integer> TEMPTATION_COOLDOWN_TICKS = new MemoryKey<>(NamespacedKey.minecraft("temptation_cooldown_ticks"), Integer.class);

Expand Down
13 changes: 13 additions & 0 deletions paper-api/src/main/java/org/bukkit/entity/memory/SpearAttack.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.bukkit.entity.memory;

public interface SpearAttack {

enum SpearStatus {

// Start generate - SpearStatus
APPROACH,
CHARGING,
RETREAT;
// End generate - SpearStatus
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
import org.bukkit.entity.Wolf;
import org.bukkit.entity.ZombieNautilus;
import org.bukkit.entity.memory.MemoryKey;
import org.bukkit.entity.memory.SpearAttack;
import org.bukkit.generator.structure.Structure;
import org.bukkit.generator.structure.StructureType;
import org.bukkit.inventory.ItemRarity;
Expand Down Expand Up @@ -228,7 +229,8 @@ protected String rewriteFieldType(Holder.Reference<net.minecraft.world.level.gam
.register("BlockType", BlockType.class, new BlockTypeRewriter())
.register("FeatureFlag", FeatureFlag.class, new FeatureFlagRewriter())
.register("Tag", Tag.class, new TagRewriter())
.register("MapPalette#colors", MapPalette.class, new MapPaletteRewriter());
.register("MapPalette#colors", MapPalette.class, new MapPaletteRewriter())
.register("SpearStatus", SpearAttack.SpearStatus.class, new EnumCloneRewriter<>(net.minecraft.world.entity.ai.behavior.SpearAttack.SpearStatus.class));
RegistryBootstrapper.bootstrapApi(sourceSet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.world.phys.Vec3;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.memory.SpearAttack;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;

import static io.papermc.generator.utils.Formatting.quoted;
Expand Down Expand Up @@ -61,7 +62,8 @@ public MemoryKeyRewriter() {
);

private static final Map<Class<?>, Class<?>> API_BRIDGE = Map.of(
GlobalPos.class, Location.class
GlobalPos.class, Location.class,
net.minecraft.world.entity.ai.behavior.SpearAttack.SpearStatus.class, SpearAttack.SpearStatus.class
);

private static final Map<String, String> FIELD_RENAMES = Map.of(
Expand Down Expand Up @@ -106,11 +108,15 @@ protected String rewriteFieldName(Holder.Reference<MemoryModuleType<?>> referenc

@Override
protected String rewriteFieldValue(Holder.Reference<MemoryModuleType<?>> reference) {
String apiMemoryTypeClassName = this.apiMemoryType.getSimpleName();
if (this.apiMemoryType.getEnclosingClass() != null && this.apiMemoryType.isEnum()) {
apiMemoryTypeClassName = this.apiMemoryType.getEnclosingClass().getSimpleName() + "." + this.apiMemoryType.getSimpleName();
}
return "new %s<>(%s.minecraft(%s), %s.class)".formatted(
this.registryEntry.apiClass().getSimpleName(),
NamespacedKey.class.getSimpleName(),
quoted(reference.key().identifier().getPath()),
this.apiMemoryType.getSimpleName() // assume the type is already import (see above in rewriteFieldType)
apiMemoryTypeClassName // assume the type is already import (see above in rewriteFieldType)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.UUID;
import net.minecraft.core.GlobalPos;
import net.minecraft.world.entity.ai.behavior.SpearAttack;
import org.bukkit.Location;
import org.bukkit.craftbukkit.util.CraftLocation;

Expand All @@ -10,16 +11,18 @@ public final class CraftMemoryMapper {
private CraftMemoryMapper() {}

public static Object fromNms(Object object) {
if (object instanceof GlobalPos) {
return CraftLocation.fromGlobalPos((GlobalPos) object);
} else if (object instanceof Long) {
return (Long) object;
} else if (object instanceof UUID) {
return (UUID) object;
} else if (object instanceof Boolean) {
return (Boolean) object;
} else if (object instanceof Integer) {
return (Integer) object;
if (object instanceof GlobalPos globalPos) {
return CraftLocation.fromGlobalPos(globalPos);
} else if (object instanceof SpearAttack.SpearStatus spearStatus) {
return CraftSpearAttack.fromNms(spearStatus);
} else if (object instanceof Long longValue) {
return longValue;
} else if (object instanceof UUID uuid) {
return uuid;
} else if (object instanceof Boolean booleanValue) {
return booleanValue;
} else if (object instanceof Integer integerValue) {
return integerValue;
}

throw new UnsupportedOperationException("Do not know how to map " + object);
Expand All @@ -28,16 +31,18 @@ public static Object fromNms(Object object) {
public static Object toNms(Object object) {
if (object == null) {
return null;
} else if (object instanceof Location) {
return CraftLocation.toGlobalPos((Location) object);
} else if (object instanceof Long) {
return (Long) object;
} else if (object instanceof UUID) {
return (UUID) object;
} else if (object instanceof Boolean) {
return (Boolean) object;
} else if (object instanceof Integer) {
return (Integer) object;
} else if (object instanceof org.bukkit.entity.memory.SpearAttack.SpearStatus spearStatus) {
return CraftSpearAttack.toNms(spearStatus);
} else if (object instanceof Location location) {
return CraftLocation.toGlobalPos(location);
} else if (object instanceof Long longValue) {
return longValue;
} else if (object instanceof UUID uuid) {
return uuid;
} else if (object instanceof Boolean booleanValue) {
return booleanValue;
} else if (object instanceof Integer integerValue) {
return integerValue;
}

throw new UnsupportedOperationException("Do not know how to map " + object);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.bukkit.craftbukkit.entity.memory;

import net.minecraft.world.entity.ai.behavior.SpearAttack;

public class CraftSpearAttack {
public static SpearAttack.SpearStatus toNms(org.bukkit.entity.memory.SpearAttack.SpearStatus bukkit) {
return SpearAttack.SpearStatus.values()[bukkit.ordinal()];
}

public static org.bukkit.entity.memory.SpearAttack.SpearStatus fromNms(SpearAttack.SpearStatus nms) {
return org.bukkit.entity.memory.SpearAttack.SpearStatus.values()[nms.ordinal()];
}
}
Loading