Eternal Portals

This commit is contained in:
Aleksey 2020-10-30 16:42:41 +03:00
parent 6d809df962
commit 81e4098a72
8 changed files with 430 additions and 82 deletions

View file

@ -8,17 +8,33 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.util.Tickable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import ru.betterend.registry.EndBlockEntities;
import ru.betterend.util.EternalRitual;
public class PedestalBlockEntity extends BlockEntity implements Inventory, Tickable {
private ItemStack activeItem = ItemStack.EMPTY;
private EternalRitual linkedRitual;
private int age;
public PedestalBlockEntity() {
super(EndBlockEntities.PEDESTAL);
}
public boolean hasRitual() {
return this.linkedRitual != null;
}
public void linkRitual(EternalRitual ritual) {
this.linkedRitual = ritual;
}
public EternalRitual getRitual() {
return this.linkedRitual;
}
public int getAge() {
return this.age;
}
@ -73,6 +89,14 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
return this.toTag(new CompoundTag());
}
@Override
public void setLocation(World world, BlockPos pos) {
super.setLocation(world, pos);
if (hasRitual()) {
this.linkedRitual.setWorld(world);
}
}
@Override
public void fromTag(BlockState state, CompoundTag tag) {
super.fromTag(state, tag);
@ -80,11 +104,18 @@ public class PedestalBlockEntity extends BlockEntity implements Inventory, Ticka
CompoundTag itemTag = tag.getCompound("active_item");
this.activeItem = ItemStack.fromTag(itemTag);
}
if (tag.contains("ritual")) {
this.linkedRitual = new EternalRitual(world);
this.linkedRitual.fromTag(tag.getCompound("ritual"));
}
}
@Override
public CompoundTag toTag(CompoundTag tag) {
tag.put("active_item", activeItem.toTag(new CompoundTag()));
if (this.hasRitual()) {
tag.put("ritual", linkedRitual.toTag(new CompoundTag()));
}
return super.toTag(tag);
}