WIP: Included target name in data component.
This commit is contained in:
@ -12,19 +12,22 @@ public class TotemData {
|
|||||||
public static final Codec<TotemData> CODEC = RecordCodecBuilder.create(instance ->
|
public static final Codec<TotemData> CODEC = RecordCodecBuilder.create(instance ->
|
||||||
instance.group(
|
instance.group(
|
||||||
Codec.INT.fieldOf("targetIndex").forGetter(TotemData::getTargetIndex),
|
Codec.INT.fieldOf("targetIndex").forGetter(TotemData::getTargetIndex),
|
||||||
Codec.STRING.fieldOf("targetUUID").forGetter(TotemData::getTargetUUID)
|
Codec.STRING.fieldOf("targetUUID").forGetter(TotemData::getTargetUUID),
|
||||||
|
Codec.STRING.fieldOf("targetName").forGetter(TotemData::getTargetName)
|
||||||
).apply(instance, TotemData::new)
|
).apply(instance, TotemData::new)
|
||||||
);
|
);
|
||||||
public static final StreamCodec<ByteBuf, TotemData> STREAM_CODEC = StreamCodec.composite(
|
public static final StreamCodec<ByteBuf, TotemData> STREAM_CODEC = StreamCodec.composite(
|
||||||
ByteBufCodecs.INT, TotemData::getTargetIndex,
|
ByteBufCodecs.INT, TotemData::getTargetIndex,
|
||||||
ByteBufCodecs.STRING_UTF8, TotemData::getTargetUUID,
|
ByteBufCodecs.STRING_UTF8, TotemData::getTargetUUID,
|
||||||
|
ByteBufCodecs.STRING_UTF8, TotemData::getTargetName,
|
||||||
TotemData::new
|
TotemData::new
|
||||||
);
|
);
|
||||||
|
|
||||||
private int targetIndex;
|
private int targetIndex;
|
||||||
private String targetUUID;
|
private String targetUUID;
|
||||||
|
private String targetName;
|
||||||
|
|
||||||
public TotemData(int targetIndex, String targetUUID) {
|
public TotemData(int targetIndex, String targetUUID, String targetName) {
|
||||||
this.targetIndex = targetIndex;
|
this.targetIndex = targetIndex;
|
||||||
this.targetUUID = targetUUID;
|
this.targetUUID = targetUUID;
|
||||||
}
|
}
|
||||||
@ -32,15 +35,22 @@ public class TotemData {
|
|||||||
public int getTargetIndex() {
|
public int getTargetIndex() {
|
||||||
return targetIndex;
|
return targetIndex;
|
||||||
}
|
}
|
||||||
public void setTargetIndex(int newTargetIndex) {
|
public void setTargetIndex(int targetIndex) {
|
||||||
targetIndex = newTargetIndex;
|
this.targetIndex = targetIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTargetUUID() {
|
public String getTargetUUID() {
|
||||||
return targetUUID;
|
return targetUUID;
|
||||||
}
|
}
|
||||||
public void setTargetUUID(String newTargetUUID) {
|
public void setTargetUUID(String targetUUID) {
|
||||||
targetUUID = newTargetUUID;
|
this.targetUUID = targetUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTargetName() {
|
||||||
|
return targetName;
|
||||||
|
}
|
||||||
|
public void setTargetName(String targetName) {
|
||||||
|
this.targetName = targetName;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -74,13 +74,16 @@ public abstract class TotemItem extends Item {
|
|||||||
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static String getTargetName(ItemStack stack) {
|
public static String getTargetName(ItemStack stack) {
|
||||||
if (!isTotem(stack)) { return null; }
|
return getTotemData(stack).map(TotemData::getTargetName).orElse(null);
|
||||||
return stack.getOrCreateTag().getString(TAG_TARGET_NAME);
|
|
||||||
}
|
}
|
||||||
public static void setTargetName(ItemStack stack, String targetName) {
|
public static void setTargetName(ItemStack stack, String targetName) {
|
||||||
if (!isTotem(stack)) { return; }
|
Optional<TotemData> data = getTotemData(stack);
|
||||||
stack.getOrCreateTag().putString(TAG_TARGET_NAME, targetName);
|
if (data.isEmpty()) { return; }
|
||||||
|
|
||||||
|
data.get().setTargetName(targetName);
|
||||||
|
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getTargetCost(ItemStack stack) {
|
public static int getTargetCost(ItemStack stack) {
|
||||||
|
|||||||
Reference in New Issue
Block a user