Search in sources :

Example 1 with UpgradeItem

use of com.teamresourceful.resourcefulbees.item.UpgradeItem in project ResourcefulBees by Resourceful-Bees.

the class TieredBeehiveBlock method performHiveUpgrade.

@Nullable
private InteractionResult performHiveUpgrade(@NotNull BlockState state, @NotNull Level world, @NotNull BlockPos pos, ItemStack itemstack) {
    CompoundTag data = ((UpgradeItem) itemstack.getItem()).getUpgradeData();
    BlockEntity tileEntity = world.getBlockEntity(pos);
    if (tileEntity instanceof TieredBeehiveTileEntity) {
        TieredBeehiveTileEntity beehiveTileEntity = (TieredBeehiveTileEntity) tileEntity;
        if (1 + beehiveTileEntity.getTier() == data.getInt(NBTConstants.NBT_TIER)) {
            int newTier = data.getInt(NBTConstants.NBT_TIER);
            beehiveTileEntity.setTier(newTier);
            beehiveTileEntity.setTierModifier(data.getFloat(NBTConstants.NBT_TIER_MODIFIER));
            beehiveTileEntity.recalculateHoneyLevel();
            itemstack.shrink(1);
            state = state.setValue(TIER_PROPERTY, newTier);
            world.setBlockAndUpdate(pos, state);
            return InteractionResult.SUCCESS;
        }
    }
    return null;
}
Also used : UpgradeItem(com.teamresourceful.resourcefulbees.item.UpgradeItem) CompoundTag(net.minecraft.nbt.CompoundTag) BeehiveBlockEntity(net.minecraft.world.level.block.entity.BeehiveBlockEntity) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) TieredBeehiveTileEntity(com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

UpgradeItem (com.teamresourceful.resourcefulbees.item.UpgradeItem)1 TieredBeehiveTileEntity (com.teamresourceful.resourcefulbees.tileentity.TieredBeehiveTileEntity)1 CompoundTag (net.minecraft.nbt.CompoundTag)1 BeehiveBlockEntity (net.minecraft.world.level.block.entity.BeehiveBlockEntity)1 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)1 Nullable (org.jetbrains.annotations.Nullable)1