use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.
the class ColonyManager method deleteColony.
/**
* Delete a colony and kill all citizens/purge all buildings.
*
* @param id the colonies id.
*/
public static void deleteColony(final int id) {
try {
final Colony colony = getColony(id);
Log.getLogger().info("Deleting colony " + id);
colonies.remove(id);
coloniesByWorld.get(colony.getDimension()).remove(colony);
final Set<World> colonyWorlds = new HashSet<>();
Log.getLogger().info("Removing citizens for " + id);
for (final CitizenData citizenData : new ArrayList<>(colony.getCitizens().values())) {
Log.getLogger().info("Kill Citizen " + citizenData.getName());
final EntityCitizen entityCitizen = citizenData.getCitizenEntity();
if (entityCitizen != null) {
final World world = entityCitizen.getEntityWorld();
citizenData.getCitizenEntity().onDeath(CONSOLE_DAMAGE_SOURCE);
colonyWorlds.add(world);
}
}
Log.getLogger().info("Removing buildings for " + id);
for (final AbstractBuilding building : new ArrayList<>(colony.getBuildings().values())) {
final BlockPos location = building.getLocation();
Log.getLogger().info("Delete Building at " + location);
building.destroy();
for (final World world : colonyWorlds) {
if (world.getBlockState(location).getBlock() instanceof AbstractBlockHut) {
Log.getLogger().info("Found Block, deleting " + world.getBlockState(location).getBlock());
world.setBlockToAir(location);
}
}
}
Log.getLogger().info("Done with " + id);
} catch (final RuntimeException e) {
Log.getLogger().warn("Deleting Colony " + id + " errored:", e);
}
}
use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.
the class EventHandler method onPlayerInteract.
/**
* Event when a player right clicks a block, or right clicks with an item.
* Event gets cancelled when player has no permission. Event gets cancelled
* when the player has no permission to place a hut, and tried it.
*
* @param event {@link PlayerInteractEvent.RightClickBlock}
*/
@SubscribeEvent
public void onPlayerInteract(@NotNull final PlayerInteractEvent.RightClickBlock event) {
final EntityPlayer player = event.getEntityPlayer();
final World world = event.getWorld();
//Only execute for the main hand our colony events.
if (event.getHand() == EnumHand.MAIN_HAND && !(event.getWorld().isRemote)) {
// and uses that return value, but I didn't want to call it twice
if (playerRightClickInteract(player, world, event.getPos()) && world.getBlockState(event.getPos()).getBlock() instanceof AbstractBlockHut) {
final IColony colony = ColonyManager.getIColony(world, event.getPos());
if (colony != null && !colony.getPermissions().hasPermission(player, Action.ACCESS_HUTS)) {
event.setCanceled(true);
}
return;
} else if (event.getEntityPlayer() != null && "pmardle".equalsIgnoreCase(event.getEntityPlayer().getName()) && event.getItemStack() != null && Block.getBlockFromItem(event.getItemStack().getItem()) instanceof BlockSilverfish) {
LanguageHandler.sendPlayerMessage(event.getEntityPlayer(), "Stop that you twat!!!");
event.setCanceled(true);
}
if (player.getHeldItemMainhand() == null || player.getHeldItemMainhand().getItem() == null) {
return;
}
handleEventCancellation(event, player);
}
}
use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.
the class ColonyPermissionEventHandler method on.
/**
* PlayerInteractEvent handler.
* <p>
* Check, if a player right clicked a block.
* Deny if:
* - If the block is in colony
* - block is AbstractBlockHut
* - player has not permission
*
* @param event PlayerInteractEvent
*/
@SubscribeEvent
public void on(final PlayerInteractEvent event) {
if (colony.isCoordInColony(event.getWorld(), event.getPos()) && !(event instanceof PlayerInteractEvent.EntityInteract || event instanceof PlayerInteractEvent.EntityInteractSpecific)) {
final Block block = event.getWorld().getBlockState(event.getPos()).getBlock();
// Huts
if (block instanceof AbstractBlockHut && !colony.getPermissions().hasPermission(event.getEntityPlayer(), Action.ACCESS_HUTS)) {
cancelEvent(event, event.getEntityPlayer());
}
final Permissions perms = colony.getPermissions();
if (isFreeToInteractWith(event.getWorld().getBlockState(event.getPos()).getBlock(), event.getPos()) && perms.hasPermission(event.getEntityPlayer(), Action.ACCESS_FREE_BLOCKS)) {
return;
}
if (Configurations.enableColonyProtection) {
if (!perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_BLOCK) && event.getWorld().getBlockState(event.getPos()).getBlock() != null) {
cancelEvent(event, event.getEntityPlayer());
}
if (event.getWorld().getBlockState(event.getPos()).getBlock() instanceof BlockContainer && !perms.hasPermission(event.getEntityPlayer(), Action.OPEN_CONTAINER)) {
cancelEvent(event, event.getEntityPlayer());
}
if (event.getWorld().getTileEntity(event.getPos()) != null && !perms.hasPermission(event.getEntityPlayer(), Action.RIGHTCLICK_ENTITY)) {
cancelEvent(event, event.getEntityPlayer());
}
if (event.getItemStack() != null && event.getItemStack().getItem() instanceof ItemPotion && !perms.hasPermission(event.getEntityPlayer(), Action.THROW_POTION)) {
cancelEvent(event, event.getEntityPlayer());
}
if (event.getItemStack() != null && event.getItemStack().getItem() instanceof ItemScanTool && !perms.hasPermission(event.getEntityPlayer(), Action.USE_SCAN_TOOL)) {
cancelEvent(event, event.getEntityPlayer());
}
}
}
}
use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.
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 workOrderName The name of the work order.
* @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 Structures.StructureName sn, final int rotation, @NotNull final BlockPos buildPos, final boolean mirror) {
final String hut = sn.getSection();
final Block block = Block.getBlockFromName(Constants.MOD_ID + ":blockHut" + hut);
final Colony tempColony = ColonyManager.getClosestColony(world, buildPos);
if (tempColony != null && (!tempColony.getPermissions().hasPermission(player, Action.MANAGE_HUTS) && !(block instanceof BlockHutTownHall && BlockPosUtil.getDistance2D(tempColony.getCenter(), buildPos) >= Configurations.workingRangeTownHall * 2 + Configurations.townHallPadding))) {
return;
}
if (block != null && player.inventory.hasItemStack(new ItemStack(block))) {
if (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());
player.inventory.clearMatchingItems(Item.getItemFromBlock(block), -1, 1, null);
setupBuilding(world, player, sn, rotation, buildPos, mirror);
}
} else {
LanguageHandler.sendPlayerMessage(player, BuildToolPlaceMessage.NO_HUT_IN_INVENTORY);
}
}
use of com.minecolonies.coremod.blocks.AbstractBlockHut in project minecolonies by Minecolonies.
the class EntityAIStructureBuilder method requestMaterials.
/**
* Iterates through all the required resources and stores them in the building.
* Suppressing Sonar Rule Squid:S135
* The rule thinks we should have less continue and breaks.
* But in this case the rule does not apply because code would become unreadable and uneffective without.
*/
@SuppressWarnings(LOOPS_SHOULD_NOT_CONTAIN_MORE_THAN_A_SINGLE_BREAK_OR_CONTINUE_STATEMENT)
private void requestMaterials() {
if (job.getWorkOrder().isRequested()) {
return;
}
final AbstractBuildingWorker buildingWorker = getOwnBuilding();
if (buildingWorker instanceof BuildingBuilder) {
((BuildingBuilder) buildingWorker).resetNeededResources();
}
while (job.getStructure().findNextBlock()) {
@Nullable final Template.BlockInfo blockInfo = job.getStructure().getBlockInfo();
@Nullable final Template.EntityInfo entityInfo = job.getStructure().getEntityinfo();
if (entityInfo != null) {
requestEntityToBuildingIfRequired(entityInfo);
}
if (blockInfo == null) {
continue;
}
@Nullable IBlockState blockState = blockInfo.blockState;
@Nullable Block block = blockState.getBlock();
if (job.getStructure().isStructureBlockEqualWorldBlock() || (blockState.getBlock() instanceof BlockBed && blockState.getValue(BlockBed.PART).equals(BlockBed.EnumPartType.FOOT)) || (blockState.getBlock() instanceof BlockDoor && blockState.getValue(BlockDoor.HALF).equals(BlockDoor.EnumDoorHalf.UPPER))) {
continue;
}
if (block instanceof BlockSolidSubstitution) {
blockState = getSolidSubstitution(job.getStructure().getBlockPosition());
block = blockState.getBlock();
}
final Block worldBlock = BlockPosUtil.getBlock(world, job.getStructure().getBlockPosition());
if (block != null && block != Blocks.AIR && worldBlock != Blocks.BEDROCK && !(worldBlock instanceof AbstractBlockHut) && !isBlockFree(block, 0)) {
requestBlockToBuildingIfRequired((BuildingBuilder) getOwnBuilding(), blockState);
}
}
job.getWorkOrder().setRequested(true);
}
Aggregations