Search in sources :

Example 11 with AbstractBlockHut

use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.

the class BuildToolPasteMessage method handleHut.

/**
 * Handles the placement of huts.
 *
 * @param world    World the hut is being placed into.
 * @param player   Who placed the hut.
 * @param sn       The name of the structure.
 * @param rotation The number of times the structure should be rotated.
 * @param buildPos The location the hut is being placed.
 * @param mirror   Whether or not the strcture is mirrored.
 * @param state    The state of the hut.
 * @param complete If complete or not.
 */
private static void handleHut(@NotNull final World world, @NotNull final PlayerEntity player, final StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror, final BlockState state, final boolean complete) {
    final IColony tempColony = IColonyManager.getInstance().getClosestColony(world, buildPos);
    if (!complete && tempColony != null && !tempColony.getPermissions().hasPermission(player, Action.MANAGE_HUTS) && IColonyManager.getInstance().isFarEnoughFromColonies(world, buildPos)) {
        return;
    }
    final String hut = sn.getSection();
    final ItemStack stack = BuildingUtils.getItemStackForHutFromInventory(player.inventory, hut);
    final Block block = stack.getItem() instanceof BlockItem ? ((BlockItem) stack.getItem()).getBlock() : null;
    if (block != null && EventHandler.onBlockHutPlaced(world, player, block, buildPos)) {
        world.destroyBlock(buildPos, true);
        world.setBlockAndUpdate(buildPos, state);
        if (!complete) {
            ((AbstractBlockHut<?>) block).onBlockPlacedByBuildTool(world, buildPos, world.getBlockState(buildPos), player, null, mirror, sn.getStyle());
            setupBuilding(world, player, sn, rotation, buildPos, mirror);
        }
    }
}
Also used : IColony(com.minecolonies.api.colony.IColony) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack) BlockItem(net.minecraft.item.BlockItem) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut)

Example 12 with AbstractBlockHut

use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.

the class ClientEventHandler method onItemTooltipEvent.

/**
 * Fires when an item tooltip is requested, generally from inventory, JEI, or when minecraft is first populating the recipe book.
 * @param event An ItemTooltipEvent
 */
@SubscribeEvent
public static void onItemTooltipEvent(final ItemTooltipEvent event) {
    // Vanilla recipe books populate tooltips once before the player exists on remote clients, some other cases.
    if (event.getPlayer() == null) {
        return;
    }
    IColony colony = IMinecoloniesAPI.getInstance().getColonyManager().getIColony(event.getPlayer().level, event.getPlayer().blockPosition());
    if (colony == null) {
        colony = IMinecoloniesAPI.getInstance().getColonyManager().getIColonyByOwner(event.getPlayer().level, event.getPlayer());
    }
    handleCrafterRecipeTooltips(colony, event.getToolTip(), event.getItemStack().getItem());
    if (event.getItemStack().getItem() instanceof BlockItem) {
        final BlockItem blockItem = (BlockItem) event.getItemStack().getItem();
        if (blockItem.getBlock() instanceof AbstractBlockHut) {
            handleHutBlockResearchUnlocks(colony, event.getToolTip(), blockItem.getBlock());
        }
    }
}
Also used : IColony(com.minecolonies.api.colony.IColony) BlockItem(net.minecraft.item.BlockItem) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 13 with AbstractBlockHut

use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.

the class ColonyManager method deleteColony.

/**
 * Delete a colony and purge all buildings and citizens.
 *
 * @param iColony    the colony to destroy.
 * @param canDestroy if the building outlines should be destroyed as well.
 */
