Attach serializer to object

This commit is contained in:
Marcel Konrad
2020-05-22 14:55:07 +02:00
parent 93cb07647d
commit f161867a1a
3 changed files with 7 additions and 2 deletions

View File

@@ -5,7 +5,6 @@ import javax.annotation.Nullable;
import exopandora.worldhandler.builder.component.impl.ComponentTag; import exopandora.worldhandler.builder.component.impl.ComponentTag;
import exopandora.worldhandler.util.MutableStringTextComponent; import exopandora.worldhandler.util.MutableStringTextComponent;
import exopandora.worldhandler.util.SignText; import exopandora.worldhandler.util.SignText;
import net.minecraft.nbt.StringNBT;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@@ -23,7 +22,7 @@ public class BuilderSignEditor extends BuilderData
for(int x = 0; x < 4; x++) for(int x = 0; x < 4; x++)
{ {
this.sign[x] = this.registerNBTComponent(new ComponentTag<SignText>("Text" + (x + 1), new SignText(x), text -> StringNBT.valueOf(text.toString()))); this.sign[x] = this.registerNBTComponent(new ComponentTag<SignText>("Text" + (x + 1), new SignText(x), SignText::toNBT));
} }
} }

View File

@@ -2,6 +2,7 @@ package exopandora.worldhandler.util;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import net.minecraft.nbt.StringNBT;
import net.minecraft.util.text.event.ClickEvent; import net.minecraft.util.text.event.ClickEvent;
import net.minecraft.util.text.event.ClickEvent.Action; import net.minecraft.util.text.event.ClickEvent.Action;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
@@ -61,6 +62,11 @@ public class SignText
return this.text.getStyle().getClickEvent() != null && this.text.getStyle().getClickEvent().getAction() == Action.RUN_COMMAND && this.text.getStyle().getClickEvent().getValue() != null; return this.text.getStyle().getClickEvent() != null && this.text.getStyle().getClickEvent().getAction() == Action.RUN_COMMAND && this.text.getStyle().getClickEvent().getValue() != null;
} }
public StringNBT toNBT()
{
return StringNBT.valueOf(this.toString());
}
@Override @Override
public String toString() public String toString()
{ {