use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class ItemAncientTome method onUpdate.
@Override
public void onUpdate(final ItemStack stack, final World worldIn, final Entity entityIn, final int itemSlot, final boolean isSelected) {
super.onUpdate(stack, worldIn, entityIn, itemSlot, isSelected);
final Colony colony = ColonyManager.getClosestColony(worldIn, entityIn.getPosition());
raidWillHappen = colony != null && colony.hasWillRaidTonight();
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class BuildRequestMessage method messageOnServerThread.
@Override
public void messageOnServerThread(final BuildRequestMessage message, final EntityPlayerMP player) {
final Colony colony = ColonyManager.getColony(message.colonyId);
if (colony == null) {
return;
}
final AbstractBuilding building = colony.getBuildingManager().getBuilding(message.buildingId);
if (building == null) {
return;
}
// Verify player has permission to change this huts settings
if (!colony.getPermissions().hasPermission(player, Action.MANAGE_HUTS)) {
return;
}
if (building.hasWorkOrder()) {
building.removeWorkOrder();
} else {
switch(message.mode) {
case BUILD:
building.requestUpgrade(player);
break;
case REPAIR:
building.requestRepair();
break;
default:
break;
}
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class BuildToolPasteMessage method setupBuilding.
/**
* setup the building once it has been placed.
*
* @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.
*/
private static void setupBuilding(@NotNull final World world, @NotNull final EntityPlayer player, final StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
@Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, buildPos);
if (building == null) {
Log.getLogger().error("BuildTool: building is null!");
} else {
if (building.getTileEntity() != null) {
final Colony colony = ColonyManager.getColony(world, buildPos);
if (colony == null) {
Log.getLogger().info("No colony for " + player.getName());
} else {
building.getTileEntity().setColony(colony);
}
}
String name = sn.toString();
name = name.substring(name.length() - 1);
try {
final int level = Integer.parseInt(name);
building.setBuildingLevel(level);
} catch (final NumberFormatException e) {
Log.getLogger().warn("Couldn't parse the level.", e);
}
building.setStyle(sn.getStyle());
building.setRotation(rotation);
if (mirror) {
building.invertMirror();
}
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
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.
*/
private static void handleHut(@NotNull final World world, @NotNull final EntityPlayer player, final StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
final Colony tempColony = ColonyManager.getClosestColony(world, buildPos);
if (tempColony != null && !tempColony.getPermissions().hasPermission(player, Action.MANAGE_HUTS) && !ColonyManager.isTooCloseToColony(world, buildPos)) {
return;
}
final String hut = sn.getSection();
final Block block = Block.getBlockFromName(Constants.MOD_ID + ":blockHut" + hut);
if (block != null && EventHandler.onBlockHutPlaced(world, player, block, buildPos)) {
world.destroyBlock(buildPos, true);
world.setBlockState(buildPos, block.getDefaultState().withRotation(BlockUtils.getRotation(rotation)));
((AbstractBlockHut) block).onBlockPlacedByBuildTool(world, buildPos, world.getBlockState(buildPos), player, null, mirror, sn.getStyle());
setupBuilding(world, player, sn, rotation, buildPos, mirror);
}
}
use of com.minecolonies.coremod.colony.Colony in project minecolonies by Minecolonies.
the class BuildToolPlaceMessage method setupBuilding.
/**
* setup the building once it has been placed.
*
* @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.
*/
private static void setupBuilding(@NotNull final World world, @NotNull final EntityPlayer player, final StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
@Nullable final AbstractBuilding building = ColonyManager.getBuilding(world, buildPos);
if (building == null) {
Log.getLogger().error("BuildTool: building is null!");
} else {
if (building.getTileEntity() != null) {
final Colony colony = ColonyManager.getColony(world, buildPos);
if (colony == null) {
Log.getLogger().info("No colony for " + player.getName());
} else {
building.getTileEntity().setColony(colony);
}
}
building.setStyle(sn.getStyle());
building.setRotation(rotation);
if (mirror) {
building.invertMirror();
}
}
}
Aggregations