Search in sources :

Example 11 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by Minecolonies.

the class AbstractItemScroll method useOn.

@Override
@NotNull
public ActionResultType useOn(ItemUseContext ctx) {
    // Right click on block
    if (ctx.getLevel().isClientSide || !ctx.getPlayer().isShiftKeyDown() || !needsColony()) {
        return ActionResultType.PASS;
    }
    final TileEntity te = ctx.getLevel().getBlockEntity(ctx.getClickedPos());
    final ItemStack scroll = ctx.getPlayer().getItemInHand(ctx.getHand());
    final CompoundNBT compound = checkForCompound(scroll);
    if (te instanceof TileEntityColonyBuilding) {
        compound.putInt(TAG_COLONY_ID, ((AbstractTileEntityColonyBuilding) te).getColonyId());
        compound.putString(TAG_COLONY_DIM, ((AbstractTileEntityColonyBuilding) te).getColony().getWorld().dimension().location().toString());
        BlockPosUtil.write(compound, TAG_BUILDING_POS, ctx.getClickedPos());
        LanguageHandler.sendPlayerMessage(ctx.getPlayer(), "minecolonies.scroll.registered", ((AbstractTileEntityColonyBuilding) te).getColony().getName());
    }
    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 12 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by Minecolonies.

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)

Example 13 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by Minecolonies.

the class AbstractBuilding method onDestroyed.

@Override
public void onDestroyed() {
    final AbstractTileEntityColonyBuilding tileEntityNew = this.getTileEntity();
    final World world = colony.getWorld();
    final Block block = world.getBlockState(this.getPosition()).getBlock();
    if (tileEntityNew != null) {
        InventoryUtils.dropItemHandler(tileEntityNew.getInventory(), world, tileEntityNew.getPosition().getX(), tileEntityNew.getPosition().getY(), tileEntityNew.getPosition().getZ());
        world.updateNeighbourForOutputSignal(this.getPosition(), block);
    }
    ChunkDataHelper.claimColonyChunks(colony, false, this.getID(), getClaimRadius(getBuildingLevel()));
    ConstructionTapeHelper.removeConstructionTape(getCorners(), world);
    getModules(IBuildingEventsModule.class).forEach(IBuildingEventsModule::onDestroyed);
}
Also used : AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AirBlock(net.minecraft.block.AirBlock) Block(net.minecraft.block.Block) World(net.minecraft.world.World)

Example 14 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by Minecolonies.

the class AbstractBuilding method getTileEntity.

@Override
public AbstractTileEntityColonyBuilding getTileEntity() {
    if (tileEntity != null && tileEntity.isRemoved()) {
        tileEntity = null;
    }
    if ((tileEntity == null) && colony != null && colony.getWorld() != null && getPosition() != null && WorldUtil.isBlockLoaded(colony.getWorld(), getPosition()) && !(colony.getWorld().getBlockState(getPosition()).getBlock() instanceof AirBlock) && colony.getWorld().getBlockState(this.getPosition()).getBlock() instanceof AbstractBlockHut) {
        final TileEntity te = colony.getWorld().getBlockEntity(getPosition());
        if (te instanceof TileEntityColonyBuilding) {
            tileEntity = (TileEntityColonyBuilding) te;
            if (tileEntity.getBuilding() == null) {
                tileEntity.setColony(colony);
                tileEntity.setBuilding(this);
            }
        } else {
            Log.getLogger().error("Somehow the wrong TileEntity is at the location where the building should be!", new Exception());
            Log.getLogger().error("Trying to restore order!");
            final AbstractTileEntityColonyBuilding tileEntityColonyBuilding = new TileEntityColonyBuilding(MinecoloniesTileEntities.BUILDING);
            colony.getWorld().setBlockEntity(getPosition(), tileEntityColonyBuilding);
            this.tileEntity = tileEntityColonyBuilding;
        }
    }
    return tileEntity;
}
Also used : ChestTileEntity(net.minecraft.tileentity.ChestTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) AirBlock(net.minecraft.block.AirBlock) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut)

Example 15 with AbstractTileEntityColonyBuilding

