use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.
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.
* @param state The state of the hut.
* @param complete If complete or not.
*/
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 boolean complete) {
final IColony tempColony = IColonyManager.getInstance().getClosestColony(world, buildPos);
if (!complete && tempColony != null && !tempColony.getPermissions().hasPermission(player, Action.MANAGE_HUTS) && IColonyManager.getInstance().isFarEnoughFromColonies(world, buildPos)) {
return;
}
final String hut = sn.getSection();
final ItemStack stack = BuildingUtils.getItemStackForHutFromInventory(player.inventory, hut);
final Block block = stack.getItem() instanceof BlockItem ? ((BlockItem) stack.getItem()).getBlock() : null;
if (block != null && EventHandler.onBlockHutPlaced(world, player, block, buildPos)) {
world.destroyBlock(buildPos, true);
world.setBlockAndUpdate(buildPos, state);
if (!complete) {
((AbstractBlockHut<?>) block).onBlockPlacedByBuildTool(world, buildPos, world.getBlockState(buildPos), player, null, mirror, sn.getStyle());
setupBuilding(world, player, sn, rotation, buildPos, mirror);
}
}
}
use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.
the class ClientEventHandler method onItemTooltipEvent.
/**
* Fires when an item tooltip is requested, generally from inventory, JEI, or when minecraft is first populating the recipe book.
* @param event An ItemTooltipEvent
*/
@SubscribeEvent
public static void onItemTooltipEvent(final ItemTooltipEvent event) {
// Vanilla recipe books populate tooltips once before the player exists on remote clients, some other cases.
if (event.getPlayer() == null) {
return;
}
IColony colony = IMinecoloniesAPI.getInstance().getColonyManager().getIColony(event.getPlayer().level, event.getPlayer().blockPosition());
if (colony == null) {
colony = IMinecoloniesAPI.getInstance().getColonyManager().getIColonyByOwner(event.getPlayer().level, event.getPlayer());
}
handleCrafterRecipeTooltips(colony, event.getToolTip(), event.getItemStack().getItem());
if (event.getItemStack().getItem() instanceof BlockItem) {
final BlockItem blockItem = (BlockItem) event.getItemStack().getItem();
if (blockItem.getBlock() instanceof AbstractBlockHut) {
handleHutBlockResearchUnlocks(colony, event.getToolTip(), blockItem.getBlock());
}
}
}
use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by ldtteam.
the class ColonyManager method deleteColony.
/**
* Delete a colony and purge all buildings and citizens.
*
* @param iColony the colony to destroy.
* @param canDestroy if the building outlines should be destroyed as well.
*/
private void deleteColony(@Nullable final IColony iColony, final boolean canDestroy) {
if (!(iColony instanceof Colony)) {
return;
}
final Colony colony = (Colony) iColony;
final int id = colony.getID();
final World world = colony.getWorld();
if (world == null) {
Log.getLogger().warn("Deleting Colony " + id + " errored: World is Null");
return;
}
try {
ChunkDataHelper.claimColonyChunks(world, false, id, colony.getCenter(), colony.getDimension());
Log.getLogger().info("Removing citizens for " + id);
for (final ICitizenData citizenData : new ArrayList<>(colony.getCitizenManager().getCitizens())) {
Log.getLogger().info("Kill Citizen " + citizenData.getName());
citizenData.getEntity().ifPresent(entityCitizen -> entityCitizen.die(CONSOLE_DAMAGE_SOURCE));
}
Log.getLogger().info("Removing buildings for " + id);
for (final IBuilding building : new ArrayList<>(colony.getBuildingManager().getBuildings().values())) {
try {
final BlockPos location = building.getPosition();
Log.getLogger().info("Delete Building at " + location);
if (canDestroy) {
building.deconstruct();
}
building.destroy();
if (world.getBlockState(location).getBlock() instanceof AbstractBlockHut) {
Log.getLogger().info("Found Block, deleting " + world.getBlockState(location).getBlock());
world.removeBlock(location, false);
}
} catch (final Exception ex) {
Log.getLogger().warn("Something went wrong deleting a building while deleting the colony!", ex);
}
}
try {
MinecraftForge.EVENT_BUS.unregister(colony.getEventHandler());
} catch (final NullPointerException e) {
Log.getLogger().warn("Can't unregister the event handler twice");
}
Log.getLogger().info("Deleting colony: " + colony.getID());
final IColonyManagerCapability cap = world.getCapability(COLONY_MANAGER_CAP, null).resolve().orElse(null);
if (cap == null) {
Log.getLogger().warn(MISSING_WORLD_CAP_MESSAGE);
return;
}
cap.deleteColony(id);
BackUpHelper.markColonyDeleted(colony.getID(), colony.getDimension());
colony.getImportantMessageEntityPlayers().forEach(player -> Network.getNetwork().sendToPlayer(new ColonyViewRemoveMessage(colony.getID(), colony.getDimension()), (ServerPlayerEntity) player));
Log.getLogger().info("Successfully deleted colony: " + id);
} catch (final RuntimeException e) {
Log.getLogger().warn("Deleting Colony " + id + " errored:", e);
}
}
use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by Minecolonies.
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())));
}
}
use of com.minecolonies.api.blocks.AbstractBlockHut in project minecolonies by Minecolonies.
the class AbstractBuilding method getTileEntity.
@Override
public AbstractTileEntityColonyBuilding getTileEntity() {
if (tileEntity != null && tileEntity.isRemoved()) {
tileEntity = null;
}
if ((tileEntity == null) && colony != null && colony.getWorld() != null && getPosition() != null && WorldUtil.isBlockLoaded(colony.getWorld(), getPosition()) && !(colony.getWorld().getBlockState(getPosition()).getBlock() instanceof AirBlock) && colony.getWorld().getBlockState(this.getPosition()).getBlock() instanceof AbstractBlockHut) {
final TileEntity te = colony.getWorld().getBlockEntity(getPosition());
if (te instanceof TileEntityColonyBuilding) {
tileEntity = (TileEntityColonyBuilding) te;
if (tileEntity.getBuilding() == null) {
tileEntity.setColony(colony);
tileEntity.setBuilding(this);
}
} else {
Log.getLogger().error("Somehow the wrong TileEntity is at the location where the building should be!", new Exception());
Log.getLogger().error("Trying to restore order!");
final AbstractTileEntityColonyBuilding tileEntityColonyBuilding = new TileEntityColonyBuilding(MinecoloniesTileEntities.BUILDING);
colony.getWorld().setBlockEntity(getPosition(), tileEntityColonyBuilding);
this.tileEntity = tileEntityColonyBuilding;
}
}
return tileEntity;
}
Aggregations