Search in sources :

Example 21 with TileEntityColonyBuilding

use of com.minecolonies.api.tileentities.TileEntityColonyBuilding in project minecolonies by ldtteam.

the class AbstractBlockHut method createTileEntity.

@Nullable
@Override
public TileEntity createTileEntity(final BlockState state, final IBlockReader world) {
    final TileEntityColonyBuilding building = (TileEntityColonyBuilding) MinecoloniesTileEntities.BUILDING.create();
    building.registryName = this.getBuildingEntry().getRegistryName();
    return building;
}
Also used : AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) Nullable(org.jetbrains.annotations.Nullable)

Example 22 with TileEntityColonyBuilding

use of com.minecolonies.api.tileentities.TileEntityColonyBuilding in project minecolonies by ldtteam.

the class AbstractBlockHut method setPlacedBy.

/**
 * Event-Handler for placement of this block.
 * <p>
 * Override for custom logic.
 *
 * @param worldIn the word we are in.
 * @param pos     the position where the block was placed.
 * @param state   the state the placed block is in.
 * @param placer  the player placing the block.
 * @param stack   the itemstack from where the block was placed.
 * @see Block#setPlacedBy(World, BlockPos, BlockState, LivingEntity, ItemStack)
 */
@Override
public void setPlacedBy(@NotNull final World worldIn, @NotNull final BlockPos pos, final BlockState state, final LivingEntity placer, final ItemStack stack) {
    super.setPlacedBy(worldIn, pos, state, placer, stack);
    /*
        Only work on server side
        */
    if (worldIn.isClientSide) {
        return;
    }
    final TileEntity tileEntity = worldIn.getBlockEntity(pos);
    if (tileEntity instanceof TileEntityColonyBuilding) {
        @NotNull final TileEntityColonyBuilding hut = (TileEntityColonyBuilding) tileEntity;
        if (hut.getBuildingName() != getBuildingEntry().getRegistryName()) {
            hut.registryName = getBuildingEntry().getRegistryName();
        }
        @Nullable final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(worldIn, hut.getPosition());
        if (colony != null) {
            colony.getBuildingManager().addNewBuilding(hut, worldIn);
            colony.getProgressManager().progressBuildingPlacement(this);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) IColony(com.minecolonies.api.colony.IColony) NotNull(org.jetbrains.annotations.NotNull) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with TileEntityColonyBuilding

use of com.minecolonies.api.tileentities.TileEntityColonyBuilding in project minecolonies by ldtteam.

the class ItemScrollHighlight method useOn.

@Override
@NotNull
public ActionResultType useOn(ItemUseContext ctx) {
    // Right click on block
    if (ctx.getLevel().isClientSide || ctx.getPlayer() == null || !ctx.getPlayer().isShiftKeyDown()) {
        return ActionResultType.PASS;
    }
    final TileEntity te = ctx.getLevel().getBlockEntity(ctx.getClickedPos());
    if (te instanceof TileEntityColonyBuilding) {
        ctx.getItemInHand().shrink(1);
        if (ctx.getLevel().random.nextInt(10) == 0) {
            ctx.getPlayer().displayClientMessage(new TranslationTextComponent("minecolonies.scroll.failed" + (ctx.getLevel().random.nextInt(FAIL_RESPONSES_TOTAL) + 1)).setStyle(Style.EMPTY.withColor(TextFormatting.GOLD)), true);
            ctx.getPlayer().addEffect(new EffectInstance(Effects.GLOWING, TICKS_SECOND * 300));
            SoundUtils.playSoundForPlayer((ServerPlayerEntity) ctx.getPlayer(), SoundEvents.ENDER_CHEST_OPEN, 0.3f, 1.0f);
            return ActionResultType.SUCCESS;
        }
        final TileEntityColonyBuilding building = (TileEntityColonyBuilding) te;
        final Set<ICitizenData> citizens = building.getColony().getBuildingManager().getBuilding(ctx.getClickedPos()).getAllAssignedCitizen();
        for (final ICitizenData citizenData : citizens) {
            if (citizenData.getEntity().isPresent()) {
                citizenData.getEntity().get().addEffect(new EffectInstance(Effects.GLOWING, TICKS_SECOND * 120));
                citizenData.getEntity().get().addEffect(new EffectInstance(Effects.MOVEMENT_SPEED, TICKS_SECOND * 120));
            }
        }
        SoundUtils.playSoundForPlayer((ServerPlayerEntity) ctx.getPlayer(), SoundEvents.PLAYER_LEVELUP, 0.3f, 1.0f);
    }
    return ActionResultType.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) ICitizenData(com.minecolonies.api.colony.ICitizenData) EffectInstance(net.minecraft.potion.EffectInstance) NotNull(org.jetbrains.annotations.NotNull)

Example 24 with TileEntityColonyBuilding

use of com.minecolonies.api.tileentities.TileEntityColonyBuilding in project minecolonies by ldtteam.

the class ItemResourceScroll method useOn.

/**
 * Used when clicking on block in world.
 *
 * @param ctx the context of use.
 * @return the result
 */
@Override
@NotNull
public ActionResultType useOn(ItemUseContext ctx) {
    final ItemStack scroll = ctx.getPlayer().getItemInHand(ctx.getHand());
    final CompoundNBT compound = checkForCompound(scroll);
    TileEntity entity = ctx.getLevel().getBlockEntity(ctx.getClickedPos());
    if (entity instanceof TileEntityColonyBuilding) {
        compound.putInt(TAG_COLONY_ID, ((AbstractTileEntityColonyBuilding) entity).getColonyId());
        BlockPosUtil.write(compound, TAG_BUILDER, ((AbstractTileEntityColonyBuilding) entity).getPosition());
        if (!ctx.getLevel().isClientSide) {
            LanguageHandler.sendPlayerMessage(ctx.getPlayer(), TranslationConstants.COM_MINECOLONIES_SCROLL_BUILDER_SET, ((AbstractTileEntityColonyBuilding) entity).getColony().getName());
        }
    } else if (ctx.getLevel().isClientSide) {
        openWindow(compound, ctx.getPlayer());
    }
    return ActionResultType.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Example 25 with TileEntityColonyBuilding

use of com.minecolonies.api.tileentities.TileEntityColonyBuilding in project minecolonies by ldtteam.

the class ItemClipboard method useOn.

@Override
@NotNull
public ActionResultType useOn(final ItemUseContext ctx) {
    final ItemStack clipboard = ctx.getPlayer().getItemInHand(ctx.getHand());
    final CompoundNBT compound = checkForCompound(clipboard);
    final TileEntity entity = ctx.getLevel().getBlockEntity(ctx.getClickedPos());
    if (entity instanceof TileEntityColonyBuilding) {
        compound.putInt(TAG_COLONY, ((AbstractTileEntityColonyBuilding) entity).getColonyId());
        if (!ctx.getLevel().isClientSide) {
            LanguageHandler.sendPlayerMessage(ctx.getPlayer(), TranslationConstants.COM_MINECOLONIES_CLIPBOARD_COLONY_SET, ((AbstractTileEntityColonyBuilding) entity).getColony().getName());
        }
    } else if (ctx.getLevel().isClientSide) {
        openWindow(compound, ctx.getLevel(), ctx.getPlayer());
    }
    return ActionResultType.SUCCESS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) ItemStack(net.minecraft.item.ItemStack) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

TileEntityColonyBuilding (com.minecolonies.api.tileentities.TileEntityColonyBuilding)26 TileEntity (net.minecraft.tileentity.TileEntity)22 AbstractTileEntityColonyBuilding (com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding)18 NotNull (org.jetbrains.annotations.NotNull)14 ItemStack (net.minecraft.item.ItemStack)9 Nullable (org.jetbrains.annotations.Nullable)8 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)6 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)4 IColony (com.minecolonies.api.colony.IColony)4 TileEntityRack (com.minecolonies.api.tileentities.TileEntityRack)4 ICitizenData (com.minecolonies.api.colony.ICitizenData)2 IWareHouse (com.minecolonies.api.colony.buildings.workerbuildings.IWareHouse)2 ChatPriority (com.minecolonies.api.colony.interactionhandling.ChatPriority)2 ILocation (com.minecolonies.api.colony.requestsystem.location.ILocation)2 IRequest (com.minecolonies.api.colony.requestsystem.request.IRequest)2 IRequestable (com.minecolonies.api.colony.requestsystem.requestable.IRequestable)2 Delivery (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.Delivery)2 IDeliverymanRequestable (com.minecolonies.api.colony.requestsystem.requestable.deliveryman.IDeliverymanRequestable)2 ItemStorage (com.minecolonies.api.crafting.ItemStorage)2