use of com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding in project minecolonies by Minecolonies.

the class CreateColonyMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final ServerPlayerEntity sender = ctxIn.getSender();
    final World world = ctxIn.getSender().level;
    if (sender == null) {
        return;
    }
    if (sender.getStats().getValue(Stats.ITEM_USED.get(ModItems.supplyChest)) <= 0 && !sender.isCreative()) {
        LanguageHandler.sendPlayerMessage(sender, "com.minecolonies.coremod.supplyneed");
        return;
    }
    final IColony colony = IColonyManager.getInstance().getClosestColony(world, townHall);
    String style = Constants.DEFAULT_STYLE;
    final TileEntity tileEntity = world.getBlockEntity(townHall);
    if (!(tileEntity instanceof TileEntityColonyBuilding)) {
        LanguageHandler.sendPlayerMessage(sender, "com.minecolonies.coremod.gui.colony.create.notileentity");
        return;
    }
    if (!((AbstractTileEntityColonyBuilding) tileEntity).getStyle().isEmpty()) {
        style = ((AbstractTileEntityColonyBuilding) tileEntity).getStyle();
    }
    if (MineColonies.getConfig().getServer().restrictColonyPlacement.get()) {
        final double spawnDistance = Math.sqrt(BlockPosUtil.getDistanceSquared2D(townHall, ((ServerWorld) world).getSharedSpawnPos()));
        if (spawnDistance < MineColonies.getConfig().getServer().minDistanceFromWorldSpawn.get()) {
            if (!world.isClientSide) {
                LanguageHandler.sendPlayerMessage(sender, CANT_PLACE_COLONY_TOO_CLOSE_TO_SPAWN, MineColonies.getConfig().getServer().minDistanceFromWorldSpawn.get());
            }
            return;
        } else if (spawnDistance > MineColonies.getConfig().getServer().maxDistanceFromWorldSpawn.get()) {
            if (!world.isClientSide) {
                LanguageHandler.sendPlayerMessage(sender, CANT_PLACE_COLONY_TOO_FAR_FROM_SPAWN, MineColonies.getConfig().getServer().maxDistanceFromWorldSpawn.get());
            }
            return;
        }
    }
    if (colony != null && !IColonyManager.getInstance().isFarEnoughFromColonies(world, townHall)) {
        LanguageHandler.sendPlayerMessage(sender, "com.minecolonies.coremod.gui.colony.denied.tooclose", colony.getName());
        return;
    }
    final IColony ownedColony = IColonyManager.getInstance().getIColonyByOwner(world, sender);
    if (ownedColony == null) {
        IColonyManager.getInstance().createColony(world, townHall, sender, style);
        IColonyManager.getInstance().getIColonyByOwner(world, sender).getBuildingManager().addNewBuilding((TileEntityColonyBuilding) tileEntity, world);
        LanguageHandler.sendPlayerMessage((PlayerEntity) sender, "com.minecolonies.coremod.progress.colony_founded");
        return;
    }
    LanguageHandler.sendPlayerMessage((PlayerEntity) sender, "com.minecolonies.coremod.gui.colony.create.failed");
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ServerWorld(net.minecraft.world.server.ServerWorld) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) AbstractTileEntityColonyBuilding(com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding) TileEntityColonyBuilding(com.minecolonies.api.tileentities.TileEntityColonyBuilding) IColony(com.minecolonies.api.colony.IColony) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World)

Aggregations

AbstractTileEntityColonyBuilding (com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding)20 TileEntity (net.minecraft.tileentity.TileEntity)16 TileEntityColonyBuilding (com.minecolonies.api.tileentities.TileEntityColonyBuilding)12 ItemStack (net.minecraft.item.ItemStack)8 NotNull (org.jetbrains.annotations.NotNull)8 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)4 World (net.minecraft.world.World)4 AirBlock (net.minecraft.block.AirBlock)3 BlockPos (net.minecraft.util.math.BlockPos)3 IBlueprintDataProvider (com.ldtteam.structurize.blocks.interfaces.IBlueprintDataProvider)2 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)2 AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)2 IColony (com.minecolonies.api.colony.IColony)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