Unicopia/src/main/java/com/minelittlepony/unicopia/entity/ItemEntityCapabilities.java

77 lines
1.6 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.entity;
2020-01-16 12:35:46 +01:00
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ducks.IItemEntity;
2020-01-16 12:35:46 +01:00
import net.minecraft.entity.ItemEntity;
2020-01-27 11:05:22 +01:00
import net.minecraft.item.ItemStack;
2020-01-16 12:35:46 +01:00
import net.minecraft.nbt.CompoundTag;
2020-01-27 11:05:22 +01:00
import net.minecraft.util.ActionResult;
2020-01-16 12:35:46 +01:00
public class ItemEntityCapabilities implements RaceContainer<ItemEntity>, Owned<ItemEntity> {
2020-01-16 12:35:46 +01:00
private Race race = Race.HUMAN;
private final ItemEntity owner;
public ItemEntityCapabilities(ItemEntity owner) {
this.owner = owner;
}
@Override
public void onUpdate() {
}
@Override
2020-01-27 11:05:22 +01:00
public boolean beforeUpdate() {
ItemStack stack = owner.getStack();
2020-01-16 12:35:46 +01:00
2020-01-27 11:05:22 +01:00
if (!stack.isEmpty() && stack.getItem() instanceof TickableItem) {
return ((TickableItem)stack.getItem()).onGroundTick((IItemEntity)owner) == ActionResult.SUCCESS;
}
return false;
2020-01-16 12:35:46 +01:00
}
@Override
public Race getSpecies() {
return race;
}
@Override
public void setSpecies(Race race) {
this.race = race;
}
@Override
public void toNBT(CompoundTag compound) {
compound.putString("owner_species", race.name());
}
@Override
public void fromNBT(CompoundTag compound) {
race = Race.fromName(compound.getString("owner_species"));
}
@Override
public void setOwner(ItemEntity owner) {
}
@Override
public void onDimensionalTravel(int destinationDimension) {
}
@Override
public ItemEntity getOwner() {
return owner;
}
2020-01-27 11:05:22 +01:00
public interface TickableItem {
ActionResult onGroundTick(IItemEntity entity);
}
2020-01-16 12:35:46 +01:00
}