Search in sources :

Example 21 with AbstractBlockHut

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

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 22 with AbstractBlockHut

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

the class BuildToolPlaceMessage 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.
 */
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 Block blockAtPos = world.getBlockState(buildPos).getBlock();
    if (blockAtPos instanceof IBuilderUndestroyable || ModTags.indestructible.contains(blockAtPos)) {
        LanguageHandler.sendPlayerMessage(player, INDESTRUCTIBLE_BLOCK_AT_POS);
        SoundUtils.playErrorSound(player, buildPos);
        return;
    }
    final Block block = state.getBlock();
    final ItemStack tempStack = new ItemStack(block, 1);
    final int slot = InventoryUtils.findFirstSlotInItemHandlerWith(new InvWrapper(player.inventory), s -> ItemStackUtils.compareItemStacksIgnoreStackSize(tempStack, s, false, false));
    if (slot < 0) {
        return;
    }
    final ItemStack stack = player.inventory.getItem(slot);
    final IColony tempColony = IColonyManager.getInstance().getClosestColony(world, buildPos);
    if (tempColony != null && (!tempColony.getPermissions().hasPermission(player, Action.MANAGE_HUTS) && !(block instanceof BlockHutTownHall && IColonyManager.getInstance().isFarEnoughFromColonies(world, buildPos)))) {
        return;
    }
    final CompoundNBT compound = stack.getTag();
    if (tempColony != null && compound != null && compound.contains(TAG_COLONY_ID) && tempColony.getID() != compound.getInt(TAG_COLONY_ID)) {
        LanguageHandler.sendPlayerMessage(player, WRONG_COLONY, compound.getInt(TAG_COLONY_ID));
        return;
    }
    if (block != null && player.inventory.contains(new ItemStack(block))) {
        if (EventHandler.onBlockHutPlaced(world, player, block, buildPos)) {
            if (tempColony != null) {
                AdvancementUtils.TriggerAdvancementPlayersForColony(tempColony, playerMP -> AdvancementTriggers.PLACE_STRUCTURE.trigger(playerMP, sn));
            } else {
                AdvancementTriggers.PLACE_STRUCTURE.trigger((ServerPlayerEntity) player, sn);
            }
            world.destroyBlock(buildPos, true);
            world.setBlockAndUpdate(buildPos, state);
            ((AbstractBlockHut<?>) block).onBlockPlacedByBuildTool(world, buildPos, world.getBlockState(buildPos), player, null, mirror, sn.getStyle());
            boolean complete = false;
            int level = 0;
            if (compound != null) {
                if (compound.getAllKeys().contains(TAG_OTHER_LEVEL)) {
                    level = compound.getInt(TAG_OTHER_LEVEL);
                }
                if (compound.getAllKeys().contains(TAG_PASTEABLE)) {
                    String schematic = sn.toString();
                    schematic = schematic.substring(0, schematic.length() - 1);
                    schematic += level;
                    CreativeBuildingStructureHandler.loadAndPlaceStructureWithRotation(player.level, schematic, buildPos, BlockPosUtil.getRotationFromRotations(rotation), mirror ? Mirror.FRONT_BACK : Mirror.NONE, true, (ServerPlayerEntity) player);
                    complete = true;
                }
            }
            InventoryUtils.reduceStackInItemHandler(new InvWrapper(player.inventory), stack, 1);
            setupBuilding(world, player, sn, rotation, buildPos, mirror, level, complete);
        }
    } else {
        LanguageHandler.sendPlayerMessage(player, NO_HUT_IN_INVENTORY);
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) Block(net.minecraft.block.Block) IColony(com.minecolonies.api.colony.IColony) BlockHutTownHall(com.minecolonies.coremod.blocks.huts.BlockHutTownHall) ItemStack(net.minecraft.item.ItemStack) IBuilderUndestroyable(com.minecolonies.api.entity.ai.citizen.builder.IBuilderUndestroyable) 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