Search in sources :

Example 81 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class DirectPlaceMessage method onExecute.

@Override
public void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer) {
    final ServerPlayerEntity player = ctxIn.getSender();
    final World world = player.getCommandSenderWorld();
    final IColony colony = IColonyManager.getInstance().getColonyByPosFromWorld(world, pos);
    if ((colony == null && state.getBlock() == ModBlocks.blockHutTownHall) || (colony != null && colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS))) {
        final CompoundNBT compound = stack.getTag();
        if (colony != null && compound != null && compound.contains(TAG_COLONY_ID) && colony.getID() != compound.getInt(TAG_COLONY_ID)) {
            MessageUtils.format(WRONG_COLONY, compound.getInt(TAG_COLONY_ID)).sendTo(player);
            return;
        }
        player.getCommandSenderWorld().setBlockAndUpdate(pos, state);
        InventoryUtils.reduceStackInItemHandler(new InvWrapper(player.inventory), stack);
        state.getBlock().setPlacedBy(world, pos, state, player, stack);
        if (compound != null && compound.contains(TAG_OTHER_LEVEL)) {
            final IBuilding building = colony.getBuildingManager().getBuilding(pos);
            if (building != null) {
                building.setBuildingLevel(compound.getInt(TAG_OTHER_LEVEL));
                building.setDeconstructed();
            }
        }
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) InvWrapper(net.minecraftforge.items.wrapper.InvWrapper) IColony(com.minecolonies.api.colony.IColony) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) World(net.minecraft.world.World)

Example 82 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class HireFireMessage method onExecute.

@Override
protected void onExecute(final NetworkEvent.Context ctxIn, final boolean isLogicalServer, final IColony colony, final IBuilding building) {
    final ICitizenData citizen = colony.getCitizenManager().getCivilian(citizenID);
    citizen.setPaused(false);
    if (hire) {
        building.getModuleMatching(IAssignsJob.class, m -> m.getJobEntry() == entry).assignCitizen(citizen);
    } else {
        building.getModuleMatching(IAssignsJob.class, m -> m.getJobEntry() == entry).removeCitizen(citizen);
    }
}
Also used : AbstractBuildingServerMessage(com.minecolonies.coremod.network.messages.server.AbstractBuildingServerMessage) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) IBuildingView(com.minecolonies.api.colony.buildings.views.IBuildingView) IColony(com.minecolonies.api.colony.IColony) IAssignsJob(com.minecolonies.api.colony.buildings.modules.IAssignsJob) NetworkEvent(net.minecraftforge.fml.network.NetworkEvent) ICitizenData(com.minecolonies.api.colony.ICitizenData) JobEntry(com.minecolonies.api.colony.jobs.registry.JobEntry) NotNull(org.jetbrains.annotations.NotNull) PacketBuffer(net.minecraft.network.PacketBuffer) IAssignsJob(com.minecolonies.api.colony.buildings.modules.IAssignsJob) ICitizenData(com.minecolonies.api.colony.ICitizenData)

Example 83 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class AbstractTileEntityColonyBuilding method readSchematicDataFromNBT.

@Override
public void readSchematicDataFromNBT(final CompoundNBT originalCompound) {
    final String old = getSchematicName();
    IBlueprintDataProvider.super.readSchematicDataFromNBT(originalCompound);
    if (level == null || level.isClientSide || getColony() == null || getColony().getBuildingManager() == null) {
        return;
    }
    final IBuilding building = getColony().getBuildingManager().getBuilding(worldPosition);
    if (building != null) {
        building.onUpgradeSchematicTo(old, getSchematicName(), this);
    }
    this.version = VERSION;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding)

Example 84 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class RaidManager method findSpawnPointInDirections.

/**
 * Finds a spawnpoint randomly in a circular shape around the center Advances
 *
 * @param start      the center of the area to search for a spawn point
 * @param advancePos The position we advance towards
 * @return the calculated position
 */
private BlockPos findSpawnPointInDirections(final BlockPos start, final BlockPos advancePos) {
    BlockPos spawnPos = new BlockPos(start);
    Vector3d tempPos = new Vector3d(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ());
    final Collection<IBuilding> buildings = colony.getBuildingManager().getBuildings().values();
    final int xDiff = Math.abs(start.getX() - advancePos.getX());
    final int zDiff = Math.abs(start.getZ() - advancePos.getZ());
    Vector3d xzRatio = new Vector3d(xDiff * (start.getX() < advancePos.getX() ? 1 : -1), 0, zDiff * (start.getZ() < advancePos.getZ() ? 1 : -1));
    // Reduce ratio to 3 chunks a step
    xzRatio = xzRatio.normalize().scale(3);
    int validChunkCount = 0;
    for (int i = 0; i < 10; i++) {
        if (WorldUtil.isEntityBlockLoaded(colony.getWorld(), new BlockPos(tempPos))) {
            tempPos = tempPos.add(16 * xzRatio.x, 0, 16 * xzRatio.z);
            if (WorldUtil.isEntityBlockLoaded(colony.getWorld(), new BlockPos(tempPos))) {
                if (isValidSpawnPoint(buildings, new BlockPos(tempPos))) {
                    spawnPos = new BlockPos(tempPos);
                    validChunkCount++;
                    if (validChunkCount > 5) {
                        return spawnPos;
                    }
                }
            } else {
                break;
            }
        } else {
            break;
        }
    }
    if (!spawnPos.equals(start)) {
        return spawnPos;
    }
    return null;
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BlockPos(net.minecraft.util.math.BlockPos)

Example 85 with IBuilding

use of com.minecolonies.api.colony.buildings.IBuilding in project minecolonies by Minecolonies.

the class RaidManager method calculateSpawnLocation.

/**
 * Calculate a random spawn point along the colony's border
 *
 * @return Returns the random blockPos
 */
@Override
public BlockPos calculateSpawnLocation() {
    BlockPos locationSum = new BlockPos(0, 0, 0);
    int amount = 0;
    for (final IBuilding building : colony.getBuildingManager().getBuildings().values()) {
        if (WorldUtil.isEntityBlockLoaded(colony.getWorld(), building.getPosition())) {
            amount++;
            locationSum = locationSum.offset(building.getPosition());
        }
    }
    if (amount == 0) {
        Log.getLogger().info("Trying to spawn raid on colony with no loaded buildings, aborting!");
        return null;
    }
    // Calculate center on loaded buildings, to find a nice distance for raiders
    final BlockPos calcCenter = new BlockPos(locationSum.getX() / amount, locationSum.getY() / amount, locationSum.getZ() / amount);
    // Get a random point on a circle around the colony,far out for the direction
    final int degree = colony.getWorld().random.nextInt(360);
    int x = (int) Math.round(500 * Math.cos(Math.toRadians(degree)));
    int z = (int) Math.round(500 * Math.sin(Math.toRadians(degree)));
    final BlockPos advanceTowards = calcCenter.offset(x, 0, z);
    BlockPos spawnPos = null;
    final BlockPos closestBuilding = colony.getBuildingManager().getBestBuilding(advanceTowards, IBuilding.class);
    if (closestBuilding == null) {
        return null;
    }
    // 8 Tries
    for (int i = 0; i < 8; i++) {
        spawnPos = findSpawnPointInDirections(new BlockPos(closestBuilding.getX(), calcCenter.getY(), closestBuilding.getZ()), advanceTowards);
        if (spawnPos != null) {
            break;
        }
    }
    if (spawnPos == null) {
        return null;
    }
    BlockPos worldSpawnPos = BlockPosUtil.findAround(colony.getWorld(), BlockPosUtil.getFloor(spawnPos, colony.getWorld()), 3, 30, SOLID_AIR_POS_SELECTOR);
    if (worldSpawnPos == null && MineColonies.getConfig().getServer().skyRaiders.get()) {
        worldSpawnPos = BlockPosUtil.findAround(colony.getWorld(), BlockPosUtil.getFloor(spawnPos, colony.getWorld()), 10, 15, DOUBLE_AIR_POS_SELECTOR);
    }
    return worldSpawnPos;
}
Also used : IBuilding(com.minecolonies.api.colony.buildings.IBuilding) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

IBuilding (com.minecolonies.api.colony.buildings.IBuilding)187 BlockPos (net.minecraft.util.math.BlockPos)71 NotNull (org.jetbrains.annotations.NotNull)45 IColony (com.minecolonies.api.colony.IColony)37 Nullable (org.jetbrains.annotations.Nullable)26 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)24 ICitizenData (com.minecolonies.api.colony.ICitizenData)22 World (net.minecraft.world.World)20 ItemStack (net.minecraft.item.ItemStack)19 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)19 TileEntity (net.minecraft.tileentity.TileEntity)17 CompoundNBT (net.minecraft.nbt.CompoundNBT)15 ArrayList (java.util.ArrayList)14 AbstractBuildingGuards (com.minecolonies.coremod.colony.buildings.AbstractBuildingGuards)10 ItemStorage (com.minecolonies.api.crafting.ItemStorage)9 ResourceLocation (net.minecraft.util.ResourceLocation)9 IItemHandler (net.minecraftforge.items.IItemHandler)9 InventoryUtils (com.minecolonies.api.util.InventoryUtils)8 ItemStackUtils (com.minecolonies.api.util.ItemStackUtils)8 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)8