private void deleteColony(@Nullable final IColony iColony, final boolean canDestroy) {
    if (!(iColony instanceof Colony)) {
        return;
    }
    final Colony colony = (Colony) iColony;
    final int id = colony.getID();
    final World world = colony.getWorld();
    if (world == null) {
        Log.getLogger().warn("Deleting Colony " + id + " errored: World is Null");
        return;
    }
    try {
        ChunkDataHelper.claimColonyChunks(world, false, id, colony.getCenter(), colony.getDimension());
        Log.getLogger().info("Removing citizens for " + id);
        for (final ICitizenData citizenData : new ArrayList<>(colony.getCitizenManager().getCitizens())) {
            Log.getLogger().info("Kill Citizen " + citizenData.getName());
            citizenData.getEntity().ifPresent(entityCitizen -> entityCitizen.die(CONSOLE_DAMAGE_SOURCE));
        }
        Log.getLogger().info("Removing buildings for " + id);
        for (final IBuilding building : new ArrayList<>(colony.getBuildingManager().getBuildings().values())) {
            try {
                final BlockPos location = building.getPosition();
                Log.getLogger().info("Delete Building at " + location);
                if (canDestroy) {
                    building.deconstruct();
                }
                building.destroy();
                if (world.getBlockState(location).getBlock() instanceof AbstractBlockHut) {
                    Log.getLogger().info("Found Block, deleting " + world.getBlockState(location).getBlock());
                    world.removeBlock(location, false);
                }
            } catch (final Exception ex) {
                Log.getLogger().warn("Something went wrong deleting a building while deleting the colony!", ex);
            }
        }
        try {
            MinecraftForge.EVENT_BUS.unregister(colony.getEventHandler());
        } catch (final NullPointerException e) {
            Log.getLogger().warn("Can't unregister the event handler twice");
        }
        Log.getLogger().info("Deleting colony: " + colony.getID());
        final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null).resolve().orElse(null);
        if (cap == null) {
            Log.getLogger().warn(MISSING_WORLD_CAP_MESSAGE);
            return;
        }
        cap.deleteColony(id);
        BackUpHelper.markColonyDeleted(colony.getID(), colony.getDimension());
        colony.getImportantMessageEntityPlayers().forEach(player -> Network.getNetwork().sendToPlayer(new ColonyViewRemoveMessage(colony.getID(), colony.getDimension()), (ServerPlayerEntity) player));
        Log.getLogger().info("Successfully deleted colony: " + id);
    } catch (final RuntimeException e) {
        Log.getLogger().warn("Deleting Colony " + id + " errored:", e);
    }
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) ColonyViewRemoveMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyViewRemoveMessage) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) World(net.minecraft.world.World) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut) BlockPos(net.minecraft.util.math.BlockPos)

Example 14 with AbstractBlockHut

use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by Minecolonies.

the class DefaultBlockLootTableProvider method saveBlock.

private void saveBlock(@NotNull final Block block, @NotNull final LootTableRegistrar registrar) {
    if (block.getRegistryName() != null) {
        final ResourceLocation id = new ResourceLocation(block.getRegistryName().getNamespace(), "blocks/" + block.getRegistryName().getPath());
        final StandaloneLootEntry.Builder<?> item = ItemLootEntry.lootTableItem(block);
        if (block instanceof AbstractBlockHut || block instanceof BlockMinecoloniesRack) {
            item.apply(CopyName.copyName(CopyName.Source.BLOCK_ENTITY));
        }
        registrar.register(id, LootParameterSets.BLOCK, LootTable.lootTable().withPool(LootPool.lootPool().add(item).when(SurvivesExplosion.survivesExplosion())));
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) BlockMinecoloniesRack(com.minecolonies.coremod.blocks.BlockMinecoloniesRack) AbstractBlockHut(com.minecolonies.api.blocks.AbstractBlockHut)

Example 15 with AbstractBlockHut

use of com.minecolonies.api.blocks.AbstractBlockHut 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)

Aggregations

AbstractBlockHut (com.minecolonies.api.blocks.AbstractBlockHut)22 ItemStack (net.minecraft.item.ItemStack)8 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)8 IColony (com.minecolonies.api.colony.IColony)6 IBuilding (com.minecolonies.api.colony.buildings.IBuilding)6 Block (net.minecraft.block.Block)6 BlockItem (net.minecraft.item.BlockItem)6 AbstractTileEntityColonyBuilding (com.minecolonies.api.tileentities.AbstractTileEntityColonyBuilding)4 TileEntityColonyBuilding (com.minecolonies.api.tileentities.TileEntityColonyBuilding)4 BlockMinecoloniesRack (com.minecolonies.coremod.blocks.BlockMinecoloniesRack)4 AirBlock (net.minecraft.block.AirBlock)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 TileEntity (net.minecraft.tileentity.TileEntity)4 BlockPos (net.minecraft.util.math.BlockPos)4 World (net.minecraft.world.World)4 Blueprint (com.ldtteam.structures.blueprints.v1.Blueprint)2 ItemScanTool (com.ldtteam.structurize.items.ItemScanTool)2 StructureName (com.ldtteam.structurize.management.StructureName)2 PlacementSettings (com.ldtteam.structurize.util.PlacementSettings)2 IRSComponentBlock (com.minecolonies.api.blocks.interfaces.IRSComponentBlock)2