Pedestals serialization
This commit is contained in:
parent
068fa540be
commit
83f4f923b1
3 changed files with 38 additions and 40 deletions
|
@ -33,15 +33,6 @@ public class EternalPedestalEntity extends PedestalBlockEntity {
|
|||
linkedRitual.setWorld(world);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
if (tag.contains("ritual")) {
|
||||
linkedRitual = new EternalRitual(world);
|
||||
linkedRitual.fromTag(tag.getCompound("ritual"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
|
@ -50,4 +41,13 @@ public class EternalPedestalEntity extends PedestalBlockEntity {
|
|||
}
|
||||
return super.toTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fromTag(CompoundTag tag) {
|
||||
super.fromTag(tag);
|
||||
if (tag.contains("ritual")) {
|
||||
linkedRitual = new EternalRitual(world);
|
||||
linkedRitual.fromTag(tag.getCompound("ritual"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package ru.betterend.blocks.entities;
|
||||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -42,27 +43,21 @@ public class InfusionPedestalEntity extends PedestalBlockEntity {
|
|||
}
|
||||
super.tick();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public CompoundTag toInitialChunkDataTag() {
|
||||
return this.toTag(new CompoundTag());
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
if (hasRitual()) {
|
||||
tag.put("ritual", linkedRitual.toTag(new CompoundTag()));
|
||||
}
|
||||
return super.toTag(tag);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
protected void fromTag(CompoundTag tag) {
|
||||
super.fromTag(tag);
|
||||
if (tag.contains("ritual")) {
|
||||
linkedRitual = new InfusionRitual(world, pos);
|
||||
linkedRitual.fromTag(tag.getCompound("ritual"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
if (hasRitual()) {
|
||||
tag.put("ritual", linkedRitual.toTag(new CompoundTag()));
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,14 +106,30 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
|||
@Override
|
||||
public void fromTag(BlockState state, CompoundTag tag) {
|
||||
super.fromTag(state, tag);
|
||||
fromClientTag(tag);
|
||||
fromTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toTag(CompoundTag tag) {
|
||||
super.toTag(tag);
|
||||
tag.put("active_item", activeItem.toTag(new CompoundTag()));
|
||||
return tag;
|
||||
return super.toTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromClientTag(CompoundTag tag) {
|
||||
fromTag(tag);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toClientTag(CompoundTag tag) {
|
||||
return toTag(tag);
|
||||
}
|
||||
|
||||
protected void fromTag(CompoundTag tag) {
|
||||
if (tag.contains("active_item")) {
|
||||
CompoundTag itemTag = tag.getCompound("active_item");
|
||||
activeItem = ItemStack.fromTag(itemTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -125,17 +141,4 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromClientTag(CompoundTag tag) {
|
||||
if (tag.contains("active_item")) {
|
||||
CompoundTag itemTag = tag.getCompound("active_item");
|
||||
activeItem = ItemStack.fromTag(itemTag);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag toClientTag(CompoundTag tag) {
|
||||
return toTag(tag);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue