Search in sources :

Example 1 with BuildingBeekeeper

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper in project minecolonies by Minecolonies.

the class ItemScepterBeekeeper method useOn.

@Override
public ActionResultType useOn(final ItemUseContext useContext) {
    // if server world, do nothing
    if (useContext.getLevel().isClientSide) {
        return ActionResultType.FAIL;
    }
    final PlayerEntity player = useContext.getPlayer();
    final ItemStack scepter = useContext.getPlayer().getItemInHand(useContext.getHand());
    final CompoundNBT compound = scepter.getOrCreateTag();
    final IColony colony = IColonyManager.getInstance().getColonyByWorld(compound.getInt(TAG_ID), useContext.getLevel());
    final BlockPos hutPos = BlockPosUtil.read(compound, TAG_POS);
    final IBuilding hut = colony.getBuildingManager().getBuilding(hutPos);
    final BuildingBeekeeper building = (BuildingBeekeeper) hut;
    if (useContext.getLevel().getBlockState(useContext.getClickedPos()).getBlock() instanceof BeehiveBlock) {
        final Collection<BlockPos> positions = building.getHives();
        final BlockPos pos = useContext.getClickedPos();
        if (positions.contains(pos)) {
            LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.removehive");
            building.removeHive(pos);
            SoundUtils.playSoundForPlayer((ServerPlayerEntity) player, SoundEvents.NOTE_BLOCK_BELL, (float) SoundUtils.VOLUME * 2, 0.5f);
        } else {
            if (positions.size() < building.getMaximumHives()) {
                LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.addhive");
                building.addHive(pos);
                SoundUtils.playSuccessSound(player, player.blockPosition());
            }
            if (positions.size() >= building.getMaximumHives()) {
                LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.maxhives");
                player.inventory.removeItemNoUpdate(player.inventory.selected);
            }
        }
    } else {
        player.inventory.removeItemNoUpdate(player.inventory.selected);
    }
    return super.useOn(useContext);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BeehiveBlock(net.minecraft.block.BeehiveBlock) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Example 2 with BuildingBeekeeper

use of com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper in project minecolonies by ldtteam.

the class ItemScepterBeekeeper method useOn.

@Override
public ActionResultType useOn(final ItemUseContext useContext) {
    // if server world, do nothing
    if (useContext.getLevel().isClientSide) {
        return ActionResultType.FAIL;
    }
    final PlayerEntity player = useContext.getPlayer();
    final ItemStack scepter = useContext.getPlayer().getItemInHand(useContext.getHand());
    final CompoundNBT compound = scepter.getOrCreateTag();
    final IColony colony = IColonyManager.getInstance().getColonyByWorld(compound.getInt(TAG_ID), useContext.getLevel());
    final BlockPos hutPos = BlockPosUtil.read(compound, TAG_POS);
    final IBuilding hut = colony.getBuildingManager().getBuilding(hutPos);
    final BuildingBeekeeper building = (BuildingBeekeeper) hut;
    if (useContext.getLevel().getBlockState(useContext.getClickedPos()).getBlock() instanceof BeehiveBlock) {
        final Collection<BlockPos> positions = building.getHives();
        final BlockPos pos = useContext.getClickedPos();
        if (positions.contains(pos)) {
            LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.removehive");
            building.removeHive(pos);
            SoundUtils.playSoundForPlayer((ServerPlayerEntity) player, SoundEvents.NOTE_BLOCK_BELL, (float) SoundUtils.VOLUME * 2, 0.5f);
        } else {
            if (positions.size() < building.getMaximumHives()) {
                LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.addhive");
                building.addHive(pos);
                SoundUtils.playSuccessSound(player, player.blockPosition());
            }
            if (positions.size() >= building.getMaximumHives()) {
                LanguageHandler.sendPlayerMessage(useContext.getPlayer(), "item.minecolonies.scepterbeekeeper.maxhives");
                player.inventory.removeItemNoUpdate(player.inventory.selected);
            }
        }
    } else {
        player.inventory.removeItemNoUpdate(player.inventory.selected);
    }
    return super.useOn(useContext);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BuildingBeekeeper(com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper) IColony(com.minecolonies.api.colony.IColony) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) BeehiveBlock(net.minecraft.block.BeehiveBlock) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity)

Aggregations

IColony (com.minecolonies.api.colony.IColony)2 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)2 BuildingBeekeeper (com.minecolonies.coremod.colony.buildings.workerbuildings.BuildingBeekeeper)2 BeehiveBlock (net.minecraft.block.BeehiveBlock)2 PlayerEntity (net.minecraft.entity.player.PlayerEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 ItemStack (net.minecraft.item.ItemStack)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 BlockPos (net.minecraft.util.math.BlockPos)2