fixed bug from #440 implementation, implemented #439 (casting items now store the caster's pigment when created).
This commit is contained in:
parent
c4c2825f3d
commit
578c4fdab5
|
@ -1,6 +1,7 @@
|
|||
package at.petrak.hexcasting.api.addldata;
|
||||
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota;
|
||||
import at.petrak.hexcasting.api.pigment.FrozenPigment;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -15,7 +16,9 @@ public interface ADHexHolder {
|
|||
@Nullable
|
||||
List<Iota> getHex(ServerLevel level);
|
||||
|
||||
void writeHex(List<Iota> patterns, long media);
|
||||
void writeHex(List<Iota> patterns, @Nullable FrozenPigment pigment, long media);
|
||||
|
||||
void clearHex();
|
||||
|
||||
@Nullable FrozenPigment getPigment();
|
||||
}
|
||||
|
|
|
@ -54,6 +54,8 @@ public class PackagedItemCastEnv extends PlayerBasedCastEnv {
|
|||
|
||||
@Override
|
||||
public FrozenPigment getColorizer() {
|
||||
return null;
|
||||
var casterStack = this.caster.getItemInHand(this.castingHand);
|
||||
var casterHexHolder = IXplatAbstractions.INSTANCE.findHexHolder(casterStack);
|
||||
return casterHexHolder.getPigment();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package at.petrak.hexcasting.api.item;
|
||||
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota;
|
||||
import at.petrak.hexcasting.api.pigment.FrozenPigment;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
@ -24,7 +25,9 @@ public interface HexHolderItem extends MediaHolderItem {
|
|||
@Nullable
|
||||
List<Iota> getHex(ItemStack stack, ServerLevel level);
|
||||
|
||||
void writeHex(ItemStack stack, List<Iota> program, long media);
|
||||
void writeHex(ItemStack stack, List<Iota> program, @Nullable FrozenPigment pigment, long media);
|
||||
|
||||
void clearHex(ItemStack stack);
|
||||
|
||||
@Nullable FrozenPigment getPigment(ItemStack stack);
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ const val SQRT_3 = 1.7320508f
|
|||
fun Vec3.serializeToNBT(): CompoundTag {
|
||||
val tag = CompoundTag()
|
||||
tag.putDouble("x", this.x)
|
||||
tag.putDouble("y", this.x)
|
||||
tag.putDouble("z", this.x)
|
||||
tag.putDouble("y", this.y)
|
||||
tag.putDouble("z", this.z)
|
||||
return tag
|
||||
}
|
||||
|
||||
|
|
|
@ -74,7 +74,7 @@ class OpMakePackagedSpell<T : ItemPackagedHex>(val itemType: T, val cost: Int) :
|
|||
val entityStack = itemEntity.item.copy()
|
||||
val mediamount = extractMedia(entityStack, drainForBatteries = true)
|
||||
if (mediamount > 0) {
|
||||
hexHolder.writeHex(patterns, mediamount)
|
||||
hexHolder.writeHex(patterns, ctx.colorizer, mediamount)
|
||||
}
|
||||
|
||||
itemEntity.item = entityStack
|
||||
|
|
|
@ -5,6 +5,7 @@ import at.petrak.hexcasting.api.casting.eval.vm.CastingVM;
|
|||
import at.petrak.hexcasting.api.casting.iota.Iota;
|
||||
import at.petrak.hexcasting.api.casting.iota.IotaType;
|
||||
import at.petrak.hexcasting.api.item.HexHolderItem;
|
||||
import at.petrak.hexcasting.api.pigment.FrozenPigment;
|
||||
import at.petrak.hexcasting.api.utils.NBTHelper;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
|
@ -32,6 +33,7 @@ import static at.petrak.hexcasting.api.HexAPI.modLoc;
|
|||
*/
|
||||
public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHolderItem {
|
||||
public static final String TAG_PROGRAM = "patterns";
|
||||
public static final String TAG_PIGMENT = "pigment";
|
||||
public static final ResourceLocation HAS_PATTERNS_PRED = modLoc("has_patterns");
|
||||
|
||||
public ItemPackagedHex(Properties pProperties) {
|
||||
|
@ -74,24 +76,35 @@ public abstract class ItemPackagedHex extends ItemMediaHolder implements HexHold
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeHex(ItemStack stack, List<Iota> program, long media) {
|
||||
public void writeHex(ItemStack stack, List<Iota> program, @Nullable FrozenPigment pigment, long media) {
|
||||
ListTag patsTag = new ListTag();
|
||||
for (Iota pat : program) {
|
||||
patsTag.add(IotaType.serialize(pat));
|
||||
}
|
||||
|
||||
NBTHelper.putList(stack, TAG_PROGRAM, patsTag);
|
||||
if (pigment != null)
|
||||
NBTHelper.putCompound(stack, TAG_PIGMENT, pigment.serializeToNBT());
|
||||
|
||||
withMedia(stack, media, media);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHex(ItemStack stack) {
|
||||
NBTHelper.remove(stack, ItemPackagedHex.TAG_PROGRAM);
|
||||
NBTHelper.remove(stack, TAG_PROGRAM);
|
||||
NBTHelper.remove(stack, TAG_PIGMENT);
|
||||
NBTHelper.remove(stack, TAG_MEDIA);
|
||||
NBTHelper.remove(stack, TAG_MAX_MEDIA);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FrozenPigment getPigment(ItemStack stack) {
|
||||
var ctag = NBTHelper.getCompound(stack, TAG_PIGMENT);
|
||||
if (ctag == null)
|
||||
return null;
|
||||
return FrozenPigment.fromNBT(ctag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand usedHand) {
|
||||
var stack = player.getItemInHand(usedHand);
|
||||
|
|
|
@ -3,6 +3,7 @@ package at.petrak.hexcasting.fabric.cc.adimpl;
|
|||
import at.petrak.hexcasting.api.addldata.ADHexHolder;
|
||||
import at.petrak.hexcasting.api.item.HexHolderItem;
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota;
|
||||
import at.petrak.hexcasting.api.pigment.FrozenPigment;
|
||||
import at.petrak.hexcasting.fabric.cc.HexCardinalComponents;
|
||||
import dev.onyxstudios.cca.api.v3.item.ItemComponent;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
|
@ -45,13 +46,18 @@ public abstract class CCHexHolder extends ItemComponent implements ADHexHolder {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeHex(List<Iota> patterns, long media) {
|
||||
this.hexHolder.writeHex(this.stack, patterns, media);
|
||||
public void writeHex(List<Iota> patterns, @Nullable FrozenPigment pigment, long media) {
|
||||
this.hexHolder.writeHex(this.stack, patterns, pigment, media);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHex() {
|
||||
this.hexHolder.clearHex(this.stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FrozenPigment getPigment() {
|
||||
return this.hexHolder.getPigment(this.stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package at.petrak.hexcasting.forge.cap.adimpl;
|
|||
import at.petrak.hexcasting.api.addldata.ADHexHolder;
|
||||
import at.petrak.hexcasting.api.item.HexHolderItem;
|
||||
import at.petrak.hexcasting.api.casting.iota.Iota;
|
||||
import at.petrak.hexcasting.api.pigment.FrozenPigment;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
@ -28,12 +29,17 @@ public record CapItemHexHolder(HexHolderItem holder,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void writeHex(List<Iota> patterns, long media) {
|
||||
holder.writeHex(stack, patterns, media);
|
||||
public void writeHex(List<Iota> patterns, @Nullable FrozenPigment pigment, long media) {
|
||||
holder.writeHex(stack, patterns, pigment, media);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearHex() {
|
||||
holder.clearHex(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable FrozenPigment getPigment() {
|
||||
return holder.getPigment(stack);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue