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();
}
}
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations