WIP: Included target deaths in data component.
This commit is contained in:
@ -13,23 +13,28 @@ public class TotemData {
|
||||
instance.group(
|
||||
Codec.INT.fieldOf("targetIndex").forGetter(TotemData::getTargetIndex),
|
||||
Codec.STRING.fieldOf("targetUUID").forGetter(TotemData::getTargetUUID),
|
||||
Codec.STRING.fieldOf("targetName").forGetter(TotemData::getTargetName)
|
||||
Codec.STRING.fieldOf("targetName").forGetter(TotemData::getTargetName),
|
||||
Codec.INT.fieldOf("targetDeaths").forGetter(TotemData::getTargetDeaths)
|
||||
).apply(instance, TotemData::new)
|
||||
);
|
||||
public static final StreamCodec<ByteBuf, TotemData> STREAM_CODEC = StreamCodec.composite(
|
||||
ByteBufCodecs.INT, TotemData::getTargetIndex,
|
||||
ByteBufCodecs.STRING_UTF8, TotemData::getTargetUUID,
|
||||
ByteBufCodecs.STRING_UTF8, TotemData::getTargetName,
|
||||
ByteBufCodecs.INT, TotemData::getTargetDeaths,
|
||||
TotemData::new
|
||||
);
|
||||
|
||||
private int targetIndex;
|
||||
private String targetUUID;
|
||||
private String targetName;
|
||||
private int targetDeaths;
|
||||
|
||||
public TotemData(int targetIndex, String targetUUID, String targetName) {
|
||||
public TotemData(int targetIndex, String targetUUID, String targetName, int targetDeaths) {
|
||||
this.targetIndex = targetIndex;
|
||||
this.targetUUID = targetUUID;
|
||||
this.targetName = targetName;
|
||||
this.targetDeaths = targetDeaths;
|
||||
}
|
||||
|
||||
public int getTargetIndex() {
|
||||
@ -53,9 +58,16 @@ public class TotemData {
|
||||
this.targetName = targetName;
|
||||
}
|
||||
|
||||
public int getTargetDeaths() {
|
||||
return targetDeaths;
|
||||
}
|
||||
public void setTargetDeaths(int targetDeaths) {
|
||||
this.targetDeaths = targetDeaths;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.targetIndex, this.targetUUID);
|
||||
return Objects.hash(this.targetIndex, this.targetUUID, this.targetName, this.targetDeaths);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,7 +77,9 @@ public class TotemData {
|
||||
} else {
|
||||
return obj instanceof TotemData td
|
||||
&& this.targetIndex == td.targetIndex
|
||||
&& Objects.equals(this.targetUUID, td.targetUUID);
|
||||
&& Objects.equals(this.targetUUID, td.targetUUID)
|
||||
&& Objects.equals(this.targetName, td.targetName)
|
||||
&& this.targetDeaths == td.targetDeaths;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -91,14 +91,17 @@ public abstract class TotemItem extends Item {
|
||||
return !isCostDynamic(stack) ? getConfig(stack).getChargeCost() :
|
||||
(int)(getTargetDeaths(stack) * getConfig(stack).getChargeCostMultiplier());
|
||||
}
|
||||
|
||||
public static int getTargetDeaths(ItemStack stack) {
|
||||
if (!isTotem(stack)) { return -1; }
|
||||
return stack.getOrCreateTag().getInt(TAG_TARGET_DEATHS);
|
||||
|
||||
@Nullable
|
||||
public static Integer getTargetDeaths(ItemStack stack) {
|
||||
return getTotemData(stack).map(TotemData::getTargetDeaths).orElse(null);
|
||||
}
|
||||
public static void setTargetDeaths(ItemStack stack, ServerPlayer target) {
|
||||
if (!isTotem(stack)) { return; }
|
||||
stack.getOrCreateTag().putInt(TAG_TARGET_DEATHS, target.getStats().getValue(Stats.CUSTOM.get(Stats.DEATHS)));
|
||||
Optional<TotemData> data = getTotemData(stack);
|
||||
if (data.isEmpty()) { return; }
|
||||
|
||||
data.get().setTargetDeaths(target.getStats().getValue(Stats.CUSTOM.get(Stats.DEATHS)));
|
||||
stack.set(ModDataComponents.TOTEM_DATA.get(), data.get());
|
||||
}
|
||||
|
||||
public static boolean isTotemFull(ItemStack stack) {
|
||||
|
||||
Reference in New Issue
Block a user